refactor: abstract away connection tie breaking
So we don't need to carry that logic in LocalPeer
This commit is contained in:
1 parent
6efa794ab4
commit
9302105a2e
2 files changed
+28
-9
No files matched your search
@@ -189,21 +189,20 @@ func (peer *LocalPeer) handleAddConnection(conn *LocalConnection) {
|
||||
if dupConn == conn {
|
||||
return
|
||||
}
|
||||
// conn.UID is used as the tie breaker here, in the
|
||||
// knowledge that both sides will make the same decision.
|
||||
dupConnLocal := dupConn.(*LocalConnection)
|
||||
if conn.UID == dupConnLocal.UID {
|
||||
switch conn.BreakTie(dupConnLocal) {
|
||||
case TieBreakWon:
|
||||
dupConnLocal.CheckFatal(dupErr)
|
||||
peer.handleDeleteConnection(dupConnLocal)
|
||||
case TieBreakLost:
|
||||
conn.CheckFatal(dupErr)
|
||||
return
|
||||
case TieBreakTied:
|
||||
// oh good grief. Sod it, just kill both of them.
|
||||
conn.CheckFatal(dupErr)
|
||||
dupConnLocal.CheckFatal(dupErr)
|
||||
peer.handleDeleteConnection(dupConnLocal)
|
||||
return
|
||||
} else if conn.UID < dupConnLocal.UID {
|
||||
dupConnLocal.CheckFatal(dupErr)
|
||||
peer.handleDeleteConnection(dupConnLocal)
|
||||
} else {
|
||||
conn.CheckFatal(dupErr)
|
||||
return
|
||||
}
|
||||
}
|
||||
if err := peer.checkConnectionLimit(); err != nil {
|
||||
|
||||
Reference in new issue
Block a user