-
Notifications
You must be signed in to change notification settings - Fork 1
/
types.go
154 lines (134 loc) · 2.38 KB
/
types.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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
package types
import (
"fmt"
"net/http"
"time"
)
type NATType int
const (
NATUnknown NATType = iota
NATOpenInternet
NATSymmetric
NATFullCone
NATRestricted
NATPortRestricted
NATUDPBlock
)
func (n NATType) String() string {
switch n {
case NATUnknown:
return "Unknown"
case NATFullCone:
return "FullCone"
case NATRestricted:
return "Restricted"
case NATPortRestricted:
return "PortRestricted"
case NATSymmetric:
return "Symmetric"
case NATOpenInternet:
return "OpenInternet"
case NATUDPBlock:
return "UDPBlock"
default:
return ""
}
}
// Token access download asset
type Token struct {
ID string
// CipherText encrypted TokenPayload by public key
CipherText string
// Sign signs CipherText by scheduler private key
Sign string
}
type EdgeDownloadInfo struct {
Address string
Tk *Token
NodeID string
NatType string
}
type EdgeDownloadInfoList struct {
Infos []*EdgeDownloadInfo
SchedulerURL string
SchedulerKey string
}
type Edge struct {
Address string
Token *Token
NodeID string
NATType string
SchedulerURL string
SchedulerKey string
}
func (e Edge) GetNATType() NATType {
switch e.NATType {
case "NoNAT":
return NATOpenInternet
case "SymmetricNAT":
return NATSymmetric
case "FullConeNAT":
return NATFullCone
case "RestrictedNAT":
return NATRestricted
case "PortRestrictedNAT":
return NATPortRestricted
default:
return NATUnknown
}
}
type Client struct {
Node *Edge
Weight int
HttpClient *http.Client
}
type NatPunchReq struct {
Tk *Token
NodeID string
Timeout time.Duration
}
func (e Edge) ToNatPunchReq() *NatPunchReq {
return &NatPunchReq{
Tk: e.Token,
NodeID: e.NodeID,
Timeout: 30 * time.Second,
}
}
type AccessPoint struct {
AreaID string
SchedulerURLs []string
}
type Host struct {
IP string
Port string
}
func (h Host) String() string {
return fmt.Sprintf("%s:%s", h.IP, h.Port)
}
type FileRange struct {
Start int64
End int64
}
type Workload struct {
DownloadSpeed int64 // bytes/ms
DownloadSize int64
StartTime int64
EndTime int64
}
type WorkloadReport struct {
TokenID string
ClientID string
NodeID string
Workload *Workload
Extra *Extra `json:"-"`
}
type ProofParam struct {
Proofs *WorkloadReport
SchedulerKey string
SchedulerURL string
}
type Extra struct {
Cost int64 //ms
Count int64
Address string
}