mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-20 10:52:25 +00:00
p2p/simulations: WIP make sim compatible with enode/enr
This commit is contained in:
parent
216bd2ceba
commit
5697731c0c
4 changed files with 12 additions and 3 deletions
|
|
@ -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
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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))
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Reference in a new issue