Skip to content

Commit 256705b

Browse files
committed
WIP: Session id switch and recycling.
1 parent f7107e9 commit 256705b

File tree

4 files changed

+183
-150
lines changed

4 files changed

+183
-150
lines changed

crates/net/network-devp2p/src/connection.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -236,6 +236,11 @@ impl Connection {
236236
})
237237
}
238238

239+
pub fn switch_session_token(&mut self, token: StreamToken) {
240+
trace!(target: "network", "Switching connection token from {:?} to {:?}", self.token, token);
241+
self.token = token;
242+
}
243+
239244
/// Register this connection with the IO event loop.
240245
pub fn register_socket<Host: Handler>(
241246
&self,

crates/net/network-devp2p/src/host.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -902,7 +902,7 @@ impl Host {
902902
}
903903

904904
let mut s = session.lock();
905-
self.sessions.register_finalized_handshake(token, s.id());
905+
self.sessions.register_finalized_handshake(&mut s);
906906
let (min_peers, mut max_peers, reserved_only, self_id) = {
907907
let info = self.info.read();
908908
let mut max_peers = info.config.max_peers;

crates/net/network-devp2p/src/session.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,18 @@ impl Session {
139139
})
140140
}
141141

142+
pub fn switch_session_token(&mut self, token_id: StreamToken) {
143+
144+
match &mut self.state {
145+
State::Handshake(h) => {
146+
error!(target: "network", "Setting token on handshake state is not allowed");
147+
},
148+
State::Session(s) => {
149+
s.connection.switch_session_token(token_id);
150+
},
151+
}
152+
}
153+
142154
fn complete_handshake<Message>(
143155
&mut self,
144156
io: &IoContext<Message>,

0 commit comments

Comments
 (0)