@ -319,12 +319,12 @@ func makeNode(config *cfg.Config,
stateSyncReactorShim = p2p . NewReactorShim ( logger . With ( "module" , "statesync" ) , "StateSyncShim" , statesync . ChannelShims )
stateSyncReactorShim = p2p . NewReactorShim ( logger . With ( "module" , "statesync" ) , "StateSyncShim" , statesync . ChannelShims )
if config . P2P . DisableLegacy {
channels = makeChannelsFromShims ( router , statesync . ChannelShims )
peerUpdates = peerManager . Subscribe ( )
} else {
if config . P2P . UseLegacy {
channels = getChannelsFromShim ( stateSyncReactorShim )
channels = getChannelsFromShim ( stateSyncReactorShim )
peerUpdates = stateSyncReactorShim . PeerUpdates
peerUpdates = stateSyncReactorShim . PeerUpdates
} else {
channels = makeChannelsFromShims ( router , statesync . ChannelShims )
peerUpdates = peerManager . Subscribe ( )
}
}
stateSyncReactor = statesync . NewReactor (
stateSyncReactor = statesync . NewReactor (
@ -373,13 +373,7 @@ func makeNode(config *cfg.Config,
pexCh := pex . ChannelDescriptor ( )
pexCh := pex . ChannelDescriptor ( )
transport . AddChannelDescriptors ( [ ] * p2p . ChannelDescriptor { & pexCh } )
transport . AddChannelDescriptors ( [ ] * p2p . ChannelDescriptor { & pexCh } )
if config . P2P . DisableLegacy {
addrBook = nil
pexReactor , err = createPEXReactorV2 ( config , logger , peerManager , router )
if err != nil {
return nil , err
}
} else {
if config . P2P . UseLegacy {
// setup Transport and Switch
// setup Transport and Switch
sw = createSwitch (
sw = createSwitch (
config , transport , p2pMetrics , mpReactorShim , bcReactorForSwitch ,
config , transport , p2pMetrics , mpReactorShim , bcReactorForSwitch ,
@ -402,6 +396,12 @@ func makeNode(config *cfg.Config,
}
}
pexReactor = createPEXReactorAndAddToSwitch ( addrBook , config , sw , logger )
pexReactor = createPEXReactorAndAddToSwitch ( addrBook , config , sw , logger )
} else {
addrBook = nil
pexReactor , err = createPEXReactorV2 ( config , logger , peerManager , router )
if err != nil {
return nil , err
}
}
}
if config . RPC . PprofListenAddress != "" {
if config . RPC . PprofListenAddress != "" {
@ -461,6 +461,17 @@ func makeNode(config *cfg.Config,
} ,
} ,
}
}
// this is a terrible, because typed nil interfaces are not ==
// nil, so this is just cleanup to avoid having a non-nil
// value in the RPC environment that has the semantic
// properties of nil.
if sw == nil {
node . rpcEnv . P2PPeers = nil
} else if peerManager == nil {
node . rpcEnv . PeerManager = nil
}
// end hack
node . rpcEnv . P2PTransport = node
node . rpcEnv . P2PTransport = node
node . BaseService = * service . NewBaseService ( logger , "Node" , node )
node . BaseService = * service . NewBaseService ( logger , "Node" , node )
@ -519,12 +530,8 @@ func makeSeedNode(config *cfg.Config,
// p2p stack is removed.
// p2p stack is removed.
pexCh := pex . ChannelDescriptor ( )
pexCh := pex . ChannelDescriptor ( )
transport . AddChannelDescriptors ( [ ] * p2p . ChannelDescriptor { & pexCh } )
transport . AddChannelDescriptors ( [ ] * p2p . ChannelDescriptor { & pexCh } )
if config . P2P . DisableLegacy {
pexReactor , err = createPEXReactorV2 ( config , logger , peerManager , router )
if err != nil {
return nil , err
}
} else {
if config . P2P . UseLegacy {
sw = createSwitch (
sw = createSwitch (
config , transport , p2pMetrics , nil , nil ,
config , transport , p2pMetrics , nil , nil ,
nil , nil , nil , nil , nodeInfo , nodeKey , p2pLogger ,
nil , nil , nil , nil , nodeInfo , nodeKey , p2pLogger ,
@ -546,6 +553,11 @@ func makeSeedNode(config *cfg.Config,
}
}
pexReactor = createPEXReactorAndAddToSwitch ( addrBook , config , sw , logger )
pexReactor = createPEXReactorAndAddToSwitch ( addrBook , config , sw , logger )
} else {
pexReactor , err = createPEXReactorV2 ( config , logger , peerManager , router )
if err != nil {
return nil , err
}
}
}
if config . RPC . PprofListenAddress != "" {
if config . RPC . PprofListenAddress != "" {
@ -608,18 +620,16 @@ func (n *nodeImpl) OnStart() error {
}
}
n . isListening = true
n . isListening = true
n . Logger . Info ( "p2p service" , "legacy_enabled" , ! n . config . P2P . Disabl eLegacy)
n . Logger . Info ( "p2p service" , "legacy_enabled" , n . config . P2P . Us eLegacy)
if n . config . P2P . DisableLegacy {
if err = n . router . Start ( ) ; err != nil {
return err
}
} else {
if n . config . P2P . UseLegacy {
// Add private IDs to addrbook to block those peers being added
// Add private IDs to addrbook to block those peers being added
n . addrBook . AddPrivateIDs ( strings . SplitAndTrimEmpty ( n . config . P2P . PrivatePeerIDs , "," , " " ) )
n . addrBook . AddPrivateIDs ( strings . SplitAndTrimEmpty ( n . config . P2P . PrivatePeerIDs , "," , " " ) )
if err = n . sw . Start ( ) ; err != nil {
if err = n . sw . Start ( ) ; err != nil {
return err
return err
}
}
} else if err = n . router . Start ( ) ; err != nil {
return err
}
}
if n . config . Mode != cfg . ModeSeed {
if n . config . Mode != cfg . ModeSeed {
@ -650,16 +660,14 @@ func (n *nodeImpl) OnStart() error {
}
}
}
}
if n . config . P2P . DisableLegacy {
if err := n . pexReactor . Start ( ) ; err != nil {
return err
}
} else {
if n . config . P2P . UseLegacy {
// Always connect to persistent peers
// Always connect to persistent peers
err = n . sw . DialPeersAsync ( strings . SplitAndTrimEmpty ( n . config . P2P . PersistentPeers , "," , " " ) )
err = n . sw . DialPeersAsync ( strings . SplitAndTrimEmpty ( n . config . P2P . PersistentPeers , "," , " " ) )
if err != nil {
if err != nil {
return fmt . Errorf ( "could not dial peers from persistent-peers field: %w" , err )
return fmt . Errorf ( "could not dial peers from persistent-peers field: %w" , err )
}
}
} else if err := n . pexReactor . Start ( ) ; err != nil {
return err
}
}
// Run state sync
// Run state sync
@ -738,14 +746,14 @@ func (n *nodeImpl) OnStop() {
n . Logger . Error ( "failed to stop the PEX v2 reactor" , "err" , err )
n . Logger . Error ( "failed to stop the PEX v2 reactor" , "err" , err )
}
}
if n . config . P2P . DisableLegacy {
if err := n . router . Stop ( ) ; err != nil {
n . Logger . Error ( "failed to stop router" , "err" , err )
}
} else {
if n . config . P2P . UseLegacy {
if err := n . sw . Stop ( ) ; err != nil {
if err := n . sw . Stop ( ) ; err != nil {
n . Logger . Error ( "failed to stop switch" , "err" , err )
n . Logger . Error ( "failed to stop switch" , "err" , err )
}
}
} else {
if err := n . router . Stop ( ) ; err != nil {
n . Logger . Error ( "failed to stop router" , "err" , err )
}
}
}
if err := n . transport . Close ( ) ; err != nil {
if err := n . transport . Close ( ) ; err != nil {