|
|
|
@ -520,6 +520,8 @@ func NewLocalBackend(logf logger.Logf, logID logid.PublicID, sys *tsd.System, lo
|
|
|
|
b.currentNodeAtomic.Store(nb)
|
|
|
|
b.currentNodeAtomic.Store(nb)
|
|
|
|
nb.ready()
|
|
|
|
nb.ready()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
sys.Engine.Get().SetPeerByIPLookupFunc(b.lookupPeerByIP)
|
|
|
|
|
|
|
|
|
|
|
|
if sys.InitialConfig != nil {
|
|
|
|
if sys.InitialConfig != nil {
|
|
|
|
if err := b.initPrefsFromConfig(sys.InitialConfig); err != nil {
|
|
|
|
if err := b.initPrefsFromConfig(sys.InitialConfig); err != nil {
|
|
|
|
return nil, err
|
|
|
|
return nil, err
|
|
|
|
@ -651,6 +653,25 @@ func (b *LocalBackend) currentNode() *nodeBackend {
|
|
|
|
return b.currentNodeAtomic.Load()
|
|
|
|
return b.currentNodeAtomic.Load()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func (b *LocalBackend) lookupPeerByIP(ip netip.Addr) (peerKey key.NodePublic, ok bool) {
|
|
|
|
|
|
|
|
nb := b.currentNode()
|
|
|
|
|
|
|
|
nb.mu.Lock()
|
|
|
|
|
|
|
|
defer nb.mu.Unlock()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
nid, ok := nb.nodeByAddr[ip]
|
|
|
|
|
|
|
|
if !ok {
|
|
|
|
|
|
|
|
log.Printf("lookupPeerByIP: %v -> no node ID", ip)
|
|
|
|
|
|
|
|
return key.NodePublic{}, false
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
peer, ok := nb.peers[nid]
|
|
|
|
|
|
|
|
if !ok {
|
|
|
|
|
|
|
|
log.Printf("lookupPeerByIP: no node ID %v", nid)
|
|
|
|
|
|
|
|
return key.NodePublic{}, false
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
log.Printf("lookupPeerByIP: %v -> %v (%v)", ip, peer.Name(), peer.Key())
|
|
|
|
|
|
|
|
return peer.Key(), true
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// FindExtensionByName returns an active extension with the given name,
|
|
|
|
// FindExtensionByName returns an active extension with the given name,
|
|
|
|
// or nil if no such extension exists.
|
|
|
|
// or nil if no such extension exists.
|
|
|
|
func (b *LocalBackend) FindExtensionByName(name string) any {
|
|
|
|
func (b *LocalBackend) FindExtensionByName(name string) any {
|
|
|
|
|