From 6ffaf8cdb932beb4353367cf8b23752acd2aa774 Mon Sep 17 00:00:00 2001 From: vyzo Date: Fri, 27 Sep 2024 14:21:59 +0300 Subject: [PATCH 1/2] identify: fix faulty handling of conn entries in IdentifyWait --- p2p/protocol/identify/id.go | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/p2p/protocol/identify/id.go b/p2p/protocol/identify/id.go index acaa40aca3..108d224b61 100644 --- a/p2p/protocol/identify/id.go +++ b/p2p/protocol/identify/id.go @@ -155,7 +155,7 @@ type idService struct { // The conns map contains all connections we're currently handling. // Connections are inserted as soon as they're available in the swarm // Connections are removed from the map when the connection disconnects. - conns map[network.Conn]entry + conns map[network.Conn]*entry addrMu sync.Mutex @@ -201,7 +201,7 @@ func NewIDService(h host.Host, opts ...Option) (*idService, error) { ProtocolVersion: cfg.protocolVersion, ctx: ctx, ctxCancel: cancel, - conns: make(map[network.Conn]entry), + conns: make(map[network.Conn]*entry), disableSignedPeerRecord: cfg.disableSignedPeerRecord, setupCompleted: make(chan struct{}), metricsTracer: cfg.metricsTracer, @@ -412,7 +412,7 @@ func (ids *idService) IdentifyWait(c network.Conn) <-chan struct{} { close(ch) return ch } else { - ids.addConnWithLock(c) + e = ids.addConnWithLock(c) } } @@ -986,12 +986,14 @@ func HasConsistentTransport(a ma.Multiaddr, green []ma.Multiaddr) bool { } // addConnWithLock assuems caller holds the connsMu lock -func (ids *idService) addConnWithLock(c network.Conn) { - _, found := ids.conns[c] +func (ids *idService) addConnWithLock(c network.Conn) *entry { + e, found := ids.conns[c] if !found { <-ids.setupCompleted - ids.conns[c] = entry{} + e = &entry{} + ids.conns[c] = e } + return e } func signedPeerRecordFromMessage(msg *pb.Identify) (*record.Envelope, error) { From 51f71ee52d29a2ed9a97d21d08737333a1944a0f Mon Sep 17 00:00:00 2001 From: vyzo Date: Fri, 27 Sep 2024 14:38:17 +0300 Subject: [PATCH 2/2] remove unnecessary assignment --- p2p/protocol/identify/id.go | 1 - 1 file changed, 1 deletion(-) diff --git a/p2p/protocol/identify/id.go b/p2p/protocol/identify/id.go index 108d224b61..f800de2132 100644 --- a/p2p/protocol/identify/id.go +++ b/p2p/protocol/identify/id.go @@ -421,7 +421,6 @@ func (ids *idService) IdentifyWait(c network.Conn) <-chan struct{} { } // First call to IdentifyWait for this connection. Create the channel. e.IdentifyWaitChan = make(chan struct{}) - ids.conns[c] = e // Spawn an identify. The connection may actually be closed // already, but that doesn't really matter. We'll fail to open a