(
self,
target: T,
local_addr: Option<SocketAddr>,
)
| 350 | } |
| 351 | |
| 352 | pub async fn connect<'t, T>( |
| 353 | self, |
| 354 | target: T, |
| 355 | local_addr: Option<SocketAddr>, |
| 356 | ) -> ResultType<FramedStream> |
| 357 | where |
| 358 | T: IntoTargetAddr<'t>, |
| 359 | { |
| 360 | info!("Connect to proxy server"); |
| 361 | let proxy = self.proxy_addrs().await?; |
| 362 | |
| 363 | let local = if let Some(addr) = local_addr { |
| 364 | addr |
| 365 | } else { |
| 366 | crate::config::Config::get_any_listen_addr(proxy.is_ipv4()) |
| 367 | }; |
| 368 | |
| 369 | let stream = super::timeout( |
| 370 | self.ms_timeout, |
| 371 | crate::tcp::new_socket(local, true)?.connect(proxy), |
| 372 | ) |
| 373 | .await??; |
| 374 | stream.set_nodelay(true).ok(); |
| 375 | |
| 376 | let addr = stream.local_addr()?; |
| 377 | |
| 378 | return match self.intercept { |
| 379 | ProxyScheme::Http { .. } => { |
| 380 | info!("Connect to remote http proxy server: {}", proxy); |
| 381 | let stream = |
| 382 | super::timeout(self.ms_timeout, self.http_connect(stream, target)).await??; |
| 383 | Ok(FramedStream( |
| 384 | Framed::new(DynTcpStream(Box::new(stream)), BytesCodec::new()), |
| 385 | addr, |
| 386 | None, |
| 387 | 0, |
| 388 | )) |
| 389 | } |
| 390 | ProxyScheme::Https { .. } => { |
| 391 | info!("Connect to remote https proxy server: {}", proxy); |
| 392 | let stream = |
| 393 | super::timeout(self.ms_timeout, self.https_connect(stream, target)).await??; |
| 394 | Ok(FramedStream( |
| 395 | Framed::new(DynTcpStream(Box::new(stream)), BytesCodec::new()), |
| 396 | addr, |
| 397 | None, |
| 398 | 0, |
| 399 | )) |
| 400 | } |
| 401 | ProxyScheme::Socks5 { .. } => { |
| 402 | info!("Connect to remote socket5 proxy server: {}", proxy); |
| 403 | let stream = if let Some(auth) = self.intercept.maybe_auth() { |
| 404 | super::timeout( |
| 405 | self.ms_timeout, |
| 406 | Socks5Stream::connect_with_password_and_socket( |
| 407 | stream, |
| 408 | target, |
| 409 | &auth.user_name, |
no test coverage detected