Merge pull request #25 from Snawoot/detect_block

Detect block
This commit is contained in:
Snawoot
2021-03-12 21:01:12 +02:00
committed by GitHub
2 changed files with 35 additions and 3 deletions

View File

@@ -54,3 +54,21 @@ $(OUTSUFFIX).windows-386.exe: $(src)
clean:
rm -f bin/*
fmt:
go fmt ./...
run:
go run .
.PHONY: clean all native fmt \
bin-native \
bin-linux-amd64 \
bin-linux-386 \
bin-linux-arm \
bin-freebsd-amd64 \
bin-freebsd-386 \
bin-freebsd-arm \
bin-darwin-amd64 \
bin-windows-amd64 \
bin-windows-386

View File

@@ -5,6 +5,7 @@ import (
"context"
"encoding/hex"
"encoding/json"
"errors"
"github.com/campoy/unique"
"github.com/google/uuid"
"io/ioutil"
@@ -24,12 +25,17 @@ const BG_INIT_URL = CCGI_URL + "background_init"
const ZGETTUNNELS_URL = CCGI_URL + "zgettunnels"
const LOGIN_PREFIX = "user-uuid-"
var TemporaryBanError = errors.New("temporary ban detected")
var PermanentBanError = errors.New("permanent ban detected")
type CountryList []string
type BgInitResponse struct {
Ver string `json:"ver"`
Key int64 `json:"key"`
Country string `json:"country"`
Ver string `json:"ver"`
Key int64 `json:"key"`
Country string `json:"country"`
Blocked bool `json:"blocked,omitempty"`
Permanent bool `json:"permanent,omitempty"`
}
type PortMap struct {
@@ -118,7 +124,15 @@ func background_init(ctx context.Context, user_uuid string) (res BgInitResponse,
reterr = err
return
}
reterr = json.Unmarshal(resp, &res)
if reterr == nil && res.Blocked {
if res.Permanent {
reterr = PermanentBanError
} else {
reterr = TemporaryBanError
}
}
return
}