fix: pierce the firewall on server-brokered reverse connects

When the server asks us to connect to a peer (a ConnectToPeer we receive,
carrying the server's correlation token), we dial that peer and must announce
ourselves with a PierceFirewall quoting the token — not a PeerInit — so the
remote peer can correlate its own indirect request (search-result / upload
delivery). The outbound handshake now sends PierceFirewall when the peer
carries a server token and PeerInit only for direct GetPeerAddress dials
(token None). Direct and firewalled e2e paths are unchanged.
This commit is contained in:
michel
2026-07-19 17:48:50 +02:00
parent ea25325e68
commit a186c9d07d
+19 -11
View File
@@ -586,19 +586,27 @@ impl PeerActor {
return; return;
}; };
// Connections we initiated must announce themselves with a PeerInit // Connections we initiated must announce themselves; inbound peers
// (peer code 1); inbound peers already sent us theirs, so we stay // already sent us theirs, so we stay silent for them. A direct dial
// silent for them. `get_buffer` prepends the length prefix the peer's // (resolved via GetPeerAddress, token None) sends a PeerInit; a dial we
// MessageReader expects. // make because the server asked us to (a brokered ConnectToPeer carries
// the server's token) must instead PierceFirewall with that token so
// the remote peer can correlate its own request. `get_buffer` prepends
// the length prefix the peer's MessageReader expects.
if self.outbound { if self.outbound {
let init = MessageFactory::build_peer_init_message( let handshake = match token {
&self.own_username, Some(server_token) => {
connection_type, MessageFactory::build_pierce_firewall_message(server_token)
token.unwrap_or(0), }
); None => MessageFactory::build_peer_init_message(
if let Err(e) = stream.write_all(&init.get_buffer()) { &self.own_username,
connection_type,
0,
),
};
if let Err(e) = stream.write_all(&handshake.get_buffer()) {
error!( error!(
"[peer:{}] Failed to send PeerInit handshake: {}", "[peer:{}] Failed to send outbound handshake: {}",
username, e username, e
); );
self.disconnect_with_error(e); self.disconnect_with_error(e);