-
Notifications
You must be signed in to change notification settings - Fork 7
/
params.go
138 lines (104 loc) · 4.17 KB
/
params.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
package cfg
import (
"github.com/multiformats/go-multiaddr"
"os"
"github.com/indra-labs/indra/pkg/node"
log2 "github.com/indra-labs/indra/pkg/proc/log"
)
var (
log = log2.GetLogger()
check = log.E.Chk
)
const (
// MainNet is the identifier string for the main production network.
MainNet = "mainnet"
// TestNet is the identifier string for the test network.
TestNet = "testnet"
// SimNet is the identifier string for simulation networks.
SimNet = "simnet"
)
// Params is the specification for an indranet swarm (mainnet, testnet, etc).
type Params struct {
// Name defines a human-readable identifier for the network
Name string
// Net is a uint32 magic byte identifier for the network
Net node.Swarm
// DefaultPort is the default port for p2p listening
DefaultPort string
// DNSSeedAddresses is a list of DNS hostnames used to bootstrap a new node on the network
DNSSeedAddresses []*SeedAddress
}
// SelectNetworkParams returns the network parameters associated with the network name.
func SelectNetworkParams(network string) *Params {
if nw, ok := params[network]; ok {
return nw
}
panic("invalid network, exiting...")
os.Exit(1)
return nil
}
// ParseSeedMultiAddresses returns the addresses of the seeds as a slice of multiaddr.Multiaddr.
func (p *Params) ParseSeedMultiAddresses() (addresses []multiaddr.Multiaddr, err error) {
var adr multiaddr.Multiaddr
addresses = []multiaddr.Multiaddr{}
for _, addr := range p.DNSSeedAddresses {
if adr, err = multiaddr.NewMultiaddr("/dns4/" + addr.DNSAddress + "/tcp/" + p.DefaultPort + "/p2p/" + addr.ID); check(err) {
return
}
addresses = append(addresses, adr)
}
return
}
// GetSeedsMultiAddrStrings returns the seeds multiaddrs as encoded strings.
func (p *Params) GetSeedsMultiAddrStrings() (seeds []string) {
for _, addr := range p.DNSSeedAddresses {
seeds = append(seeds, "/dns4/"+addr.DNSAddress+"/tcp/"+
p.DefaultPort+"/p2p/"+addr.ID)
}
return
}
var (
params = map[string]*Params{
MainNet: {
Name: "mainnet",
Net: node.MainNet,
DefaultPort: "8337",
DNSSeedAddresses: []*SeedAddress{
NewSeedAddress("seed0.indra.org", "12D3KooWCfTmWavthiVV7Vkm9eouCdiLdGnhd2PShQ2hiu2VVU6Q"),
NewSeedAddress("seed1.indra.org", "12D3KooWASwYWP2gMh581EQG25nauvWfwAU3g6v8TugEoEzL5Ags"),
NewSeedAddress("seed2.indra.org", "12D3KooWFW7k2YcxjZrqWXJhmoCTNiNtgjLkEUeqgvZRAF3xHZjs"),
NewSeedAddress("seed3.indra.org", "12D3KooWPxx3WMiCv3SwBNfrM6peGBWDypJqqxfdGgZKpr7BF9Vo"),
// NewSeedAddress("seed0.example.com", "12D3KooWDj2wXRVPRVP8HcQXTyAXeigAAjaX6hgdgALyNFuK1Htv"),
// NewSeedAddress("seed1.example.com", "12D3KooWMkBp6E2qjz2saq9eocT9FTh3zuoP5yAcFgFGSfXoZN8K"),
// NewSeedAddress("seed2.example.com", "12D3KooWEonhWcCp6FMwycNFrE5hSDbPdezy5ftBcHLxLPoESzgZ"),
// NewSeedAddress("seed3.example.com", "12D3KooWFq8irCNNCdE4zxjcUGVdG47fnPSd4hj9MsxH8RAunHTx"),
},
},
TestNet: {
Name: "testnet",
Net: node.TestNet,
DefaultPort: "58337",
DNSSeedAddresses: []*SeedAddress{
// NewSeedAddress("seed0.indra.org", "12D3KooWCfTmWavthiVV7Vkm9eouCdiLdGnhd2PShQ2hiu2VVU6Q"),
// NewSeedAddress("seed1.indra.org", "12D3KooWASwYWP2gMh581EQG25nauvWfwAU3g6v8TugEoEzL5Ags"),
// NewSeedAddress("seed2.indra.org", "12D3KooWFW7k2YcxjZrqWXJhmoCTNiNtgjLkEUeqgvZRAF3xHZjs"),
// NewSeedAddress("seed3.indra.org", "12D3KooWPxx3WMiCv3SwBNfrM6peGBWDypJqqxfdGgZKpr7BF9Vo"),
// NewSeedAddress("seed0.example.com", "12D3KooWDj2wXRVPRVP8HcQXTyAXeigAAjaX6hgdgALyNFuK1Htv"),
// NewSeedAddress("seed1.example.com", "12D3KooWMkBp6E2qjz2saq9eocT9FTh3zuoP5yAcFgFGSfXoZN8K"),
// NewSeedAddress("seed2.example.com", "12D3KooWEonhWcCp6FMwycNFrE5hSDbPdezy5ftBcHLxLPoESzgZ"),
// NewSeedAddress("seed3.example.com", "12D3KooWFq8irCNNCdE4zxjcUGVdG47fnPSd4hj9MsxH8RAunHTx"),
},
},
SimNet: {
Name: "simnet",
Net: node.SimNet,
DefaultPort: "62134",
// Should be passed via --seed
DNSSeedAddresses: []*SeedAddress{
NewSeedAddress("seed0", "16Uiu2HAmHL9cwDdGdGEQk7K5xTBH3rUKoRWS3tWgjej9WmjMG6L9"),
NewSeedAddress("seed1", "16Uiu2HAm3ZVpmNPnk67eCKsR3HCMSLhbw3THcBDpyKwCE5GNgHVN"),
NewSeedAddress("seed2", "16Uiu2HAmTP7o9yyuFz8f5sRGr7KTamuMo6UguuTqPMaJavdGX7Ju"),
},
},
}
)