this is supposed to execute every second to be able to calulate the difference of the transmitted bytes
All checks were successful
CI / build (push) Successful in 51s
All checks were successful
CI / build (push) Successful in 51s
This commit is contained in:
parent
538aa2e7e8
commit
70232f56bf
1 changed files with 9 additions and 11 deletions
20
main.go
20
main.go
|
@ -13,7 +13,6 @@ import (
|
|||
"os"
|
||||
"regexp"
|
||||
"runtime"
|
||||
"strconv"
|
||||
"strings"
|
||||
"sync/atomic"
|
||||
"syscall"
|
||||
|
@ -334,10 +333,10 @@ func requestPerMinute() {
|
|||
// returns, which most of the time is 403 (Forbidden). But this error code is not
|
||||
// exclusive to IP blocks, it's also returned for other reasons like a wrong
|
||||
// query parameter like `pot` (po_token) or anything like that.
|
||||
func blockChecker(gh string, cooldown int) {
|
||||
func blockChecker(gh string) {
|
||||
log.Println("[INFO] Starting blockchecker")
|
||||
// Sleep for 30 seconds before commencing the loop
|
||||
time.Sleep(30 * time.Second)
|
||||
// Sleep for 60 seconds before commencing the loop
|
||||
time.Sleep(60 * time.Second)
|
||||
url := "http://" + gh + "/v1/openvpn/status"
|
||||
|
||||
p, err := procfs.Self()
|
||||
|
@ -354,7 +353,7 @@ func blockChecker(gh string, cooldown int) {
|
|||
stat, _ := p.NetDev()
|
||||
current := stat.Total().TxBytes
|
||||
aux := current - last
|
||||
if float64(aux)*0.000008 < 3.0 {
|
||||
if float64(aux)*0.000008 < 2.0 {
|
||||
body := "{\"status\":\"stopped\"}\""
|
||||
// This should never fail too
|
||||
request, _ := http.NewRequest("PUT", url, strings.NewReader(body))
|
||||
|
@ -364,7 +363,6 @@ func blockChecker(gh string, cooldown int) {
|
|||
} else {
|
||||
log.Printf("[INFO] Request to change IP sent to gluetun successfully")
|
||||
}
|
||||
time.Sleep(time.Duration(cooldown) * time.Second)
|
||||
}
|
||||
last = current
|
||||
}
|
||||
|
@ -546,11 +544,11 @@ func main() {
|
|||
go requestPerSecond()
|
||||
go requestPerMinute()
|
||||
if bc {
|
||||
num, err := strconv.Atoi(bc_cooldown)
|
||||
if err != nil {
|
||||
log.Fatalf("[FATAL] Error while setting BLOCK_CHECKER_COOLDOWN: %s", err)
|
||||
}
|
||||
go blockChecker(gh, num)
|
||||
// num, err := strconv.Atoi(bc_cooldown)
|
||||
// if err != nil {
|
||||
// log.Fatalf("[FATAL] Error while setting BLOCK_CHECKER_COOLDOWN: %s", err)
|
||||
// }
|
||||
go blockChecker(gh)
|
||||
}
|
||||
|
||||
ln, err := net.Listen("tcp", host+":"+port)
|
||||
|
|
Loading…
Add table
Reference in a new issue