mirror of
https://github.com/octoleo/syncthing.git
synced 2024-11-09 23:00:58 +00:00
Refactor node ID handling, use check digits (fixes #269)
New node ID:s contain four Luhn check digits and are grouped differently. Code uses NodeID type instead of string, so it's formatted homogenously everywhere.
This commit is contained in:
parent
aff41d0b08
commit
926b08c197
@ -17,6 +17,7 @@ import (
|
|||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/calmh/syncthing/discover"
|
"github.com/calmh/syncthing/discover"
|
||||||
|
"github.com/calmh/syncthing/protocol"
|
||||||
"github.com/golang/groupcache/lru"
|
"github.com/golang/groupcache/lru"
|
||||||
"github.com/juju/ratelimit"
|
"github.com/juju/ratelimit"
|
||||||
)
|
)
|
||||||
@ -32,7 +33,7 @@ type address struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
var (
|
var (
|
||||||
nodes = make(map[string]node)
|
nodes = make(map[protocol.NodeID]node)
|
||||||
lock sync.Mutex
|
lock sync.Mutex
|
||||||
queries = 0
|
queries = 0
|
||||||
announces = 0
|
announces = 0
|
||||||
@ -182,8 +183,16 @@ func handleAnnounceV2(addr *net.UDPAddr, buf []byte) {
|
|||||||
updated: time.Now(),
|
updated: time.Now(),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var id protocol.NodeID
|
||||||
|
if len(pkt.This.ID) == 32 {
|
||||||
|
// Raw node ID
|
||||||
|
copy(id[:], pkt.This.ID)
|
||||||
|
} else {
|
||||||
|
id.UnmarshalText(pkt.This.ID)
|
||||||
|
}
|
||||||
|
|
||||||
lock.Lock()
|
lock.Lock()
|
||||||
nodes[pkt.This.ID] = node
|
nodes[id] = node
|
||||||
lock.Unlock()
|
lock.Unlock()
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -199,8 +208,16 @@ func handleQueryV2(conn *net.UDPConn, addr *net.UDPAddr, buf []byte) {
|
|||||||
log.Printf("<- %v %#v", addr, pkt)
|
log.Printf("<- %v %#v", addr, pkt)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var id protocol.NodeID
|
||||||
|
if len(pkt.NodeID) == 32 {
|
||||||
|
// Raw node ID
|
||||||
|
copy(id[:], pkt.NodeID)
|
||||||
|
} else {
|
||||||
|
id.UnmarshalText(pkt.NodeID)
|
||||||
|
}
|
||||||
|
|
||||||
lock.Lock()
|
lock.Lock()
|
||||||
node, ok := nodes[pkt.NodeID]
|
node, ok := nodes[id]
|
||||||
queries++
|
queries++
|
||||||
lock.Unlock()
|
lock.Unlock()
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user