mirror of
https://github.com/kaspanet/kaspad.git
synced 2025-03-30 15:08:33 +00:00

* [NOD-1286] Close router from netConnection.Disconnect * [NOD-1286] Close router in grpc errors as well * [NOD-1286] Fix typo * [NOD-1286] Rename isConnected->isRouterClosed
25 lines
910 B
Go
25 lines
910 B
Go
package connmanager
|
|
|
|
// checkIncomingConnections makes sure there's no more than maxIncoming incoming connections
|
|
// if there are - it randomly disconnects enough to go below that number
|
|
func (c *ConnectionManager) checkIncomingConnections(incomingConnectionSet connectionSet) {
|
|
if len(incomingConnectionSet) <= c.maxIncoming {
|
|
return
|
|
}
|
|
|
|
numConnectionsOverMax := len(incomingConnectionSet) - c.maxIncoming
|
|
log.Debugf("Got %d incoming connections while only %d are allowed. Disconnecting "+
|
|
"%d", len(incomingConnectionSet), c.maxIncoming, numConnectionsOverMax)
|
|
|
|
// randomly disconnect nodes until the number of incoming connections is smaller than maxIncoming
|
|
for _, connection := range incomingConnectionSet {
|
|
log.Debugf("Disconnecting %s due to exceeding incoming connections", connection)
|
|
connection.Disconnect()
|
|
|
|
numConnectionsOverMax--
|
|
if numConnectionsOverMax == 0 {
|
|
break
|
|
}
|
|
}
|
|
}
|