mirror of
https://github.com/kaspanet/kaspad.git
synced 2025-06-06 14:16:43 +00:00
[NOD-1289] Check if connection exists before establishing another one with the same address (#883)
This commit is contained in:
parent
fcae491e6d
commit
c331293a2e
@ -63,6 +63,7 @@ func (c *ConnectionManager) checkRequestedConnections(connSet connectionSet) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// try to initiate connection
|
// try to initiate connection
|
||||||
|
log.Debugf("Connecting to connection request %s", connReq.address)
|
||||||
err := c.initiateConnection(connReq.address)
|
err := c.initiateConnection(connReq.address)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Infof("Couldn't connect to %s: %s", address, err)
|
log.Infof("Couldn't connect to %s: %s", address, err)
|
||||||
|
@ -143,3 +143,19 @@ func (c *ConnectionManager) waitTillNextIteration() {
|
|||||||
case <-c.loopTicker.C:
|
case <-c.loopTicker.C:
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (c *ConnectionManager) connectionExists(addressString string) bool {
|
||||||
|
if _, ok := c.activeRequested[addressString]; ok {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
if _, ok := c.activeOutgoing[addressString]; ok {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
if _, ok := c.activeIncoming[addressString]; ok {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
@ -39,6 +39,12 @@ func (c *ConnectionManager) checkOutgoingConnections(connSet connectionSet) {
|
|||||||
netAddress := address.NetAddress()
|
netAddress := address.NetAddress()
|
||||||
tcpAddress := netAddress.TCPAddress()
|
tcpAddress := netAddress.TCPAddress()
|
||||||
addressString := tcpAddress.String()
|
addressString := tcpAddress.String()
|
||||||
|
|
||||||
|
if c.connectionExists(addressString) {
|
||||||
|
log.Debugf("Fetched address %s from address manager but it's already connected. Skipping...", addressString)
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
isBanned, err := c.addressManager.IsBanned(netAddress)
|
isBanned, err := c.addressManager.IsBanned(netAddress)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Infof("Couldn't resolve whether %s is banned: %s", addressString, err)
|
log.Infof("Couldn't resolve whether %s is banned: %s", addressString, err)
|
||||||
@ -49,6 +55,8 @@ func (c *ConnectionManager) checkOutgoingConnections(connSet connectionSet) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
c.addressManager.Attempt(netAddress)
|
c.addressManager.Attempt(netAddress)
|
||||||
|
log.Debugf("Connecting to %s because we have %d outgoing connections and the target is "+
|
||||||
|
"%d", addressString, len(c.activeOutgoing), c.targetOutgoing)
|
||||||
err = c.initiateConnection(addressString)
|
err = c.initiateConnection(addressString)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Infof("Couldn't connect to %s: %s", addressString, err)
|
log.Infof("Couldn't connect to %s: %s", addressString, err)
|
||||||
|
@ -53,7 +53,7 @@ func (c *gRPCConnection) Start(router *router.Router) {
|
|||||||
spawn("gRPCConnection.Start-connectionLoops", func() {
|
spawn("gRPCConnection.Start-connectionLoops", func() {
|
||||||
err := c.connectionLoops()
|
err := c.connectionLoops()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Errorf("error from connectionLoops for %s: %+v", c.address, err)
|
log.Errorf("error from connectionLoops for %s: %s", c.address, err)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user