From a39b85696380f210bd1d4196e0a66b5f2192dfbe Mon Sep 17 00:00:00 2001 From: sdghchj Date: Mon, 6 Dec 2021 18:26:54 +0800 Subject: [PATCH] Keep only one connection between two peers If a connection terminates with a dup error, do not add its remoteTCPAddress back into the targets --- connection_maker.go | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/connection_maker.go b/connection_maker.go index df8d04c..93cbb52 100644 --- a/connection_maker.go +++ b/connection_maker.go @@ -195,6 +195,11 @@ func (cm *connectionMaker) connectionTerminated(conn Connection, err error) { } delete(cm.connections, conn) if conn.isOutbound() { + if conn.Remote() != nil { + if _, ok := cm.ourself.Peer.connections[conn.Remote().Name]; ok { + return true + } + } target := cm.targets[conn.remoteTCPAddress()] target.state = targetWaiting target.lastError = err