refactor: make LocalConnection uid 'private'

which makes sense now that we've abstracted tie breaking
This commit is contained in:
Matthias Radestock committed 2015-01-21 20:46:45 +00:00
1 parent 9302105a2e
commit fe07a41dc3
1 file changed
+7 -7
+7 -7
View File
@@ -56,7 +56,7 @@ type LocalConnection struct {
verifyPMTU chan<- int verifyPMTU chan<- int
Decryptor Decryptor Decryptor Decryptor
Router *Router Router *Router
UID uint64 uid uint64
queryChan chan<- *ConnectionInteraction queryChan chan<- *ConnectionInteraction
} }
@@ -125,11 +125,11 @@ func (conn *LocalConnection) Start(acceptNewPeer bool) {
} }
func (conn *LocalConnection) BreakTie(dupConn *LocalConnection) ConnectionTieBreak { func (conn *LocalConnection) BreakTie(dupConn *LocalConnection) ConnectionTieBreak {
// conn.UID is used as the tie breaker here, in the knowledge that // conn.uid is used as the tie breaker here, in the knowledge that
// both sides will make the same decision. // both sides will make the same decision.
if conn.UID < dupConn.UID { if conn.uid < dupConn.uid {
return TieBreakWon return TieBreakWon
} else if dupConn.UID < conn.UID { } else if dupConn.uid < conn.uid {
return TieBreakLost return TieBreakLost
} else { } else {
return TieBreakTied return TieBreakTied
@@ -206,7 +206,7 @@ func (conn *LocalConnection) Shutdown(err error) {
// b) updating a remote peer's knowledge of our address, in the event // b) updating a remote peer's knowledge of our address, in the event
// it changes (e.g. because NAT paths expired). // it changes (e.g. because NAT paths expired).
func (conn *LocalConnection) ReceivedHeartbeat(remoteUDPAddr *net.UDPAddr, connUID uint64) { func (conn *LocalConnection) ReceivedHeartbeat(remoteUDPAddr *net.UDPAddr, connUID uint64) {
if remoteUDPAddr == nil || connUID != conn.UID { if remoteUDPAddr == nil || connUID != conn.uid {
return return
} }
conn.queryChan <- &ConnectionInteraction{ conn.queryChan <- &ConnectionInteraction{
@@ -243,7 +243,7 @@ func (conn *LocalConnection) run(queryChan <-chan *ConnectionInteraction, accept
log.Printf("->[%s] completed handshake with %s\n", conn.remoteTCPAddr, conn.remote.Name) log.Printf("->[%s] completed handshake with %s\n", conn.remoteTCPAddr, conn.remote.Name)
heartbeatFrameBytes := make([]byte, EthernetOverhead+8) heartbeatFrameBytes := make([]byte, EthernetOverhead+8)
binary.BigEndian.PutUint64(heartbeatFrameBytes[EthernetOverhead:], conn.UID) binary.BigEndian.PutUint64(heartbeatFrameBytes[EthernetOverhead:], conn.uid)
conn.heartbeatFrame = &ForwardedFrame{ conn.heartbeatFrame = &ForwardedFrame{
srcPeer: conn.local, srcPeer: conn.local,
dstPeer: conn.remote, dstPeer: conn.remote,
@@ -474,7 +474,7 @@ func (conn *LocalConnection) handshake(enc *gob.Encoder, dec *gob.Decoder, accep
if err != nil { if err != nil {
return err return err
} }
conn.UID = localConnID ^ remoteConnID conn.uid = localConnID ^ remoteConnID
if usingPassword { if usingPassword {
remotePublicStr, rpErr := checkHandshakeStringField("PublicKey", "", handshakeRecv) remotePublicStr, rpErr := checkHandshakeStringField("PublicKey", "", handshakeRecv)