mirror of
https://github.com/octoleo/syncthing.git
synced 2025-01-22 14:48:30 +00:00
Show status of global announce server (fixes #71)
This commit is contained in:
parent
31bfd8c039
commit
b802cb1e36
@ -168,6 +168,9 @@ func restGetSystem(w http.ResponseWriter) {
|
||||
res["goroutines"] = runtime.NumGoroutine()
|
||||
res["alloc"] = m.Alloc
|
||||
res["sys"] = m.Sys
|
||||
if discoverer != nil {
|
||||
res["extAnnounceOK"] = discoverer.ExtAnnounceOK()
|
||||
}
|
||||
cpuUsageLock.RLock()
|
||||
var cpusum float64
|
||||
for _, p := range cpuUsagePercent {
|
||||
|
@ -33,6 +33,7 @@ var (
|
||||
confDir string
|
||||
rateBucket *ratelimit.Bucket
|
||||
stop = make(chan bool)
|
||||
discoverer *discover.Discoverer
|
||||
)
|
||||
|
||||
const (
|
||||
@ -228,8 +229,8 @@ func main() {
|
||||
m.SaveIndexes(confDir)
|
||||
|
||||
// Routine to connect out to configured nodes
|
||||
disc := discovery()
|
||||
go listenConnect(myID, disc, m, tlsCfg)
|
||||
discoverer = discovery()
|
||||
go listenConnect(myID, m, tlsCfg)
|
||||
|
||||
for _, repo := range cfg.Repositories {
|
||||
// Routine to pull blocks from other nodes to synchronize the local
|
||||
@ -337,7 +338,7 @@ func saveConfig() {
|
||||
saveConfigCh <- struct{}{}
|
||||
}
|
||||
|
||||
func listenConnect(myID string, disc *discover.Discoverer, m *Model, tlsCfg *tls.Config) {
|
||||
func listenConnect(myID string, m *Model, tlsCfg *tls.Config) {
|
||||
var conns = make(chan *tls.Conn)
|
||||
|
||||
// Listen
|
||||
@ -389,8 +390,8 @@ func listenConnect(myID string, disc *discover.Discoverer, m *Model, tlsCfg *tls
|
||||
var addrs []string
|
||||
for _, addr := range nodeCfg.Addresses {
|
||||
if addr == "dynamic" {
|
||||
if disc != nil {
|
||||
t := disc.Lookup(nodeCfg.NodeID)
|
||||
if discoverer != nil {
|
||||
t := discoverer.Lookup(nodeCfg.NodeID)
|
||||
if len(t) == 0 {
|
||||
continue
|
||||
}
|
||||
|
@ -19,16 +19,18 @@ const (
|
||||
)
|
||||
|
||||
type Discoverer struct {
|
||||
MyID string
|
||||
ListenAddresses []string
|
||||
BroadcastIntv time.Duration
|
||||
ExtBroadcastIntv time.Duration
|
||||
beacon *mc.Beacon
|
||||
registry map[string][]string
|
||||
registryLock sync.RWMutex
|
||||
extServer string
|
||||
localBroadcastTick <-chan time.Time
|
||||
forcedBroadcastTick chan time.Time
|
||||
myID string
|
||||
listenAddrs []string
|
||||
localBcastIntv time.Duration
|
||||
globalBcastIntv time.Duration
|
||||
beacon *mc.Beacon
|
||||
registry map[string][]string
|
||||
registryLock sync.RWMutex
|
||||
extServer string
|
||||
localBcastTick <-chan time.Time
|
||||
forcedBcastTick chan time.Time
|
||||
extAnnounceOK bool
|
||||
extAnnounceOKmut sync.Mutex
|
||||
}
|
||||
|
||||
var (
|
||||
@ -42,24 +44,22 @@ const maxErrors = 30
|
||||
|
||||
func NewDiscoverer(id string, addresses []string) (*Discoverer, error) {
|
||||
disc := &Discoverer{
|
||||
MyID: id,
|
||||
ListenAddresses: addresses,
|
||||
BroadcastIntv: 30 * time.Second,
|
||||
ExtBroadcastIntv: 1800 * time.Second,
|
||||
beacon: mc.NewBeacon("239.21.0.25", 21025),
|
||||
registry: make(map[string][]string),
|
||||
myID: id,
|
||||
listenAddrs: addresses,
|
||||
localBcastIntv: 30 * time.Second,
|
||||
globalBcastIntv: 1800 * time.Second,
|
||||
beacon: mc.NewBeacon("239.21.0.25", 21025),
|
||||
registry: make(map[string][]string),
|
||||
}
|
||||
|
||||
// Receive announcements sent to the local multicast group.
|
||||
|
||||
go disc.recvAnnouncements()
|
||||
|
||||
return disc, nil
|
||||
}
|
||||
|
||||
func (d *Discoverer) StartLocal() {
|
||||
d.localBroadcastTick = time.Tick(d.BroadcastIntv)
|
||||
d.forcedBroadcastTick = make(chan time.Time)
|
||||
d.localBcastTick = time.Tick(d.localBcastIntv)
|
||||
d.forcedBcastTick = make(chan time.Time)
|
||||
go d.sendLocalAnnouncements()
|
||||
}
|
||||
|
||||
@ -68,9 +68,15 @@ func (d *Discoverer) StartGlobal(server string) {
|
||||
go d.sendExternalAnnouncements()
|
||||
}
|
||||
|
||||
func (d *Discoverer) ExtAnnounceOK() bool {
|
||||
d.extAnnounceOKmut.Lock()
|
||||
defer d.extAnnounceOKmut.Unlock()
|
||||
return d.extAnnounceOK
|
||||
}
|
||||
|
||||
func (d *Discoverer) announcementPkt() []byte {
|
||||
var addrs []Address
|
||||
for _, astr := range d.ListenAddresses {
|
||||
for _, astr := range d.listenAddrs {
|
||||
addr, err := net.ResolveTCPAddr("tcp", astr)
|
||||
if err != nil {
|
||||
log.Printf("discover/announcement: %v: not announcing %s", err, astr)
|
||||
@ -88,7 +94,7 @@ func (d *Discoverer) announcementPkt() []byte {
|
||||
}
|
||||
var pkt = AnnounceV2{
|
||||
Magic: AnnouncementMagicV2,
|
||||
NodeID: d.MyID,
|
||||
NodeID: d.myID,
|
||||
Addresses: addrs,
|
||||
}
|
||||
return pkt.MarshalXDR()
|
||||
@ -101,8 +107,8 @@ func (d *Discoverer) sendLocalAnnouncements() {
|
||||
d.beacon.Send(buf)
|
||||
|
||||
select {
|
||||
case <-d.localBroadcastTick:
|
||||
case <-d.forcedBroadcastTick:
|
||||
case <-d.localBcastTick:
|
||||
case <-d.forcedBcastTick:
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -124,22 +130,40 @@ func (d *Discoverer) sendExternalAnnouncements() {
|
||||
var errCounter = 0
|
||||
|
||||
for errCounter < maxErrors {
|
||||
var ok bool
|
||||
|
||||
if debug {
|
||||
dlog.Printf("send announcement -> %v\n%s", remote, hex.Dump(buf))
|
||||
}
|
||||
|
||||
_, err = conn.WriteTo(buf, remote)
|
||||
if err != nil {
|
||||
log.Println("discover/write: warning:", err)
|
||||
errCounter++
|
||||
ok = false
|
||||
} else {
|
||||
errCounter = 0
|
||||
}
|
||||
if debug {
|
||||
|
||||
// Verify that the announce server responds positively for our node ID
|
||||
|
||||
time.Sleep(1 * time.Second)
|
||||
res := d.externalLookup(d.MyID)
|
||||
dlog.Println("external lookup check:", res)
|
||||
res := d.externalLookup(d.myID)
|
||||
if debug {
|
||||
dlog.Println("external lookup check:", res)
|
||||
}
|
||||
ok = len(res) > 0
|
||||
|
||||
}
|
||||
|
||||
d.extAnnounceOKmut.Lock()
|
||||
d.extAnnounceOK = ok
|
||||
d.extAnnounceOKmut.Unlock()
|
||||
|
||||
if ok {
|
||||
time.Sleep(d.globalBcastIntv)
|
||||
} else {
|
||||
time.Sleep(60 * time.Second)
|
||||
}
|
||||
time.Sleep(d.ExtBroadcastIntv)
|
||||
}
|
||||
log.Printf("discover/write: %v: stopping due to too many errors: %v", remote, err)
|
||||
}
|
||||
@ -162,7 +186,7 @@ func (d *Discoverer) recvAnnouncements() {
|
||||
dlog.Printf("parsed announcement: %#v", pkt)
|
||||
}
|
||||
|
||||
if pkt.NodeID != d.MyID {
|
||||
if pkt.NodeID != d.myID {
|
||||
var addrs []string
|
||||
for _, a := range pkt.Addresses {
|
||||
var nodeAddr string
|
||||
@ -182,7 +206,7 @@ func (d *Discoverer) recvAnnouncements() {
|
||||
_, seen := d.registry[pkt.NodeID]
|
||||
if !seen {
|
||||
select {
|
||||
case d.forcedBroadcastTick <- time.Now():
|
||||
case d.forcedBcastTick <- time.Now():
|
||||
}
|
||||
}
|
||||
d.registry[pkt.NodeID] = addrs
|
||||
|
@ -248,6 +248,11 @@
|
||||
</div>
|
||||
</li>
|
||||
<li>
|
||||
<div ng-if="system.extAnnounceOK != undefined" class="li-column" title="Global announce server">
|
||||
<span class="text-muted glyphicon glyphicon-bullhorn"></span>
|
||||
<span class="data text-success" ng-if="system.extAnnounceOK">Online</span>
|
||||
<span class="data text-danger" ng-if="!system.extAnnounceOK">Offline</span>
|
||||
</div>
|
||||
<div class="li-column">
|
||||
<span class="text-muted glyphicon glyphicon-cog"></span>
|
||||
<span class="data"><a href="" ng-click="editNode(nodeCfg)"><span class="glyphicon glyphicon-pencil"></span> Edit</a></span>
|
||||
|
Loading…
x
Reference in New Issue
Block a user