Skip to content
Snippets Groups Projects
Verified Commit 8967df96 authored by Tóth Miklós Tibor's avatar Tóth Miklós Tibor :shrug:
Browse files

Smol fix

parent 2a65b8bc
No related branches found
No related tags found
No related merge requests found
......@@ -31,11 +31,12 @@ type Details struct {
func Discover(d Discovered) error {
for _, ip := range d.IPs {
go func(ip string) {
resp, e := http.Get(fmt.Sprintf("http://[%s]:8080/describe", ip))
if e != nil {
log.Println("host is ded", ip)
log.Println(e)
continue
return
}
var det Details
......@@ -43,7 +44,7 @@ func Discover(d Discovered) error {
e = dec.Decode(&det)
if e != nil {
log.Println(e)
continue
return
}
if det.Score < -10 {
......@@ -52,7 +53,7 @@ func Discover(d Discovered) error {
if e != nil {
log.Println(e)
}
continue
return
}
str := ""
......@@ -66,13 +67,18 @@ func Discover(d Discovered) error {
str = strings.Repeat("9", det.Properties.MaxTokenLength)
}
go submit(ip, str)
_, e = submit(ip, str)
if e != nil {
log.Println(e)
return
}
if !nosleep {
t := time.Duration(rand.Intn(10)) * time.Second
fmt.Println("Sleeping for", t)
time.Sleep(t)
}
}(ip)
}
return nil
}
......@@ -36,7 +36,7 @@ func init() {
}
func init() {
http.DefaultClient.Timeout = time.Second * 10
http.DefaultClient.Timeout = time.Second * 4
}
func main() {
......@@ -51,6 +51,8 @@ func main() {
panic(e)
}
time.Sleep(time.Second)
go func() {
for m := range connCh {
e := c.WriteJSON(m)
......@@ -87,11 +89,12 @@ func main() {
log.Println(e)
continue
}
go func() {
e = Discover(d)
if e != nil {
log.Println(e)
continue
}
}()
case "submitted":
var s Submitted
e = json.Unmarshal(msg, &s)
......@@ -99,11 +102,12 @@ func main() {
log.Println(e)
continue
}
go func() {
e = Submit(s)
if e != nil {
log.Println(e)
continue
}
}()
case "ack":
log.Println("ack")
......
......@@ -7,7 +7,6 @@ import (
"math/rand"
"net/http"
"strings"
"time"
)
var cache = make(map[string]bool)
......@@ -18,15 +17,6 @@ func submit(ip, pass string) ([]string, error) {
}
resp, e := http.Post(fmt.Sprintf("http://[%s]:8080/attempt", ip), "text/plain", strings.NewReader(pass+"\n"))
if e != nil {
time.Sleep(time.Second * time.Duration(rand.Intn(5)))
resp, e = http.Post(fmt.Sprintf("http://[%s]:8080/attempt", ip), "text/plain", strings.NewReader(pass+"\n"))
if e != nil {
time.Sleep(time.Second * time.Duration(rand.Intn(5)))
resp, e = http.Post(fmt.Sprintf("http://[%s]:8080/attempt", ip), "text/plain", strings.NewReader(pass+"\n"))
}
}
if e != nil {
log.Println("host is ded", ip)
return nil, e
......@@ -52,6 +42,7 @@ func submit(ip, pass string) ([]string, error) {
}
return nil, e
case 200:
cache[ip] = true
var ips []string
dec := json.NewDecoder(resp.Body)
e = dec.Decode(&ips)
......
......@@ -13,7 +13,7 @@ func Submit(s Submitted) error {
time.Sleep(t)
}
go submit(s.IP, s.Text)
_, e := submit(s.IP, s.Text)
return nil
return e
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment