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

* [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
21 lines
667 B
Go
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
|
|
}
|
|
}
|
|
}
|