node: Move state transition code to session
This commit is contained in:
parent
011923f1df
commit
71561a8e12
|
|
@ -603,16 +603,8 @@ where
|
|||
}
|
||||
|
||||
if let Some(session) = self.sessions.get_mut(&remote) {
|
||||
if let session::State::Connected { protocol, .. } = &mut session.state {
|
||||
if let session::Protocol::Fetch { .. } = protocol {
|
||||
*protocol = session::Protocol::default();
|
||||
} else {
|
||||
panic!(
|
||||
"Unexpected session state for {}: expected 'fetch' protocol, got 'gossip'",
|
||||
session.id
|
||||
);
|
||||
}
|
||||
}
|
||||
// Transition session back to gossip protocol.
|
||||
session.to_gossip();
|
||||
// Drain any messages in the session's outbox, which might have accumulated during the
|
||||
// fetch, and send them to the peer.
|
||||
self.reactor.drain(session);
|
||||
|
|
|
|||
|
|
@ -250,6 +250,19 @@ impl Session {
|
|||
*protocol = Protocol::Fetch { rid };
|
||||
}
|
||||
|
||||
pub fn to_gossip(&mut self) {
|
||||
if let State::Connected { protocol, .. } = &mut self.state {
|
||||
if let Protocol::Fetch { .. } = protocol {
|
||||
*protocol = Protocol::default();
|
||||
} else {
|
||||
panic!(
|
||||
"Unexpected session state for {}: expected 'fetch' protocol, got 'gossip'",
|
||||
self.id
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn to_connecting(&mut self) {
|
||||
assert!(
|
||||
self.is_disconnected(),
|
||||
|
|
|
|||
Loading…
Reference in New Issue