Skip to content

Commit abb3dae

Browse files
committed
socks5: detect if the session is established when proxy is not used
1 parent 8dc34ec commit abb3dae

File tree

1 file changed

+11
-6
lines changed

1 file changed

+11
-6
lines changed

src/session.rs

+11-6
Original file line numberDiff line numberDiff line change
@@ -444,8 +444,6 @@ where S::Artifact: IntoInit<M::Init>
444444
type Connection = S::Connection;
445445
type Artifact = ProtocolArtifact<M, S>;
446446

447-
fn is_established(&self) -> bool { self.state.is_complete() && self.artifact().is_some() }
448-
449447
fn run_handshake(&mut self) -> io::Result<()> {
450448
#[cfg(feature = "log")]
451449
log::debug!(target: M::NAME, "Starting handshake protocol {}", M::NAME);
@@ -641,6 +639,9 @@ mod impl_noise {
641639
}
642640

643641
mod impl_socks5 {
642+
use cyphernet::addr::Host;
643+
#[cfg(not(feature = "eidolon"))]
644+
use cyphernet::addr::{HostName, NetAddr};
644645
use cyphernet::proxy::socks5;
645646
use cyphernet::proxy::socks5::Socks5;
646647

@@ -649,7 +650,7 @@ mod impl_socks5 {
649650
impl NetStateMachine for Socks5 {
650651
const NAME: &'static str = "socks5";
651652
type Init = ZeroInit;
652-
type Artifact = ();
653+
type Artifact = NetAddr<HostName>;
653654
type Error = socks5::Error;
654655

655656
fn init(&mut self, _: Self::Init) {}
@@ -658,10 +659,14 @@ mod impl_socks5 {
658659

659660
fn advance(&mut self, input: &[u8]) -> Result<Vec<u8>, Self::Error> { self.advance(input) }
660661

661-
fn artifact(&self) -> Option<Self::Artifact> { Some(()) }
662+
fn artifact(&self) -> Option<Self::Artifact> {
663+
match self {
664+
Socks5::Initial(addr, false) if !addr.requires_proxy() => Some(addr.clone()),
665+
Socks5::Active(addr) => Some(addr.clone()),
666+
_ => None,
667+
}
668+
}
662669

663670
fn is_init(&self) -> bool { true }
664-
665-
fn is_complete(&self) -> bool { matches!(self, Socks5::Active(_)) && self.artifact().is_some() }
666671
}
667672
}

0 commit comments

Comments
 (0)