cleanup, comments

This commit is contained in:
Ethan Buchman
2015-07-10 15:39:49 +00:00
parent 24acda1afc
commit 751b892cba
6 changed files with 26 additions and 21 deletions

View File

@ -141,8 +141,7 @@ func NewNode() *Node {
func (n *Node) Start() {
log.Info("Starting Node")
n.book.Start()
nodeInfo := makeNodeInfo(n.sw)
n.sw.SetNodeInfo(nodeInfo)
n.sw.SetNodeInfo(makeNodeInfo(n.sw))
n.sw.Start()
}
@ -169,7 +168,8 @@ func (n *Node) AddListener(l p2p.Listener) {
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() {
// permute the list, dial them in random order.
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.SetConsensusState(n.consensusState)
core.SetConsensusReactor(n.consensusReactor)
@ -209,7 +209,11 @@ func (n *Node) StartRPC() {
mux := http.NewServeMux()
rpcserver.RegisterEventsHandler(mux, n.evsw)
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 {
@ -252,7 +256,8 @@ func makeNodeInfo(sw *p2p.Switch) *types.NodeInfo {
}
// 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.P2PPort = p2pPort
nodeInfo.RPCPort = uint16(rpcPort)
@ -269,7 +274,7 @@ func RunNode() {
n.Start()
// If seedNode is provided by config, dial out.
if len(config.GetString("seeds")) > 0 {
if config.GetString("seeds") != "" {
n.DialSeed()
}