-
Notifications
You must be signed in to change notification settings - Fork 1
/
healthCheck.go
52 lines (46 loc) · 1.04 KB
/
healthCheck.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
package main
import (
"net/http"
"time"
log "github.com/sirupsen/logrus"
"golang.org/x/net/proxy"
)
//HealthCheck tor circuit checker
func HealthCheck(t []TorStruct) {
log.WithFields(log.Fields{
"Len": len(t),
}).Info("Start check tor circuit")
for i, v := range t {
dialSocksProxy, err := proxy.SOCKS5("tcp", *hostNode+":"+v.Port, nil, proxy.Direct)
if err != nil {
log.Error(err)
}
tr := &http.Transport{
Dial: dialSocksProxy.Dial,
}
_, res, err := Curl(&http.Client{
Transport: tr,
Timeout: 10 * time.Second,
})
if err != nil || res.StatusCode != http.StatusOK {
log.WithFields(log.Fields{
"Error": err,
"IP Addr": v.IPAddr,
"Country": v.Country,
}).Info("Delete dirty circuit")
v.DeleteCircuit()
t = RemoveTorList(t, i)
log.Info("Request new tor circuit")
newTor, err := initTor(1)
if err != nil {
log.Error(err)
}
t = append(t, newTor...)
} else {
log.WithFields(log.Fields{
"IP Addr": v.IPAddr,
"Country": v.Country,
}).Info("Circuit OK")
}
}
}