aboutsummaryrefslogtreecommitdiffstats
path: root/p2p/peer.go
diff options
context:
space:
mode:
Diffstat (limited to 'p2p/peer.go')
-rw-r--r--p2p/peer.go36
1 files changed, 22 insertions, 14 deletions
diff --git a/p2p/peer.go b/p2p/peer.go
index 482e3d506..b61cced54 100644
--- a/p2p/peer.go
+++ b/p2p/peer.go
@@ -28,7 +28,8 @@ import (
"github.com/ethereum/go-ethereum/common/mclock"
"github.com/ethereum/go-ethereum/event"
"github.com/ethereum/go-ethereum/log"
- "github.com/ethereum/go-ethereum/p2p/discover"
+ "github.com/ethereum/go-ethereum/p2p/enode"
+ "github.com/ethereum/go-ethereum/p2p/enr"
"github.com/ethereum/go-ethereum/rlp"
)
@@ -60,7 +61,7 @@ type protoHandshake struct {
Name string
Caps []Cap
ListenPort uint64
- ID discover.NodeID
+ ID []byte // secp256k1 public key
// Ignore additional fields (for forward compatibility).
Rest []rlp.RawValue `rlp:"tail"`
@@ -90,12 +91,12 @@ const (
// PeerEvent is an event emitted when peers are either added or dropped from
// a p2p.Server or when a message is sent or received on a peer connection
type PeerEvent struct {
- Type PeerEventType `json:"type"`
- Peer discover.NodeID `json:"peer"`
- Error string `json:"error,omitempty"`
- Protocol string `json:"protocol,omitempty"`
- MsgCode *uint64 `json:"msg_code,omitempty"`
- MsgSize *uint32 `json:"msg_size,omitempty"`
+ Type PeerEventType `json:"type"`
+ Peer enode.ID `json:"peer"`
+ Error string `json:"error,omitempty"`
+ Protocol string `json:"protocol,omitempty"`
+ MsgCode *uint64 `json:"msg_code,omitempty"`
+ MsgSize *uint32 `json:"msg_size,omitempty"`
}
// Peer represents a connected remote node.
@@ -115,17 +116,23 @@ type Peer struct {
}
// NewPeer returns a peer for testing purposes.
-func NewPeer(id discover.NodeID, name string, caps []Cap) *Peer {
+func NewPeer(id enode.ID, name string, caps []Cap) *Peer {
pipe, _ := net.Pipe()
- conn := &conn{fd: pipe, transport: nil, id: id, caps: caps, name: name}
+ node := enode.SignNull(new(enr.Record), id)
+ conn := &conn{fd: pipe, transport: nil, node: node, caps: caps, name: name}
peer := newPeer(conn, nil)
close(peer.closed) // ensures Disconnect doesn't block
return peer
}
// ID returns the node's public key.
-func (p *Peer) ID() discover.NodeID {
- return p.rw.id
+func (p *Peer) ID() enode.ID {
+ return p.rw.node.ID()
+}
+
+// Node returns the peer's node descriptor.
+func (p *Peer) Node() *enode.Node {
+ return p.rw.node
}
// Name returns the node name that the remote node advertised.
@@ -160,7 +167,8 @@ func (p *Peer) Disconnect(reason DiscReason) {
// String implements fmt.Stringer.
func (p *Peer) String() string {
- return fmt.Sprintf("Peer %x %v", p.rw.id[:8], p.RemoteAddr())
+ id := p.ID()
+ return fmt.Sprintf("Peer %x %v", id[:8], p.RemoteAddr())
}
// Inbound returns true if the peer is an inbound connection
@@ -177,7 +185,7 @@ func newPeer(conn *conn, protocols []Protocol) *Peer {
disc: make(chan DiscReason),
protoErr: make(chan error, len(protomap)+1), // protocols + pingLoop
closed: make(chan struct{}),
- log: log.New("id", conn.id, "conn", conn.flags),
+ log: log.New("id", conn.node.ID(), "conn", conn.flags),
}
return p
}