mirror of
https://github.com/kaspanet/kaspad.git
synced 2025-06-13 01:26:43 +00:00

* [NOD-1120] Removed closure in NetAdapter.onConnectedHanlder * [NOD-1120] Implement all connection manager methods * [NOD-1120] Integrated connmanager into kaspad + added call for dnsseeder * [NOD-1120] Allow buffer to not be bytes.Buffer * [NOD-1120] Added timeout to connect * [NOD-1120] Don't enter connections to add loop if none needed * [NOD-1120] Add call for addressManager.Good * [NOD-1120] Minor bug fixes * [NOD-1120] Remove errChan from grpcConnection * [NOD-1120] Add comments to exported methods * [NOD-1120] cancel the context for DialContext in gRPCServer.Connect * [NOD-1120] Don't try to remove from connSet a connection that doesn't exist * [NOD-1120] add ok bool to connectionSet.get * [NOD-1120] Remove overuse of if-else in checkConnectionRequests * [NOD-1120] Made some order in ConnectionManager * [NOD-1120] Moved checkIncomingConnections to it's own file * [NOD-1120] cleanup in checkOutgoingConnections * [NOD-1120] Cleanup in SeedDNS, and move call outside of connection manager * [NOD-1120] Add check that both --connect and --addpeer aren't used * [NOD-1120] Move dial timeout to constant * [NOD-1120] Enhance comment * [NOD-1120] Log connection failure out of initiateConnection * [NOD-1148] Reshuffle checkRequestedConnections to make more sense * [NOD-1120] Move continue to correct place + reshuffle logging code * [NOD-1120] Don't expose server.Connection outside netAdapter - expose a wrapper instead * [NOD-1120] Add comments * [NOD-1120] Don't return the connection from netAdapter.Connect() * [NOD-1120] Use .Address as key for connectionSet * [NOD-1120] Fix minRetryDuration usage * [NOD-1120] Remove the correct number of incoming connections * [NOD-1120] Add comment * [NOD-1120] Rename connSet -> incomingConnectionSet * [NOD-1120] fix grammar
24 lines
778 B
Go
24 lines
778 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 address, connection := range incomingConnectionSet {
|
|
err := c.netAdapter.Disconnect(connection)
|
|
if err != nil {
|
|
log.Errorf("Error disconnecting from %s: %+v", address, err)
|
|
}
|
|
|
|
numConnectionsOverMax--
|
|
if numConnectionsOverMax == 0 {
|
|
break
|
|
}
|
|
}
|
|
}
|