2018-01-26 18:04:13 +00:00
|
|
|
package network
|
|
|
|
|
|
|
|
import (
|
2019-09-09 14:54:38 +00:00
|
|
|
"net"
|
|
|
|
|
2020-03-03 14:21:42 +00:00
|
|
|
"github.com/nspcc-dev/neo-go/pkg/network/payload"
|
2018-01-26 18:04:13 +00:00
|
|
|
)
|
|
|
|
|
2019-09-03 14:51:37 +00:00
|
|
|
// Peer represents a network node neo-go is connected to.
|
2018-01-31 08:27:08 +00:00
|
|
|
type Peer interface {
|
2019-11-06 07:55:21 +00:00
|
|
|
// RemoteAddr returns the remote address that we're connected to now.
|
|
|
|
RemoteAddr() net.Addr
|
|
|
|
// PeerAddr returns the remote address that should be used to establish
|
|
|
|
// a new connection to the node. It can differ from the RemoteAddr
|
|
|
|
// address in case where the remote node is a client and its current
|
|
|
|
// connection port is different from the one the other node should use
|
|
|
|
// to connect to it. It's only valid after the handshake is completed,
|
|
|
|
// before that it returns the same address as RemoteAddr.
|
|
|
|
PeerAddr() net.Addr
|
2018-03-14 09:36:59 +00:00
|
|
|
Disconnect(error)
|
2020-01-16 18:16:31 +00:00
|
|
|
|
|
|
|
// EnqueueMessage is a temporary wrapper that sends a message via
|
|
|
|
// EnqueuePacket if there is no error in serializing it.
|
|
|
|
EnqueueMessage(*Message) error
|
|
|
|
|
|
|
|
// EnqueuePacket is a blocking packet enqueuer, it doesn't return until
|
|
|
|
// it puts given packet into the queue. It accepts a slice of bytes that
|
|
|
|
// can be shared with other queues (so that message marshalling can be
|
|
|
|
// done once for all peers). Does nothing is the peer is not yet
|
|
|
|
// completed handshaking.
|
|
|
|
EnqueuePacket([]byte) error
|
|
|
|
|
2020-01-23 16:40:40 +00:00
|
|
|
// EnqueueP2PMessage is a temporary wrapper that sends a message via
|
|
|
|
// EnqueueP2PPacket if there is no error in serializing it.
|
|
|
|
EnqueueP2PMessage(*Message) error
|
|
|
|
|
|
|
|
// EnqueueP2PPacket is a blocking packet enqueuer, it doesn't return until
|
|
|
|
// it puts given packet into the queue. It accepts a slice of bytes that
|
|
|
|
// can be shared with other queues (so that message marshalling can be
|
|
|
|
// done once for all peers). Does nothing is the peer is not yet
|
|
|
|
// completed handshaking. This queue is intended to be used for unicast
|
|
|
|
// peer to peer communication that is more important than broadcasts
|
|
|
|
// (handled by EnqueuePacket), but less important than high-priority
|
|
|
|
// messages (handled by EnqueueHPPacket).
|
|
|
|
EnqueueP2PPacket([]byte) error
|
|
|
|
|
2020-01-16 18:16:31 +00:00
|
|
|
// EnqueueHPPacket is a blocking high priority packet enqueuer, it
|
|
|
|
// doesn't return until it puts given packet into the high-priority
|
|
|
|
// queue.
|
|
|
|
EnqueueHPPacket([]byte) error
|
2018-03-14 09:36:59 +00:00
|
|
|
Version() *payload.Version
|
2020-01-17 10:17:19 +00:00
|
|
|
LastBlockIndex() uint32
|
2019-09-13 12:43:22 +00:00
|
|
|
Handshaked() bool
|
2020-01-20 16:02:19 +00:00
|
|
|
|
|
|
|
// SendPing enqueues a ping message to be sent to the peer and does
|
|
|
|
// appropriate protocol handling like timeouts and outstanding pings
|
|
|
|
// management.
|
2020-01-27 09:44:05 +00:00
|
|
|
SendPing(*Message) error
|
2020-01-21 14:26:08 +00:00
|
|
|
// SendVersion checks handshake status and sends a version message to
|
|
|
|
// the peer.
|
|
|
|
SendVersion() error
|
2019-09-13 12:43:22 +00:00
|
|
|
SendVersionAck(*Message) error
|
2020-01-15 14:03:42 +00:00
|
|
|
// StartProtocol is a goroutine to be run after the handshake. It
|
|
|
|
// implements basic peer-related protocol handling.
|
|
|
|
StartProtocol()
|
2019-09-13 12:43:22 +00:00
|
|
|
HandleVersion(*payload.Version) error
|
|
|
|
HandleVersionAck() error
|
2020-01-20 16:02:19 +00:00
|
|
|
|
|
|
|
// HandlePong checks pong contents against Peer's state and updates it.
|
|
|
|
HandlePong(pong *payload.Ping) error
|
2018-01-31 08:27:08 +00:00
|
|
|
}
|