diff --git a/gui.go b/gui.go index e5c15f4..4a7b89f 100644 --- a/gui.go +++ b/gui.go @@ -107,19 +107,19 @@ func debugTab(title string) { g2 = tab.NewGroup("debugging options") // DEBUG flags - dbOn := g2.NewCheckbox("turn on debugging (will override all flags below)") - dbOn.Custom = func() { - DEBUGON = dbOn.B + me.dbOn = g2.NewCheckbox("turn on debugging (will override all flags below)") + me.dbOn.Custom = func() { + DEBUGON = me.dbOn.B } - dbNet := g2.NewCheckbox("turn on network debugging)") - dbNet.Custom = func() { - DEBUGNET = dbNet.B + me.dbNet = g2.NewCheckbox("turn on network debugging)") + me.dbNet.Custom = func() { + DEBUGNET = me.dbNet.B } - dbProc := g2.NewCheckbox("turn on /proc debugging)") - dbProc.Custom = func() { - DEBUGPROC = dbProc.B + me.dbProc = g2.NewCheckbox("turn on /proc debugging)") + me.dbProc.Custom = func() { + DEBUGPROC = me.dbProc.B } // various timeout settings @@ -151,9 +151,9 @@ func myDefaultExit(n *gui.Node) { func dnsTab(title string) { tab := me.window.NewTab(title) - g := tab.NewGroup("dns update") + me.mainStatus = tab.NewGroup("dns update") - grid := g.NewGrid("gridnuts", 2, 2) + grid := me.mainStatus.NewGrid("gridnuts", 2, 2) grid.SetNext(1,1) grid.NewLabel("hostname =") @@ -183,7 +183,7 @@ func dnsTab(title string) { me.DnsStatus = grid.NewLabel("unknown") */ - me.fix = g.NewButton("Fix", func () { + me.fix = me.mainStatus.NewButton("Fix", func () { if (goodHostname(me.hostname)) { log.Println("hostname is good:", me.hostname) } else { @@ -191,6 +191,7 @@ func dnsTab(title string) { return } nsupdate() + me.fixProc.Disable() }) me.fix.Disable() @@ -300,3 +301,22 @@ func updateDNS() { } log.Println("updateDNS() END") } + +func suggestProcDebugging() { + if (me.fixProc != nil) { + // me.fixProc.Disable() + return + } + + me.fixProc = me.mainStatus.NewButton("Try debugging Slow DNS lookups", func () { + debug("You're DNS lookups are very slow") + me.dbOn.Set(true) + me.dbProc.Set(true) + + DEBUGON = true + DEBUGPROC = true + processName := getProcessNameByPort(53) + log.Println("Process with port 53:", processName) + }) + // me.fixProc.Disable() +} diff --git a/main.go b/main.go index 80336ca..e9976f6 100644 --- a/main.go +++ b/main.go @@ -58,23 +58,9 @@ func checkNetworkChanges() { ttl -= 1 if (ttl < 0) { if (runtime.GOOS == "linux") { - duration := timeFunction(dnsTTL) - log.Println("dnsTTL() execution Time: ", duration) - var s string - if (duration > 5000 * time.Millisecond ) { - s = fmt.Sprint("VERY BAD\n", duration) - } else if (duration > 2000 * time.Millisecond ) { - s = fmt.Sprint("BAD\n", duration) - } else if (duration > 500 * time.Millisecond ) { - s = fmt.Sprint("SLOW\n", duration) - } else if (duration > 100 * time.Millisecond ) { - s = fmt.Sprint("OK\n", duration) - } else { - s = fmt.Sprint("FAST\n", duration) - } - log.Println(true, "getHostname()", s) - me.DnsSpeed.SetText(s) + linuxLoop() } else { + // TODO: make windows and macos diagnostics log.Println("Windows and MacOS don't work yet") } ttl = me.dnsTTL @@ -82,6 +68,31 @@ func checkNetworkChanges() { } } +// run this on each timeout +func linuxLoop() { + duration := timeFunction(dnsTTL) + log.Println("dnsTTL() execution Time: ", duration) + var s string + if (duration > 5000 * time.Millisecond ) { + s = fmt.Sprint("VERY BAD\n", duration) + suggestProcDebugging() + } else if (duration > 2000 * time.Millisecond ) { + s = fmt.Sprint("BAD\n", duration) + suggestProcDebugging() + } else if (duration > 500 * time.Millisecond ) { + s = fmt.Sprint("SLOW\n", duration) + } else if (duration > 100 * time.Millisecond ) { + s = fmt.Sprint("OK\n", duration) + } else { + s = fmt.Sprint("FAST\n", duration) + if (me.fixProc != nil) { + me.fixProc.Disable() + } + } + log.Println(true, "getHostname()", s) + me.DnsSpeed.SetText(s) +} + // This checks for changes to the network settings // and verifies that DNS is working or not working func dnsTTL() { @@ -111,9 +122,10 @@ func dnsTTL() { updateDNS() } + /* processName := getProcessNameByPort(53) fmt.Println("Process with port 53:", processName) - /* + commPath := filepath.Join("/proc", proc.Name(), "comm") comm, err := ioutil.ReadFile(commPath) if err != nil { diff --git a/structs.go b/structs.go index dbae2c5..57052d6 100644 --- a/structs.go +++ b/structs.go @@ -38,7 +38,15 @@ type Host struct { DnsA *gui.Node // the actual DNS A results (ignore for status since mostly never happens?) DnsStatus *gui.Node // the current state of DNS DnsSpeed *gui.Node // the current state of DNS + fix *gui.Node // button for the user to click + fixProc *gui.Node // button for the user to click + + mainStatus *gui.Node // group for the main display of stuff + + dbOn *gui.Node // button for setting debugging on + dbNet *gui.Node // button for setting network debugging on + dbProc *gui.Node // button for setting proc debugging on } type IPtype struct {