diff --git a/daemon/daemon.go b/daemon/daemon.go index fae9c979..ddc31076 100644 --- a/daemon/daemon.go +++ b/daemon/daemon.go @@ -69,7 +69,7 @@ func NewNode() *Node { } sw := p2p.NewSwitch() - sw.SetChainId(state.Hash(), config.App().GetString("Network")) + sw.SetNetwork(config.App().GetString("Network")) sw.AddReactor("PEX", pexReactor).Start(sw) sw.AddReactor("BLOCKCHAIN", bcReactor).Start(sw) sw.AddReactor("MEMPOOL", mempoolReactor).Start(sw) diff --git a/p2p/pex_reactor.go b/p2p/pex_reactor.go index 92685931..439b4cf9 100644 --- a/p2p/pex_reactor.go +++ b/p2p/pex_reactor.go @@ -98,9 +98,9 @@ func (pexR *PEXReactor) Receive(chId byte, src *Peer, msgBytes []byte) { switch msg.(type) { case *pexHandshakeMessage: - chainId := msg.(*pexHandshakeMessage).ChainId - if chainId != pexR.sw.chainId { - err := fmt.Sprintf("Peer is on a different chain/network. Got %s, expected %s", chainId, pexR.sw.chainId) + network := msg.(*pexHandshakeMessage).Network + if network != pexR.sw.network { + err := fmt.Sprintf("Peer is on a different chain/network. Got %s, expected %s", network, pexR.sw.network) pexR.sw.StopPeerForError(src, err) } case *pexRequestMessage: @@ -238,7 +238,7 @@ func DecodeMessage(bz []byte) (msg interface{}, err error) { A pexHandshakeMessage contains the peer's chainId */ type pexHandshakeMessage struct { - ChainId string + Network string } func (m *pexHandshakeMessage) TypeByte() byte { return msgTypeHandshake } diff --git a/p2p/switch.go b/p2p/switch.go index 5216f77d..10da29f3 100644 --- a/p2p/switch.go +++ b/p2p/switch.go @@ -1,7 +1,6 @@ package p2p import ( - "encoding/hex" "errors" "fmt" "net" @@ -28,7 +27,7 @@ or more `Channels`. So while sending outgoing messages is typically performed o incoming messages are received on the reactor. */ type Switch struct { - chainId string + network string reactors map[string]Reactor chDescs []*ChannelDescriptor reactorsByCh map[byte]Reactor @@ -48,7 +47,7 @@ const ( func NewSwitch() *Switch { sw := &Switch{ - chainId: "", + network: "", reactors: make(map[string]Reactor), chDescs: make([]*ChannelDescriptor, 0), reactorsByCh: make(map[byte]Reactor), @@ -61,8 +60,8 @@ func NewSwitch() *Switch { } // Not goroutine safe. -func (sw *Switch) SetChainId(hash []byte, network string) { - sw.chainId = hex.EncodeToString(hash) + "-" + network +func (sw *Switch) SetNetwork(network string) { + sw.network = network } // Not goroutine safe. @@ -139,7 +138,7 @@ func (sw *Switch) AddPeerWithConnection(conn net.Conn, outbound bool) (*Peer, er go peer.start() // Send handshake - msg := &pexHandshakeMessage{ChainId: sw.chainId} + msg := &pexHandshakeMessage{Network: sw.network} peer.Send(PexChannel, msg) return peer, nil