This repository has been archived by the owner on Nov 22, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
/
regions.go
128 lines (118 loc) · 3.24 KB
/
regions.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
package exchange
import (
"math"
"path"
)
// Regions: This is very experimental and needs more iterations to be stable
// currently we only offer 2 bootstrap nodes for Europe and NorthAmerica more will follow
// RegionCode defines a subnetwork code
type RegionCode uint64
const (
// GlobalRegion region is a free global network for anyone to try the network
GlobalRegion RegionCode = iota
// AsiaRegion is a specific region to connect caches in the Asian area
AsiaRegion
// AfricaRegion is a specific region in the African geographic area
AfricaRegion
// SouthAmericaRegion is a specific region
SouthAmericaRegion
// NorthAmericaRegion is a specific region to connect caches in the North American area
NorthAmericaRegion
// EuropeRegion is a specific region to connect caches in the European area
EuropeRegion
// OceaniaRegion is a specific region
OceaniaRegion
// CustomRegion is a user defined region
CustomRegion = math.MaxUint64
)
// Region represents a CDN subnetwork.
type Region struct {
// The official region name should be unique to avoid clashing with other regions.
Name string
// Code is a compressed identifier for the region.
Code RegionCode
// Bootstrap is a list of peers that can be dialed to find other peers in that region
Bootstrap []string
}
var (
asia = Region{
Name: "Asia",
Code: AsiaRegion,
Bootstrap: []string{},
}
africa = Region{
Name: "Africa",
Code: AfricaRegion,
Bootstrap: []string{},
}
southAmerica = Region{
Name: "SouthAmerica",
Code: SouthAmericaRegion,
Bootstrap: []string{},
}
northAmerica = Region{
Name: "NorthAmerica",
Code: NorthAmericaRegion,
Bootstrap: []string{
"/dns4/ohio.myel.zone/tcp/41504/p2p/12D3KooWStJfAywQmfaVFQDQYr9riDnEFG3VJ3qDGcTidvc4nQtc",
},
}
europe = Region{
Name: "Europe",
Code: EuropeRegion,
Bootstrap: []string{
"/dns4/frankfurt.myel.zone/tcp/41504/p2p/12D3KooWLaJQ7L6Q3VWxNNxqE8Tcj2wAq1QAvdBieSteAxg9KTCr",
},
}
oceania = Region{
Name: "Oceania",
Code: OceaniaRegion,
Bootstrap: []string{},
}
global = Region{
Name: "Global",
Code: GlobalRegion,
Bootstrap: []string{
"/dns4/frankfurt.myel.zone/tcp/41504/p2p/12D3KooWLaJQ7L6Q3VWxNNxqE8Tcj2wAq1QAvdBieSteAxg9KTCr",
"/dns4/ohio.myel.zone/tcp/41504/p2p/12D3KooWStJfAywQmfaVFQDQYr9riDnEFG3VJ3qDGcTidvc4nQtc",
},
}
)
// Regions is a list of preset regions
var Regions = map[string]Region{
"Global": global,
"Asia": asia,
"Africa": africa,
"SouthAmerica": southAmerica,
"NorthAmerica": northAmerica,
"Europe": europe,
"Oceania": oceania,
}
// ParseRegions converts region names to region structs
func ParseRegions(list []string) []Region {
var regions []Region
for _, rstring := range list {
if r := Regions[rstring]; r.Name != "" {
regions = append(regions, r)
continue
}
// We also support custom regions if users want their own provider subnet
regions = append(regions, Region{
Name: rstring,
Code: CustomRegion,
})
}
return regions
}
// RegionFromTopic formats a topic string into a Region struct
func RegionFromTopic(topic string) Region {
_, name := path.Split(topic)
r, ok := Regions[name]
if !ok {
return Region{
Name: name,
Code: CustomRegion,
}
}
return r
}