From d2abde3781afc913f83150c366ed2ee6a891fd01 Mon Sep 17 00:00:00 2001 From: muXxer Date: Mon, 15 Apr 2024 17:54:32 +0200 Subject: [PATCH] Remove p2p first packet received check --- pkg/network/errors.go | 2 -- pkg/network/p2p/manager.go | 20 +++----------------- 2 files changed, 3 insertions(+), 19 deletions(-) diff --git a/pkg/network/errors.go b/pkg/network/errors.go index 060cd475c..a73a74e85 100644 --- a/pkg/network/errors.go +++ b/pkg/network/errors.go @@ -11,8 +11,6 @@ var ( ErrLoopbackPeer = ierrors.New("loopback connection not allowed") // ErrDuplicatePeer is returned when the same peer is added more than once. ErrDuplicatePeer = ierrors.New("already connected") - // ErrFirstPacketNotReceived is returned when the first packet from a peer is not received. - ErrFirstPacketNotReceived = ierrors.New("first packet not received") // ErrMaxAutopeeringPeersReached is returned when the maximum number of autopeering peers is reached. ErrMaxAutopeeringPeersReached = ierrors.New("max autopeering peers reached") ) diff --git a/pkg/network/p2p/manager.go b/pkg/network/p2p/manager.go index ab2573c7d..30064518b 100644 --- a/pkg/network/p2p/manager.go +++ b/pkg/network/p2p/manager.go @@ -2,7 +2,6 @@ package p2p import ( "context" - "time" "github.com/libp2p/go-libp2p/core/host" p2pnetwork "github.com/libp2p/go-libp2p/core/network" @@ -145,7 +144,7 @@ func (m *Manager) DialPeer(ctx context.Context, peer *network.Peer) error { return ierrors.Wrapf(err, "failed to update peer %s", peer.ID.String()) } - if err := m.addNeighbor(ctx, peer, ps); err != nil { + if err := m.addNeighbor(peer, ps); err != nil { m.closeStream(stream) return ierrors.Wrapf(err, "failed to add neighbor %s", peer.ID.String()) @@ -347,7 +346,7 @@ func (m *Manager) handleStream(stream p2pnetwork.Stream) { return } - if err := m.addNeighbor(m.ctx, networkPeer, ps); err != nil { + if err := m.addNeighbor(networkPeer, ps); err != nil { m.logger.LogErrorf("failed to add neighbor, peerID: %s, error: %s", peerID.String(), err.Error()) m.closeStream(stream) @@ -376,7 +375,7 @@ func (m *Manager) neighbor(id peer.ID) (*neighbor, error) { return nbr, nil } -func (m *Manager) addNeighbor(ctx context.Context, peer *network.Peer, ps *PacketsStream) error { +func (m *Manager) addNeighbor(peer *network.Peer, ps *PacketsStream) error { if peer.ID == m.libp2pHost.ID() { return ierrors.WithStack(network.ErrLoopbackPeer) } @@ -392,9 +391,6 @@ func (m *Manager) addNeighbor(ctx context.Context, peer *network.Peer, ps *Packe return ierrors.WithStack(network.ErrDuplicatePeer) } - firstPacketReceivedCtx, firstPacketReceivedCancel := context.WithDeadline(ctx, time.Now().Add(5*time.Second)) - defer firstPacketReceivedCancel() - var innerErr error nbr := newNeighbor(m.logger, peer, ps, func(nbr *neighbor, packet proto.Message) { m.protocolHandlerMutex.RLock() @@ -410,7 +406,6 @@ func (m *Manager) addNeighbor(ctx context.Context, peer *network.Peer, ps *Packe }, func(nbr *neighbor) { nbr.logger.LogInfof("Neighbor connected: %s", nbr.Peer().ID.String()) nbr.Peer().SetConnStatus(network.ConnStatusConnected) - firstPacketReceivedCancel() m.neighborAdded.Trigger(nbr) }, func(nbr *neighbor) { m.deleteNeighbor(nbr) @@ -426,15 +421,6 @@ func (m *Manager) addNeighbor(ctx context.Context, peer *network.Peer, ps *Packe nbr.readLoop() nbr.writeLoop() - <-firstPacketReceivedCtx.Done() - - if ierrors.Is(firstPacketReceivedCtx.Err(), context.DeadlineExceeded) { - nbr.logger.LogErrorf("First packet not received within deadline") - nbr.Close() - - return ierrors.WithStack(network.ErrFirstPacketNotReceived) - } - return innerErr }