zettio/weave — pull request #184 by bboreham (2014-11-14 14:12:17+00:00)
Title: Extra check for duplicate connection

Add check during initial connection handshake to see whether we already have an established connection to this peer, and reject the new connection if so.

Concern: is it possible that two peers, connecting at the same time, will each consider the other connection to be established, and thus drop both? No, since 'established' is not set until after a heartbeat has passed in one direction and a ProtocolConnectionEstablished message passed in the other, which cannot happen if the connection is rejected during handshake.

It is possible that neither side rejects the new connection during handshake, in which case the duplicate will be detected in Peer.AddConnection(), and that test has a tie-breaker so both sides will make the same choice.