func askForGreenLight() bool { url, err := http.ParseURL(sys.TangraServerURL) if err != nil { panic("tangra, bad URL") } req := &http.Request{ Method: "GET", URL: url, Close: true, UserAgent: sys.Name + "-Client-Tangra", } req.Header = make(map[string]string) req.Header["Tonika-Build"] = sys.Build req.Header["Tonika-Released"] = sys.Released // Connect conn, err := net.Dial("tcp", "", url.Host) if err != nil { if conn != nil { conn.Close() } return true } cc := http.NewClientConn(conn, nil) // Send request err = cc.Write(req) if err != nil { cc.Close() conn.Close() return true } resp, err := cc.Read() if err != nil { cc.Close() conn.Close() return true } cc.Close() conn.Close() if resp.Header == nil { return true } green, ok := resp.Header["Green"] if !ok { return true } green = strings.TrimSpace(green) if green == "Halt" { return false } return true }
func MakeMonitor(dumper json.Marshaler, reportURL string, every int64) *Monitor { key, err := crypto.ParseCipherMsgPubKey(sys.MonitorPubKey) if err != nil { panic("invalid monitor key") } mon := &Monitor{dumper, key} url, err := http.ParseURL(reportURL) if err != nil { panic("mon, bad report URL") } go mon.report(url, every) return mon }