diff --git a/internal/rpc/core/env.go b/internal/rpc/core/env.go index 5a718b232..8f590298b 100644 --- a/internal/rpc/core/env.go +++ b/internal/rpc/core/env.go @@ -57,12 +57,6 @@ type consensusState interface { GetRoundStateSimpleJSON() ([]byte, error) } -type transport interface { - Listeners() []string - IsListening() bool - NodeInfo() types.NodeInfo -} - type peerManager interface { Peers() []types.NodeID Addresses(types.NodeID) []p2p.NodeAddress @@ -84,8 +78,9 @@ type Environment struct { ConsensusReactor *consensus.Reactor BlockSyncReactor *blocksync.Reactor - // Legacy p2p stack - P2PTransport transport + IsListening bool + Listeners []string + NodeInfo types.NodeInfo // interfaces for new p2p interfaces PeerManager peerManager @@ -226,6 +221,10 @@ func (env *Environment) StartService(ctx context.Context, conf *config.Config) ( return nil, err } + env.Listeners = []string{ + fmt.Sprintf("Listener(@%v)", conf.P2P.ExternalAddress), + } + listenAddrs := strings.SplitAndTrimEmpty(conf.RPC.ListenAddress, ",", " ") routes := NewRoutesMap(env, &RouteOptions{ Unsafe: conf.RPC.Unsafe, diff --git a/internal/rpc/core/net.go b/internal/rpc/core/net.go index 3cead393c..5444b77b7 100644 --- a/internal/rpc/core/net.go +++ b/internal/rpc/core/net.go @@ -27,8 +27,8 @@ func (env *Environment) NetInfo(ctx context.Context) (*coretypes.ResultNetInfo, } return &coretypes.ResultNetInfo{ - Listening: env.P2PTransport.IsListening(), - Listeners: env.P2PTransport.Listeners(), + Listening: env.IsListening, + Listeners: env.Listeners, NPeers: len(peers), Peers: peers, }, nil diff --git a/internal/rpc/core/status.go b/internal/rpc/core/status.go index 2f648978a..46b8a6fcd 100644 --- a/internal/rpc/core/status.go +++ b/internal/rpc/core/status.go @@ -66,7 +66,7 @@ func (env *Environment) Status(ctx context.Context) (*coretypes.ResultStatus, er } result := &coretypes.ResultStatus{ - NodeInfo: env.P2PTransport.NodeInfo(), + NodeInfo: env.NodeInfo, ApplicationInfo: applicationInfo, SyncInfo: coretypes.SyncInfo{ LatestBlockHash: latestBlockHash, diff --git a/node/node.go b/node/node.go index 7d7b75170..8970a29d7 100644 --- a/node/node.go +++ b/node/node.go @@ -58,7 +58,6 @@ type nodeImpl struct { router *p2p.Router nodeInfo types.NodeInfo nodeKey types.NodeKey // our node privkey - isListening bool // services eventSinks []indexer.EventSink @@ -421,8 +420,6 @@ func makeNode( node.rpcEnv.PubKey = pubKey } - node.rpcEnv.P2PTransport = node - node.BaseService = *service.NewBaseService(logger, "Node", node) return node, nil @@ -467,6 +464,7 @@ func (n *nodeImpl) OnStart(ctx context.Context) error { } } + n.rpcEnv.NodeInfo = n.nodeInfo // Start the RPC server before the P2P server // so we can eg. receive txs for the first block if n.config.RPC.ListenAddress != "" { @@ -485,7 +483,7 @@ func (n *nodeImpl) OnStart(ctx context.Context) error { if err := n.router.Start(ctx); err != nil { return err } - n.isListening = true + n.rpcEnv.IsListening = true for _, reactor := range n.services { if err := reactor.Start(ctx); err != nil { @@ -580,7 +578,7 @@ func (n *nodeImpl) OnStop() { n.stateSyncReactor.Wait() n.router.Wait() - n.isListening = false + n.rpcEnv.IsListening = false // finally stop the listeners / external services for _, l := range n.rpcListeners { @@ -669,21 +667,6 @@ func (n *nodeImpl) RPCEnvironment() *rpccore.Environment { //------------------------------------------------------------------------------ -func (n *nodeImpl) Listeners() []string { - return []string{ - fmt.Sprintf("Listener(@%v)", n.config.P2P.ExternalAddress), - } -} - -func (n *nodeImpl) IsListening() bool { - return n.isListening -} - -// NodeInfo returns the Node's Info from the Switch. -func (n *nodeImpl) NodeInfo() types.NodeInfo { - return n.nodeInfo -} - // genesisDocProvider returns a GenesisDoc. // It allows the GenesisDoc to be pulled from sources other than the // filesystem, for instance from a distributed key-value store cluster.