kaspad/infrastructure/network/connmanager/incoming_connections.go
Ori Newman fcae491e6d
[NOD-1286] Close router from netConnection.Disconnect (#881)
* [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
2020-08-19 17:28:01 +03:00

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
}
}
}