gateway.go 6.32 KB
Newer Older
1 2 3
package modules

import (
4
	"net"
5 6

	"github.com/NebulousLabs/Sia/build"
7 8
)

9
const (
10 11
	// GatewayDir is the name of the directory used to store the gateway's
	// persistent data.
12 13 14 15
	GatewayDir = "gateway"
)

var (
16 17 18 19 20 21
	// BootstrapPeers is a list of peers that can be used to find other peers -
	// when a client first connects to the network, the only options for
	// finding peers are either manual entry of peers or to use a hardcoded
	// bootstrap point. While the bootstrap point could be a central service,
	// it can also be a list of peers that are known to be stable. We have
	// chosen to hardcode known-stable peers.
22 23
	BootstrapPeers = build.Select(build.Var{
		Standard: []NetAddress{
Christopher Schinnerl's avatar
Christopher Schinnerl committed
24 25 26
			"23.175.0.151:9981",
			"51.15.48.114:9981",
			"137.74.1.200:9981",
27 28
			"23.239.14.98:9971",
			"23.239.14.98:9981",
Christopher Schinnerl's avatar
Christopher Schinnerl committed
29 30 31 32 33 34 35
			"162.211.163.190:9981",
			"67.254.219.180:9981",
			"108.28.206.98:9981",
			"162.211.163.189:9981",
			"192.254.68.245:9981",
			"69.125.184.202:9981",
			"66.49.218.20:9981",
Christopher Schinnerl's avatar
Christopher Schinnerl committed
36 37
			"66.49.218.102:9981",
			"72.229.14.109:9981",
Christopher Schinnerl's avatar
Christopher Schinnerl committed
38
			"209.182.216.47:9981",
Christopher Schinnerl's avatar
Christopher Schinnerl committed
39
			"65.30.45.202:9981",
Christopher Schinnerl's avatar
Christopher Schinnerl committed
40 41 42 43 44 45
			"174.58.166.159:9981",
			"147.135.132.95:9981",
			"88.202.202.221:9981",
			"51.15.41.218:9981",
			"147.135.133.105:9981",
			"147.135.133.100:9981",
Christopher Schinnerl's avatar
Christopher Schinnerl committed
46
			"94.23.7.123:9981",
Christopher Schinnerl's avatar
Christopher Schinnerl committed
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
			"24.125.195.213:9981",
			"107.181.137.139:9981",
			"67.207.162.194:9981",
			"147.135.132.94:9981",
			"94.23.54.36:9981",
			"147.135.133.114:9981",
			"72.24.114.182:9981",
			"85.27.163.135:9981",
			"77.132.24.85:9981",
			"62.210.140.24:9981",
			"217.160.178.117:9981",
			"80.239.147.28:9981",
			"94.137.140.40:9981",
			"193.248.47.218:9981",
			"85.214.229.44:9981",
			"138.68.84.69:9981",
			"93.103.248.239:9981",
			"76.28.239.179:9981",
			"76.174.155.33:9984",
			"94.225.83.165:9981",
			"78.41.116.91:9981",
			"51.175.10.196:9981",
			"188.242.52.10:9988",
			"188.242.52.10:9986",
			"5.20.184.133:9981",
			"81.167.50.168:9981",
			"83.142.60.64:9981",
			"85.21.232.162:9981",
			"188.244.40.69:9985",
			"188.244.40.69:9981",
			"95.78.166.67:9981",
			"109.194.162.16:9981",
			"78.248.218.28:9981",
			"217.173.23.149:9981",
			"91.231.94.22:9981",
			"27.120.81.167:9981",
			"162.211.163.188:9981",
			"122.214.1.30:9981",
			"94.201.207.205:9981",
			"71.65.230.65:9332",
			"109.248.206.13:9981",
			"114.55.95.111:9981",
			"47.94.45.200:9981",
			"121.254.64.110:9981",
			"45.56.21.129:9981",
			"188.242.52.10:9981",
			"116.62.118.38:30308",
			"174.138.20.196:9981",
Christopher Schinnerl's avatar
Christopher Schinnerl committed
95
			"71.199.19.26:9981",
Christopher Schinnerl's avatar
Christopher Schinnerl committed
96 97 98 99 100 101 102 103
			"78.46.64.86:9981",
			"115.70.170.117:9981",
			"203.87.65.150:9981",
			"75.82.191.146:19981",
			"163.172.215.185:9981",
			"108.162.149.228:9981",
			"69.172.174.21:9981",
			"91.206.15.126:9981",
Christopher Schinnerl's avatar
Christopher Schinnerl committed
104
			"13.93.44.96:9981",
Christopher Schinnerl's avatar
Christopher Schinnerl committed
105 106 107 108 109 110 111 112 113 114 115 116
			"188.244.40.69:9997",
			"92.70.88.30:9981",
			"109.173.126.111:9981",
			"5.9.139.30:9981",
			"213.239.221.175:9981",
			"66.49.218.179:9981",
			"163.172.209.161:9981",
			"101.200.202.108:9981",
			"24.6.98.156:9981",
			"162.211.163.187:9981",
			"176.9.51.183:9981",
			"87.249.251.18:9981",
Christopher Schinnerl's avatar
Christopher Schinnerl committed
117
			"74.107.124.167:9981",
Christopher Schinnerl's avatar
Christopher Schinnerl committed
118 119 120 121 122 123 124
			"163.172.18.134:9981",
			"176.9.144.99:9981",
			"45.22.40.217:9981",
			"62.210.93.142:9981",
			"80.108.192.203:9981",
			"5.57.198.66:9981",
			"147.135.133.117:9981",
125 126 127 128
		},
		Dev:     []NetAddress(nil),
		Testing: []NetAddress(nil),
	}).([]NetAddress)
129 130
)

