mirror of
https://github.com/octoleo/syncthing.git
synced 2025-02-02 11:58:28 +00:00
Respond to local announces of new nodes
This commit is contained in:
parent
c6e396e8fb
commit
645233e7dc
@ -28,6 +28,9 @@ type Discoverer struct {
|
|||||||
registry map[string][]string
|
registry map[string][]string
|
||||||
registryLock sync.RWMutex
|
registryLock sync.RWMutex
|
||||||
extServer string
|
extServer string
|
||||||
|
|
||||||
|
localBroadcastTick <-chan time.Time
|
||||||
|
forcedBroadcastTick chan time.Time
|
||||||
}
|
}
|
||||||
|
|
||||||
var (
|
var (
|
||||||
@ -60,6 +63,8 @@ func NewDiscoverer(id string, port int, extServer string) (*Discoverer, error) {
|
|||||||
go disc.recvAnnouncements()
|
go disc.recvAnnouncements()
|
||||||
|
|
||||||
if disc.ListenPort > 0 {
|
if disc.ListenPort > 0 {
|
||||||
|
disc.localBroadcastTick = time.Tick(disc.BroadcastIntv)
|
||||||
|
disc.forcedBroadcastTick = make(chan time.Time)
|
||||||
go disc.sendAnnouncements()
|
go disc.sendAnnouncements()
|
||||||
}
|
}
|
||||||
if len(disc.extServer) > 0 {
|
if len(disc.extServer) > 0 {
|
||||||
@ -96,7 +101,11 @@ func (d *Discoverer) sendAnnouncements() {
|
|||||||
errCounter = 0
|
errCounter = 0
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
time.Sleep(d.BroadcastIntv)
|
|
||||||
|
select {
|
||||||
|
case <-d.localBroadcastTick:
|
||||||
|
case <-d.forcedBroadcastTick:
|
||||||
|
}
|
||||||
}
|
}
|
||||||
log.Println("discover/write: local: stopping due to too many errors:", err)
|
log.Println("discover/write: local: stopping due to too many errors:", err)
|
||||||
}
|
}
|
||||||
@ -173,6 +182,13 @@ func (d *Discoverer) recvAnnouncements() {
|
|||||||
log.Printf("register: %#v", addrs)
|
log.Printf("register: %#v", addrs)
|
||||||
}
|
}
|
||||||
d.registryLock.Lock()
|
d.registryLock.Lock()
|
||||||
|
_, seen := d.registry[pkt.NodeID]
|
||||||
|
if !seen {
|
||||||
|
fmt.Println("new node seen, forced announce")
|
||||||
|
select {
|
||||||
|
case d.forcedBroadcastTick <- time.Now():
|
||||||
|
}
|
||||||
|
}
|
||||||
d.registry[pkt.NodeID] = addrs
|
d.registry[pkt.NodeID] = addrs
|
||||||
d.registryLock.Unlock()
|
d.registryLock.Unlock()
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user