kaspad/connmanager/incoming_connections.go
Svarog 2303aecab4
[NOD-1198] Make router a property of netConnection, and remove map from connection to router in netAdapter (#829)
* [NOD-1198] Make router a property of netConnection, and remove map from connection to router in netAdapter

* [NOD-1198] Moved all router logic from netAdapter to netConnection

* [NOD-1198] Move disconnect to NetConnection

* [NOD-1198] Unexport netConnection.start

* [NOD-1198] Remove error from Disconnect functions

* [NOD-1198] Make sure OnDisconnectedHandler doesn't run when it shouldn't
2020-07-28 11:27:48 +03:00

21 lines
667 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
// randomly disconnect nodes until the number of incoming connections is smaller than maxIncoming
for _, connection := range incomingConnectionSet {
connection.Disconnect()
numConnectionsOverMax--
if numConnectionsOverMax == 0 {
break
}
}
}