Jordan Horwich's avatar
Jordan Horwich committed
131
type (
Jordan Horwich's avatar
Jordan Horwich committed
132 133
	// Peer contains all the info necessary to Broadcast to a peer.
	Peer struct {
134 135
		Inbound    bool       `json:"inbound"`
		Local      bool       `json:"local"`
Jordan Horwich's avatar
Jordan Horwich committed
136 137 138 139
		NetAddress NetAddress `json:"netaddress"`
		Version    string     `json:"version"`
	}

Jordan Horwich's avatar
Jordan Horwich committed
140
	// A PeerConn is the connection type used when communicating with peers during
141 142 143 144
	// an RPC. It is identical to a net.Conn with the additional RPCAddr method.
	// This method acts as an identifier for peers and is the address that the
	// peer can be dialed on. It is also the address that should be used when
	// calling an RPC on the peer.
Jordan Horwich's avatar
Jordan Horwich committed
145 146
	PeerConn interface {
		net.Conn
147
		RPCAddr() NetAddress
Jordan Horwich's avatar
Jordan Horwich committed
148
	}
149

Jordan Horwich's avatar
Jordan Horwich committed
150 151 152 153 154
	// RPCFunc is the type signature of functions that handle RPCs. It is used for
	// both the caller and the callee. RPCFuncs may perform locking. RPCFuncs may
	// close the connection early, and it is recommended that they do so to avoid
	// keeping the connection open after all necessary I/O has been performed.
	RPCFunc func(PeerConn) error
Luke Champine's avatar
Luke Champine committed
155

Jordan Horwich's avatar
Jordan Horwich committed
156 157 158 159 160 161 162 163
	// A Gateway facilitates the interactions between the local node and remote
	// nodes (peers). It relays incoming blocks and transactions to local modules,
	// and broadcasts outgoing blocks and transactions to peers. In a broad sense,
	// it is responsible for ensuring that the local consensus set is consistent
	// with the "network" consensus set.
	Gateway interface {
		// Connect establishes a persistent connection to a peer.
		Connect(NetAddress) error
164

Jordan Horwich's avatar
Jordan Horwich committed
165 166
		// Disconnect terminates a connection to a peer.
		Disconnect(NetAddress) error
167

Jordan Horwich's avatar
Jordan Horwich committed
168 169
		// Address returns the Gateway's address.
		Address() NetAddress
Luke Champine's avatar
Luke Champine committed
170

Jordan Horwich's avatar
Jordan Horwich committed
171
		// Peers returns the addresses that the Gateway is currently connected to.
Jordan Horwich's avatar
Jordan Horwich committed
172
		Peers() []Peer
173

Jordan Horwich's avatar
Jordan Horwich committed
174 175 176
		// RegisterRPC registers a function to handle incoming connections that
		// supply the given RPC ID.
		RegisterRPC(string, RPCFunc)
177

178 179 180 181 182 183
		// UnregisterRPC unregisters an RPC and removes all references to the RPCFunc
		// supplied in the corresponding RegisterRPC call. References to RPCFuncs
		// registered with RegisterConnectCall are not removed and should be removed
		// with UnregisterConnectCall. If the RPC does not exist no action is taken.
		UnregisterRPC(string)

Jordan Horwich's avatar
Jordan Horwich committed
184 185 186
		// RegisterConnectCall registers an RPC name and function to be called
		// upon connecting to a peer.
		RegisterConnectCall(string, RPCFunc)
Luke Champine's avatar
Luke Champine committed
187

188 189 190 191 192 193
		// UnregisterConnectCall unregisters an RPC and removes all references to the
		// RPCFunc supplied in the corresponding RegisterConnectCall call. References
		// to RPCFuncs registered with RegisterRPC are not removed and should be
		// removed with UnregisterRPC. If the RPC does not exist no action is taken.
		UnregisterConnectCall(string)

Jordan Horwich's avatar
Jordan Horwich committed
194 195 196
		// RPC calls an RPC on the given address. RPC cannot be called on an
		// address that the Gateway is not connected to.
		RPC(NetAddress, string, RPCFunc) error
197

Jordan Horwich's avatar
Jordan Horwich committed
198
		// Broadcast transmits obj, prefaced by the RPC name, to all of the
199 200
		// given peers in parallel.
		Broadcast(name string, obj interface{}, peers []Peer)
Luke Champine's avatar
Luke Champine committed
201

202 203 204
		// Online returns true if the gateway is connected to remote hosts
		Online() bool

Jordan Horwich's avatar
Jordan Horwich committed
205 206 207 208
		// Close safely stops the Gateway's listener process.
		Close() error
	}
)