This repository was archived by the owner on Jan 24, 2025. It is now read-only.
File tree 1 file changed +10
-2
lines changed
1 file changed +10
-2
lines changed Original file line number Diff line number Diff line change @@ -3,6 +3,7 @@ package p2p
3
3
import (
4
4
"context"
5
5
"sync"
6
+ "sync/atomic"
6
7
"time"
7
8
8
9
"github.com/libp2p/go-libp2p/core/protocol"
@@ -15,7 +16,8 @@ import (
15
16
)
16
17
17
18
const (
18
- NeighborsSendQueueSize = 20_000
19
+ NeighborsSendQueueSize = 20_000
20
+ DroppedPacketDisconnectThreshold = 100
19
21
)
20
22
21
23
type queuedPacket struct {
31
33
32
34
// neighbor describes the established p2p connection to another peer.
33
35
type neighbor struct {
34
- peer * network.Peer
36
+ peer * network.Peer
37
+ droppedPacketCounter atomic.Uint32
35
38
36
39
logger log.Logger
37
40
@@ -84,7 +87,12 @@ func (n *neighbor) Peer() *network.Peer {
84
87
func (n * neighbor ) Enqueue (packet proto.Message , protocolID protocol.ID ) {
85
88
select {
86
89
case n .sendQueue <- & queuedPacket {protocolID : protocolID , packet : packet }:
90
+ n .droppedPacketCounter .Store (0 )
87
91
default :
92
+ // Drop a neighbor that does not read from the full queue.
93
+ if n .droppedPacketCounter .Add (1 ) >= DroppedPacketDisconnectThreshold {
94
+ n .Close ()
95
+ }
88
96
n .logger .LogWarn ("Dropped packet due to SendQueue being full" )
89
97
}
90
98
}
You can’t perform that action at this time.
0 commit comments