starting to watch all the engines run
Signed-off-by: Jeff Carr <jcarr@wit.com>
This commit is contained in:
parent
1208cdeda6
commit
8e4d24a3d0
7
gui.go
7
gui.go
|
@ -38,8 +38,8 @@ func debugTab(title string) {
|
|||
debugger.DebugWindow(me.myGui)
|
||||
})
|
||||
|
||||
g2.NewButton("dig A & AAAA DNS records", func () {
|
||||
log.Println("updateDNS()")
|
||||
g2.NewButton("dig A & AAAA DNS records (updateDNS())", func () {
|
||||
log.Log(CHANGE, "updateDNS() going to run:")
|
||||
updateDNS()
|
||||
})
|
||||
|
||||
|
@ -200,6 +200,7 @@ func statusGrid(n *gui.Node) {
|
|||
|
||||
// run everything because something has changed
|
||||
func updateDNS() {
|
||||
log.Log(CHANGE, "updateDNS() START")
|
||||
me.digStatus.Update()
|
||||
me.statusDNS.Update()
|
||||
|
||||
|
@ -215,5 +216,5 @@ func updateDNS() {
|
|||
// if your host is test.wit.com, find the NS resource records for wit.com
|
||||
lookupNS(me.statusOS.GetDomainName())
|
||||
|
||||
log.Println("updateDNS() END")
|
||||
log.Log(CHANGE, "updateDNS() END")
|
||||
}
|
||||
|
|
162
main.go
162
main.go
|
@ -6,7 +6,7 @@ package main
|
|||
|
||||
import (
|
||||
"fmt"
|
||||
"runtime"
|
||||
// "runtime"
|
||||
"time"
|
||||
"embed"
|
||||
|
||||
|
@ -60,107 +60,39 @@ func main() {
|
|||
}()
|
||||
}
|
||||
|
||||
// forever monitor for network and dns changes
|
||||
log.Sleep(me.artificialSleep)
|
||||
checkNetworkChanges()
|
||||
|
||||
// TCP & UDP port 53 lookups + DNS over HTTP lookups + os.Exec(dig)
|
||||
go myTicker(60 * time.Second, "DNSloop", func() {
|
||||
me.digStatus.Update()
|
||||
|
||||
if me.digStatus.Ready() {
|
||||
current := me.statusIPv6.Get()
|
||||
if me.digStatus.IPv6() {
|
||||
if current != "WORKING" {
|
||||
log.Log(CHANGE, "IPv6 resolution is WORKING")
|
||||
me.statusIPv6.Set("WORKING")
|
||||
}
|
||||
|
||||
/*
|
||||
Poll for changes to the networking settings
|
||||
*/
|
||||
|
||||
/* https://github.com/robfig/cron/blob/master/cron.go
|
||||
|
||||
// Run the cron scheduler, or no-op if already running.
|
||||
func (c *Cron) Run() {
|
||||
c.runningMu.Lock()
|
||||
if c.running {
|
||||
c.runningMu.Unlock()
|
||||
return
|
||||
}
|
||||
c.running = true
|
||||
c.runningMu.Unlock()
|
||||
c.run()
|
||||
}
|
||||
|
||||
// run the scheduler.. this is private just due to the need to synchronize
|
||||
// access to the 'running' state variable.
|
||||
func (c *Cron) run() {
|
||||
c.logger.Info("start")
|
||||
*/
|
||||
|
||||
func checkNetworkChanges() {
|
||||
var lastLocal time.Time = time.Now()
|
||||
var lastDNS time.Time = time.Now()
|
||||
|
||||
timer2 := time.NewTimer(time.Second)
|
||||
go func() {
|
||||
<-timer2.C
|
||||
fmt.Println("Timer 2 fired")
|
||||
}()
|
||||
|
||||
for {
|
||||
time.Sleep(me.ttl.Duration)
|
||||
if (time.Since(lastLocal) > me.localSleep) {
|
||||
if (runtime.GOOS == "linux") {
|
||||
duration := timeFunction(linuxLoop)
|
||||
s := fmt.Sprint(duration)
|
||||
me.statusOS.SetSpeedActual(s)
|
||||
} else {
|
||||
// TODO: make windows and macos diagnostics
|
||||
log.Warn("Windows and MacOS don't work yet")
|
||||
if current != "Need VPN" {
|
||||
log.Log(CHANGE, "IPv6 resolution seems to have broken")
|
||||
me.statusIPv6.Set("Need VPN")
|
||||
}
|
||||
lastLocal = time.Now()
|
||||
}
|
||||
if (time.Since(lastDNS) > me.dnsTtl.Duration) {
|
||||
DNSloop()
|
||||
lastDNS = time.Now()
|
||||
}
|
||||
})
|
||||
|
||||
/*
|
||||
stop2 := timer2.Stop()
|
||||
if stop2 {
|
||||
fmt.Println("Timer 2 stopped")
|
||||
}
|
||||
*/
|
||||
}
|
||||
}
|
||||
// checks if your DNS records are still broken
|
||||
// if everything is working, then it just ignores
|
||||
// things until the timeout happens
|
||||
go myTicker(10 * time.Second, "DNSloop", func() {
|
||||
log.Log(CHANGE, "me.statusDNS.Update() START")
|
||||
me.statusDNS.Update()
|
||||
})
|
||||
|
||||
// run this on each timeout
|
||||
func DNSloop() {
|
||||
duration := timeFunction(dnsTTL)
|
||||
log.Info("dnsTTL() execution Time: ", duration)
|
||||
var s, newSpeed string
|
||||
if (duration > 5000 * time.Millisecond ) {
|
||||
newSpeed = "VERY SLOW"
|
||||
} else if (duration > 2000 * time.Millisecond ) {
|
||||
newSpeed = "SLOWER"
|
||||
} else if (duration > 500 * time.Millisecond ) {
|
||||
newSpeed = "SLOW"
|
||||
} else if (duration > 100 * time.Millisecond ) {
|
||||
newSpeed = "OK"
|
||||
} else {
|
||||
newSpeed = "FAST"
|
||||
}
|
||||
if (newSpeed != me.DnsSpeedLast) {
|
||||
log.Log(CHANGE, "dns lookup speed changed =", newSpeed)
|
||||
log.Log(CHANGE, "dnsTTL() execution Time: ", duration)
|
||||
me.DnsSpeed.SetText(newSpeed)
|
||||
me.DnsSpeedLast = newSpeed
|
||||
}
|
||||
s = fmt.Sprint(duration)
|
||||
me.DnsSpeedActual.SetText(s)
|
||||
}
|
||||
|
||||
// This checks for changes to the network settings
|
||||
// and verifies that DNS is working or not working
|
||||
func dnsTTL() {
|
||||
updateDNS()
|
||||
}
|
||||
|
||||
// run update on the LinuxStatus() window
|
||||
// also update a few things on the main window
|
||||
func linuxLoop() {
|
||||
// probes the OS network settings
|
||||
myTicker(500 * time.Millisecond, "me.statusOS,Update()", func() {
|
||||
duration := timeFunction( func() {
|
||||
me.statusOS.Update()
|
||||
|
||||
if me.statusOS.ValidHostname() {
|
||||
|
@ -170,12 +102,17 @@ func linuxLoop() {
|
|||
}
|
||||
}
|
||||
|
||||
// re-check DNS API provider
|
||||
if (me.statusOS.Changed()) {
|
||||
stamp := time.Now().Format("2006/01/02 15:04:05")
|
||||
log.Log(CHANGE, "Network things changed on", stamp)
|
||||
duration := timeFunction(updateDNS)
|
||||
log.Log(CHANGE, "updateDNS() execution Time: ", duration)
|
||||
// lookup the NS records for your domain
|
||||
// if your host is test.wit.com, find the NS resource records for wit.com
|
||||
lookupNS(me.statusOS.GetDomainName())
|
||||
log.Log(CHANGE, "updateDNS() END")
|
||||
}
|
||||
})
|
||||
s := fmt.Sprint(duration)
|
||||
me.statusOS.SetSpeedActual(s)
|
||||
})
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -190,3 +127,32 @@ func timeFunction(f func()) time.Duration {
|
|||
f() // Execute the function
|
||||
return time.Since(startTime) // Calculate the elapsed time
|
||||
}
|
||||
|
||||
func timeStamp() string {
|
||||
stamp := time.Now().Format("2006/01/02 15:04:05")
|
||||
log.Log(CHANGE, "Network things changed on", stamp)
|
||||
return stamp
|
||||
}
|
||||
|
||||
|
||||
func myTicker(t time.Duration, name string, f func()) {
|
||||
ticker := time.NewTicker(t)
|
||||
defer ticker.Stop()
|
||||
done := make(chan bool)
|
||||
/*
|
||||
go func() {
|
||||
time.Sleep(10 * time.Second)
|
||||
done <- true
|
||||
}()
|
||||
*/
|
||||
for {
|
||||
select {
|
||||
case <-done:
|
||||
fmt.Println("Done!")
|
||||
return
|
||||
case t := <-ticker.C:
|
||||
log.Log(INFO, name, "Current time: ", t)
|
||||
f()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue