From 3b6d9788d5de0273a41c5254dcabe889c9e81fee Mon Sep 17 00:00:00 2001 From: Felix Lange Date: Fri, 7 Jun 2019 13:37:21 +0200 Subject: [PATCH] p2p: simplify checkpoint handling There is no need to select on srv.quit for both ends of the checkpoint channel. --- p2p/server.go | 20 ++++---------------- 1 file changed, 4 insertions(+), 16 deletions(-) diff --git a/p2p/server.go b/p2p/server.go index b103084f03..06dc95f222 100644 --- a/p2p/server.go +++ b/p2p/server.go @@ -731,11 +731,8 @@ running: c.flags |= trustedConn } // TODO: track in-progress inbound node IDs (pre-Peer) to avoid dialing them. - select { - case c.cont <- srv.postHandshakeChecks(peers, inboundCount, c): - case <-srv.quit: - break running - } + c.cont <- srv.postHandshakeChecks(peers, inboundCount, c) + case c := <-srv.checkpointAddPeer: // At this point the connection is past the protocol handshake. // Its capabilities are known and the remote identity is verified. @@ -759,11 +756,7 @@ running: // The dialer logic relies on the assumption that // dial tasks complete after the peer has been added or // discarded. Unblock the task last. - select { - case c.cont <- err: - case <-srv.quit: - break running - } + c.cont <- err case pd := <-srv.delpeer: // A peer disconnected. @@ -1012,12 +1005,7 @@ func (srv *Server) checkpoint(c *conn, stage chan<- *conn) error { case <-srv.quit: return errServerStopped } - select { - case err := <-c.cont: - return err - case <-srv.quit: - return errServerStopped - } + return <-c.cont } // runPeer runs in its own goroutine for each peer.