Skip to content

Commit c14b2ee

Browse files
authored
Merge pull request #542 from rustaceanrob/26-1-1-proxy-transport
net: Use V1 transport when connecting by proxy
2 parents 60000a3 + 9aa8912 commit c14b2ee

File tree

3 files changed

+12
-3
lines changed

3 files changed

+12
-3
lines changed

src/network/mod.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,10 @@ impl ConnectionType {
187187
}
188188
}
189189
}
190+
191+
fn is_proxy(&self) -> bool {
192+
matches!(self, ConnectionType::Socks5Proxy(_))
193+
}
190194
}
191195

192196
#[derive(Debug, Clone)]

src/network/peer.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,14 +72,18 @@ impl Peer {
7272
}
7373
}
7474

75-
pub async fn run(&mut self, connection: TcpStream) -> Result<(), PeerError> {
75+
pub async fn run(
76+
&mut self,
77+
connection: TcpStream,
78+
is_proxy_connection: bool,
79+
) -> Result<(), PeerError> {
7680
let start_time = Instant::now();
7781
let (tx, mut rx) = mpsc::channel(32);
7882
let (reader, mut writer) = connection.into_split();
7983
let mut reader = BufReader::new(reader);
8084
// If a peer signals for V2 we will use it, otherwise just use plaintext.
8185
let (mut outbound_messages, mut peer_reader) =
82-
if self.source.service_flags().has(ServiceFlags::P2P_V2) {
86+
if self.source.service_flags().has(ServiceFlags::P2P_V2) && !is_proxy_connection {
8387
let handshake_result = tokio::time::timeout(
8488
V2_HANDSHAKE_TIMEOUT,
8589
self.try_handshake(&mut writer, &mut reader),

src/network/peer_map.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,8 @@ impl PeerMap {
141141
return Err(e);
142142
}
143143
};
144-
let handle = tokio::spawn(async move { peer.run(connection).await });
144+
let is_proxy = self.connector.is_proxy();
145+
let handle = tokio::spawn(async move { peer.run(connection, is_proxy).await });
145146
self.map.insert(
146147
self.current_id,
147148
ManagedPeer {

0 commit comments

Comments
 (0)