github.com/onflow/flow-go@v0.35.7-crescendo-preview.23-atree-inlining/network/netconf/connection_manager.go (about) 1 package netconf 2 3 import "time" 4 5 const ( 6 highWatermarkKey = "high-watermark" 7 lowWatermarkKey = "low-watermark" 8 silencePeriodKey = "silence-period" 9 gracePeriodKey = "grace-period" 10 ) 11 12 type ConnectionManager struct { 13 // HighWatermark and LowWatermark govern the number of connections are maintained by the ConnManager. 14 // When the peer count exceeds the HighWatermark, as many peers will be pruned (and 15 // their connections terminated) until LowWatermark peers remain. In other words, whenever the 16 // peer count is x > HighWatermark, the ConnManager will prune x - LowWatermark peers. 17 // The pruning algorithm is as follows: 18 // 1. The ConnManager will not prune any peers that have been connected for less than GracePeriod. 19 // 2. The ConnManager will not prune any peers that are protected. 20 // 3. The ConnManager will sort the peers based on their number of streams and direction of connections, and 21 // prunes the peers with the least number of streams. If there are ties, the peer with the incoming connection 22 // will be pruned. If both peers have incoming connections, and there are still ties, one of the peers will be 23 // pruned at random. 24 // Algorithm implementation is in https://github.com/libp2p/go-libp2p/blob/master/p2p/net/connmgr/connmgr.go#L262-L318 25 HighWatermark int `mapstructure:"high-watermark"` // naming from libp2p 26 LowWatermark int `mapstructure:"low-watermark"` // naming from libp2p 27 28 // SilencePeriod is a regular interval that the connection manager will check for pruning peers if the number of peers exceeds the high-watermark. 29 // It is a regular interval. 30 SilencePeriod time.Duration `mapstructure:"silence-period"` // naming from libp2p 31 // GracePeriod is the time to wait before a new connection is considered for pruning. 32 GracePeriod time.Duration `mapstructure:"grace-period"` // naming from libp2p 33 }