|
@ -141,8 +141,7 @@ func NewNode() *Node { |
|
|
func (n *Node) Start() { |
|
|
func (n *Node) Start() { |
|
|
log.Info("Starting Node") |
|
|
log.Info("Starting Node") |
|
|
n.book.Start() |
|
|
n.book.Start() |
|
|
nodeInfo := makeNodeInfo(n.sw) |
|
|
|
|
|
n.sw.SetNodeInfo(nodeInfo) |
|
|
|
|
|
|
|
|
n.sw.SetNodeInfo(makeNodeInfo(n.sw)) |
|
|
n.sw.Start() |
|
|
n.sw.Start() |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
@ -169,7 +168,8 @@ func (n *Node) AddListener(l p2p.Listener) { |
|
|
n.book.AddOurAddress(l.ExternalAddress()) |
|
|
n.book.AddOurAddress(l.ExternalAddress()) |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
// NOTE: Blocking
|
|
|
|
|
|
|
|
|
// Dial a list of seeds in random order
|
|
|
|
|
|
// Spawns a go routine for each dial
|
|
|
func (n *Node) DialSeed() { |
|
|
func (n *Node) DialSeed() { |
|
|
// permute the list, dial them in random order.
|
|
|
// permute the list, dial them in random order.
|
|
|
seeds := strings.Split(config.GetString("seeds"), ",") |
|
|
seeds := strings.Split(config.GetString("seeds"), ",") |
|
@ -196,7 +196,7 @@ func (n *Node) dialSeed(addr *p2p.NetAddress) { |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
func (n *Node) StartRPC() { |
|
|
|
|
|
|
|
|
func (n *Node) StartRPC() net.Listener { |
|
|
core.SetBlockStore(n.blockStore) |
|
|
core.SetBlockStore(n.blockStore) |
|
|
core.SetConsensusState(n.consensusState) |
|
|
core.SetConsensusState(n.consensusState) |
|
|
core.SetConsensusReactor(n.consensusReactor) |
|
|
core.SetConsensusReactor(n.consensusReactor) |
|
@ -209,7 +209,11 @@ func (n *Node) StartRPC() { |
|
|
mux := http.NewServeMux() |
|
|
mux := http.NewServeMux() |
|
|
rpcserver.RegisterEventsHandler(mux, n.evsw) |
|
|
rpcserver.RegisterEventsHandler(mux, n.evsw) |
|
|
rpcserver.RegisterRPCFuncs(mux, core.Routes) |
|
|
rpcserver.RegisterRPCFuncs(mux, core.Routes) |
|
|
rpcserver.StartHTTPServer(listenAddr, mux) |
|
|
|
|
|
|
|
|
listener, err := rpcserver.StartHTTPServer(listenAddr, mux) |
|
|
|
|
|
if err != nil { |
|
|
|
|
|
panic(err) |
|
|
|
|
|
} |
|
|
|
|
|
return listener |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
func (n *Node) Switch() *p2p.Switch { |
|
|
func (n *Node) Switch() *p2p.Switch { |
|
@ -252,7 +256,8 @@ func makeNodeInfo(sw *p2p.Switch) *types.NodeInfo { |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
// We assume that the rpcListener has the same ExternalAddress.
|
|
|
// We assume that the rpcListener has the same ExternalAddress.
|
|
|
// This is probably true because both P2P and RPC listeners use UPnP.
|
|
|
|
|
|
|
|
|
// This is probably true because both P2P and RPC listeners use UPnP,
|
|
|
|
|
|
// except of course if the rpc is only bound to localhost
|
|
|
nodeInfo.Host = p2pHost |
|
|
nodeInfo.Host = p2pHost |
|
|
nodeInfo.P2PPort = p2pPort |
|
|
nodeInfo.P2PPort = p2pPort |
|
|
nodeInfo.RPCPort = uint16(rpcPort) |
|
|
nodeInfo.RPCPort = uint16(rpcPort) |
|
@ -269,7 +274,7 @@ func RunNode() { |
|
|
n.Start() |
|
|
n.Start() |
|
|
|
|
|
|
|
|
// If seedNode is provided by config, dial out.
|
|
|
// If seedNode is provided by config, dial out.
|
|
|
if len(config.GetString("seeds")) > 0 { |
|
|
|
|
|
|
|
|
if config.GetString("seeds") != "" { |
|
|
n.DialSeed() |
|
|
n.DialSeed() |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|