From 5697731c0c936f5e7b8333e18a7a516386ac715f Mon Sep 17 00:00:00 2001 From: lash Date: Tue, 26 Feb 2019 17:40:19 +0100 Subject: [PATCH] p2p/simulations: WIP make sim compatible with enode/enr --- p2p/simulations/adapters/inproc.go | 3 ++- p2p/simulations/adapters/types.go | 5 +++++ p2p/simulations/network.go | 6 ++++-- rlp/decode.go | 1 + 4 files changed, 12 insertions(+), 3 deletions(-) diff --git a/p2p/simulations/adapters/inproc.go b/p2p/simulations/adapters/inproc.go index bdfbf1c732..d982a47849 100644 --- a/p2p/simulations/adapters/inproc.go +++ b/p2p/simulations/adapters/inproc.go @@ -117,6 +117,7 @@ func (s *SimAdapter) NewNode(config *NodeConfig) (Node, error) { // an in-memory net.Pipe func (s *SimAdapter) Dial(dest *enode.Node) (conn net.Conn, err error) { node, ok := s.GetNode(dest.ID()) + log.Debug("destnode", "dest", dest) if !ok { return nil, fmt.Errorf("unknown node: %s", dest.ID()) } @@ -132,7 +133,7 @@ func (s *SimAdapter) Dial(dest *enode.Node) (conn net.Conn, err error) { // this is simulated 'listening' // asynchronously call the dialed destination node's p2p server // to set up connection on the 'listening' side - go srv.SetupConn(pipe1, 0, nil) + go srv.SetupConn(pipe1, 0, dest) return pipe2, nil } diff --git a/p2p/simulations/adapters/types.go b/p2p/simulations/adapters/types.go index 31856b76dd..f08bdb8ada 100644 --- a/p2p/simulations/adapters/types.go +++ b/p2p/simulations/adapters/types.go @@ -103,6 +103,8 @@ type NodeConfig struct { Reachable func(id enode.ID) bool Port uint16 + + EnodeFunc func() *enode.Node } // nodeConfigJSON is used to encode and decode NodeConfig as JSON by encoding @@ -168,6 +170,9 @@ func (n *NodeConfig) UnmarshalJSON(data []byte) error { // Node returns the node descriptor represented by the config. func (n *NodeConfig) Node() *enode.Node { + if n.EnodeFunc != nil { + return n.EnodeFunc() + } return enode.NewV4(&n.PrivateKey.PublicKey, net.IP{127, 0, 0, 1}, int(n.Port), int(n.Port)) } diff --git a/p2p/simulations/network.go b/p2p/simulations/network.go index 483d4ab87d..46e981f180 100644 --- a/p2p/simulations/network.go +++ b/p2p/simulations/network.go @@ -303,17 +303,19 @@ func (net *Network) Connect(oneID, otherID enode.ID) error { } func (net *Network) connect(oneID, otherID enode.ID) error { - log.Debug("Connecting nodes with addPeer", "id", oneID, "other", otherID) conn, err := net.initConn(oneID, otherID) if err != nil { + log.Error("connect", "init", err.Error()) return err } client, err := conn.one.Client() if err != nil { + log.Error("connect", "client", err.Error()) return err } net.events.Send(ControlEvent(conn)) - return client.Call(nil, "admin_addPeer", string(conn.other.Addr())) + s := string(conn.other.Addr()) + return client.Call(nil, "admin_addPeer", s) } // Disconnect disconnects two nodes by calling the "admin_removePeer" RPC diff --git a/rlp/decode.go b/rlp/decode.go index e638c01eaf..4545f9a8db 100644 --- a/rlp/decode.go +++ b/rlp/decode.go @@ -405,6 +405,7 @@ func decodeByteSlice(s *Stream, val reflect.Value) error { } func decodeByteArray(s *Stream, val reflect.Value) error { + log.Warn("in decodebytarray", "v", val) kind, size, err := s.Kind() if err != nil { return err