summaryrefslogtreecommitdiff
path: root/verify/verify.go
blob: 15b4f6be7fc8f989e292c14314eb8b3d454b20f3 (plain)
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
package verify

var AreaAvailableID = 80018499
var SelfMadeAvailableID = 80197526
var NonSelfMadeAvailableID = 70143836

const (
	NetworkUnrachable       = -2
	AreaUnavailable         = -1
	AreaAvailable           = 0
	UnblockSelfMadeMovie    = 1
	UnblockNonSelfMadeMovie = 2
)

type Verify interface {
	Execute() *VerifyResponse
}

type FinalResult struct {
	Res map[int]VerifyResponse
}

type VerifyResult struct {
	Config
	response chan *VerifyResponse
}

type Config struct {
	LocalAddr string
	Custom    string
}

type VerifyResponse struct {
	Type        int
	StatusCode  int
	CountryCode string
	CountryName string
}

type UnblockTestResult struct {
	movieID     int
	CountryCode string
	err         error
}

func NewVerify(c Config) *FinalResult {
	var finalResult FinalResult
	finalResult.Res = make(map[int]VerifyResponse)

	vr := VerifyResult{Config: c}
	ch := make(chan *VerifyResponse)
	vr.response = ch
	defer close(ch)

	go vr.IPv4Verifier()
	go vr.IPv6Verifier()

	for i := 0; i < 2; i++ {
		if res, err := <-ch; err {
			finalResult.Res[res.Type] = *res
		}
	}
	return &finalResult
}

func (vr *VerifyResult) IPv4Verifier() {
	verify := &IPv4Verifier{Config: vr.Config}
	vr.response <- verify.Execute()
}

func (vr *VerifyResult) IPv6Verifier() {
	verify := &IPv6Verifier{Config: vr.Config}
	vr.response <- verify.Execute()
}