node: Gossip once we switch to gossip protocol

Previous to this change, we were attempting to gossip after a successful
fetch, but before the session was switched back to the gossip protocol.
This meant that messages were queued for a short amount of time. With
this change, messages should be sent straight away.
This commit is contained in:
Alexis Sellier 2023-03-07 11:34:56 +01:00
parent ad63583bee
commit fb635d80c3
No known key found for this signature in database
1 changed files with 15 additions and 10 deletions

View File

@ -636,6 +636,21 @@ where
error!(target: "service", "Failed to announce new refs: {e}");
}
}
}
if let Some(session) = self.sessions.get_mut(&remote) {
// 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);
} else {
log::debug!(target: "service", "Session not found for {remote}");
}
// Nb. This block needs to be run after we've switched back to the gossip protocol,
// otherwise the messages will be queued.
if initiated {
// TODO: Since this fetch could be either a full clone or simply a ref update, we need
// to either announce new inventory, or new refs. Right now, we announce both in some
// cases.
@ -658,16 +673,6 @@ where
}
}
}
if let Some(session) = self.sessions.get_mut(&remote) {
// 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);
} else {
log::debug!(target: "service", "Session not found for {remote}");
}
}
pub fn accepted(&mut self, _addr: net::SocketAddr) {