From 57aecb868f9b57f42c3a32bce0b453e60061432d Mon Sep 17 00:00:00 2001 From: Bryan Boreham Date: Fri, 14 Nov 2014 14:01:11 +0000 Subject: [PATCH 1/2] Add check during initial handshake whether we already have an established connection to this peer --- router/connection.go | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/router/connection.go b/router/connection.go index 488f9a48..64b4ee04 100644 --- a/router/connection.go +++ b/router/connection.go @@ -345,6 +345,11 @@ func (conn *LocalConnection) handshake(acceptNewPeer bool) error { return fmt.Errorf("Found unknown remote name: %s at %s", name, conn.remoteTCPAddr) } } + if existingConn, found := conn.local.ConnectionTo(name); found { + if existingConn.Established() { + return fmt.Errorf("Already have connection to %s at %s", name, existingConn.RemoteTCPAddr()) + } + } uidStr, err := checkHandshakeStringField("UID", "", handshakeRecv) if err != nil { From 997e6ed2b982e6455348bb82a2725de91f28093e Mon Sep 17 00:00:00 2001 From: Bryan Boreham Date: Fri, 14 Nov 2014 14:28:45 +0000 Subject: [PATCH 2/2] squash two ifs together --- router/connection.go | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/router/connection.go b/router/connection.go index 64b4ee04..72efc333 100644 --- a/router/connection.go +++ b/router/connection.go @@ -345,10 +345,8 @@ func (conn *LocalConnection) handshake(acceptNewPeer bool) error { return fmt.Errorf("Found unknown remote name: %s at %s", name, conn.remoteTCPAddr) } } - if existingConn, found := conn.local.ConnectionTo(name); found { - if existingConn.Established() { - return fmt.Errorf("Already have connection to %s at %s", name, existingConn.RemoteTCPAddr()) - } + if existingConn, found := conn.local.ConnectionTo(name); found && existingConn.Established() { + return fmt.Errorf("Already have connection to %s at %s", name, existingConn.RemoteTCPAddr()) } uidStr, err := checkHandshakeStringField("UID", "", handshakeRecv)