bug fix in daemon -- network name only, no chain hash
This commit is contained in:
parent
cebfae60c7
commit
94c3a51760
|
@ -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)
|
||||
|
|
|
@ -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 }
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue