From 94c3a5176082ed8e7590732f7b089ec8d9b6c4c5 Mon Sep 17 00:00:00 2001 From: Jae Kwon Date: Wed, 25 Mar 2015 12:13:32 -0700 Subject: [PATCH] bug fix in daemon -- network name only, no chain hash --- daemon/daemon.go | 2 +- p2p/pex_reactor.go | 8 ++++---- p2p/switch.go | 11 +++++------ 3 files changed, 10 insertions(+), 11 deletions(-) diff --git a/daemon/daemon.go b/daemon/daemon.go index fae9c9792..ddc310762 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 926859316..439b4cf9b 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 5216f77dd..10da29f36 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