aboutsummaryrefslogtreecommitdiffstats
path: root/eth/handler.go
diff options
context:
space:
mode:
authorPéter Szilágyi <peterke@gmail.com>2015-06-26 21:54:27 +0800
committerPéter Szilágyi <peterke@gmail.com>2015-07-01 00:00:00 +0800
commit393d675690923207746ac800568faacae723f251 (patch)
tree9cd743d6f58f34c6635248979f3b45b458b721f4 /eth/handler.go
parentba95e445e16481ea7a94a462347def19b0c2bf2c (diff)
downloaddexon-393d675690923207746ac800568faacae723f251.tar
dexon-393d675690923207746ac800568faacae723f251.tar.gz
dexon-393d675690923207746ac800568faacae723f251.tar.bz2
dexon-393d675690923207746ac800568faacae723f251.tar.lz
dexon-393d675690923207746ac800568faacae723f251.tar.xz
dexon-393d675690923207746ac800568faacae723f251.tar.zst
dexon-393d675690923207746ac800568faacae723f251.zip
cmd/geth, cmd/utils, eth: advertise both eth/60 and eth/61
Diffstat (limited to 'eth/handler.go')
-rw-r--r--eth/handler.go30
1 files changed, 18 insertions, 12 deletions
diff --git a/eth/handler.go b/eth/handler.go
index 278a2bec2..44d297461 100644
--- a/eth/handler.go
+++ b/eth/handler.go
@@ -49,7 +49,7 @@ type ProtocolManager struct {
fetcher *fetcher.Fetcher
peers *peerSet
- SubProtocol p2p.Protocol
+ SubProtocols []p2p.Protocol
eventMux *event.TypeMux
txSub event.Subscription
@@ -68,8 +68,8 @@ type ProtocolManager struct {
// NewProtocolManager returns a new ethereum sub protocol manager. The Ethereum sub protocol manages peers capable
// with the ethereum network.
-func NewProtocolManager(protocolVersion, networkId int, mux *event.TypeMux, txpool txPool, pow pow.PoW, chainman *core.ChainManager) *ProtocolManager {
- // Create the protocol manager and initialize peer handlers
+func NewProtocolManager(networkId int, mux *event.TypeMux, txpool txPool, pow pow.PoW, chainman *core.ChainManager) *ProtocolManager {
+ // Create the protocol manager with the base fields
manager := &ProtocolManager{
eventMux: mux,
txpool: txpool,
@@ -79,15 +79,21 @@ func NewProtocolManager(protocolVersion, networkId int, mux *event.TypeMux, txpo
txsyncCh: make(chan *txsync),
quitSync: make(chan struct{}),
}
- manager.SubProtocol = p2p.Protocol{
- Name: "eth",
- Version: uint(protocolVersion),
- Length: ProtocolLength,
- Run: func(p *p2p.Peer, rw p2p.MsgReadWriter) error {
- peer := manager.newPeer(protocolVersion, networkId, p, rw)
- manager.newPeerCh <- peer
- return manager.handle(peer)
- },
+ // Initiate a sub-protocol for every implemented version we can handle
+ manager.SubProtocols = make([]p2p.Protocol, len(ProtocolVersions))
+ for i := 0; i < len(manager.SubProtocols); i++ {
+ version := ProtocolVersions[i]
+
+ manager.SubProtocols[i] = p2p.Protocol{
+ Name: "eth",
+ Version: version,
+ Length: ProtocolLengths[i],
+ Run: func(p *p2p.Peer, rw p2p.MsgReadWriter) error {
+ peer := manager.newPeer(int(version), networkId, p, rw)
+ manager.newPeerCh <- peer
+ return manager.handle(peer)
+ },
+ }
}
// Construct the different synchronisation mechanisms
manager.downloader = downloader.New(manager.eventMux, manager.chainman.HasBlock, manager.chainman.GetBlock, manager.chainman.InsertChain, manager.removePeer)