From afe3e3f7327a99d285aef3ef16bd781215f7ea99 Mon Sep 17 00:00:00 2001 From: Vladislav Yarmak Date: Fri, 12 Mar 2021 20:58:30 +0200 Subject: [PATCH 1/2] detect ban in bg_init response --- holaapi.go | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/holaapi.go b/holaapi.go index b93c1e4..2640505 100644 --- a/holaapi.go +++ b/holaapi.go @@ -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 } From 9c15f5eda9bfff6fd22574c03f06572932862cd4 Mon Sep 17 00:00:00 2001 From: Vladislav Yarmak Date: Fri, 12 Mar 2021 20:59:26 +0200 Subject: [PATCH 2/2] add few helper targets to makefile --- Makefile | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/Makefile b/Makefile index f49ff10..a2710c9 100644 --- a/Makefile +++ b/Makefile @@ -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