rlpx

package
Version: v0.0.0-...-47a3150 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 15, 2019 License: LGPL-3.0 Imports: 27 Imported by: 0

Documentation

Index

Constants

View Source
const (
	BaseProtocolVersion = 5
	BaseProtocolLength  = uint64(16)
)
View Source
const (

	// HeaderSize is the size of the RLPx header
	HeaderSize = sizeOfType + sizeOfLength
)

Variables

View Source
var (
	ErrStreamClosed = fmt.Errorf("session closed")
)

Functions

This section is empty.

Types

type Cap

type Cap struct {
	Name    string
	Version uint64
}

Cap is the peer capability.

type Capabilities

type Capabilities []*Cap

Capabilities are all the capabilities of the other peer

func (Capabilities) Len

func (c Capabilities) Len() int

func (Capabilities) Less

func (c Capabilities) Less(i, j int) bool

func (Capabilities) Swap

func (c Capabilities) Swap(i, j int)

type Config

type Config struct {
	Prv  *ecdsa.PrivateKey
	Pub  *ecdsa.PublicKey
	Info *Info
}

A Config structure is used to configure an Rlpx session.

type DiscReason

type DiscReason uint
const (
	DiscRequested DiscReason = iota
	DiscNetworkError
	DiscProtocolError
	DiscUselessPeer
	DiscTooManyPeers
	DiscAlreadyConnected
	DiscIncompatibleVersion
	DiscInvalidIdentity
	DiscQuitting
	DiscUnexpectedIdentity
	DiscSelf
	DiscReadTimeout
	DiscSubprotocolError = 0x10
	DiscUnknown          = 0x100
)

func (DiscReason) Error

func (d DiscReason) Error() string

func (DiscReason) String

func (d DiscReason) String() string
type Header []byte

Header represents an RLPx header

func (Header) Encode

func (h Header) Encode(msgType uint16, length uint32)

Encode encodes a header with msg code and length

func (Header) Length

func (h Header) Length() uint32

Length returns the length of the data in a RLPx header

func (Header) MsgType

func (h Header) MsgType() uint16

MsgType returns the msg code in a RLPx header

type Info

type Info struct {
	Version    uint64
	Name       string
	Caps       Capabilities
	ListenPort uint64
	ID         enode.ID `rlp:"tail"`
}

Info is the info of the node

func (*Info) MarshalRLP

func (i *Info) MarshalRLP(dst []byte) []byte

func (*Info) UnmarshalRLP

func (i *Info) UnmarshalRLP(b []byte) error

type Message

type Message struct {
	Code       uint64
	Size       uint32 // size of the paylod
	Payload    io.Reader
	ReceivedAt time.Time
	Err        error
}

Message is the p2p message

type Rlpx

type Rlpx struct {
	Logger hclog.Logger
	// contains filtered or unexported fields
}

Rlpx is the RLPx transport protocol

func (*Rlpx) Accept

func (r *Rlpx) Accept() (network.Session, error)

Accept accepts a new incomming connection

func (*Rlpx) Close

func (r *Rlpx) Close() error

func (*Rlpx) DialTimeout

func (r *Rlpx) DialTimeout(address string, timeout time.Duration) (network.Session, error)

DialTimeout implements the transport interface

func (*Rlpx) Setup

func (r *Rlpx) Setup(priv *ecdsa.PrivateKey, backends []*network.Protocol, info *network.Info, config map[string]interface{}) error

Setup implements the transport interface

type Secrets

type Secrets struct {
	RemoteID              *ecdsa.PublicKey
	AES, MAC              []byte
	EgressMAC, IngressMAC hash.Hash
	Token                 []byte
}

Secrets represents the Session Secrets which are negotiated during the encryption handshake.

type Session

type Session struct {
	Info *Info

	RemoteID *ecdsa.PublicKey
	LocalID  *ecdsa.PublicKey
	// contains filtered or unexported fields
}

Session is the Session between peers (implements net.Conn)

func Client

func Client(rlpx *Rlpx, conn net.Conn, prv *ecdsa.PrivateKey, pub *ecdsa.PublicKey, info *Info) *Session

Client returns a new Rlpx client side Session

func Server

func Server(rlpx *Rlpx, conn net.Conn, prv *ecdsa.PrivateKey, info *Info) *Session

Server returns a new Rlpx server side Session

func (*Session) Close

func (s *Session) Close() error

Close implements the net.Conn interface

func (*Session) CloseChan

func (s *Session) CloseChan() <-chan struct{}

CloseChan returns a read-only channel which is closed as soon as the session is closed.

func (*Session) Disconnect

func (s *Session) Disconnect(reason DiscReason) error

Disconnect sends a disconnect message to the peer and closes the session

func (*Session) GetInfo

func (s *Session) GetInfo() network.Info

GetInfo implements the session interface

func (*Session) Handshake

func (s *Session) Handshake() error

Handshake does the p2p and protocol handshake

func (*Session) IsClosed

func (s *Session) IsClosed() bool

IsClosed does a safe check to see if we have shutdown

func (*Session) LocalAddr

func (s *Session) LocalAddr() net.Addr

LocalAddr implements the net.Conn interface

func (*Session) OpenStream

func (s *Session) OpenStream(offset uint, length uint, spec network.ProtocolSpec) *Stream

func (*Session) Read

func (s *Session) Read(b []byte) (int, error)

Read implements the net.Conn interface

func (*Session) ReadMsg

func (s *Session) ReadMsg() (uint64, []byte, error)

ReadMsg from the Session

func (*Session) RemoteAddr

func (s *Session) RemoteAddr() net.Addr

RemoteAddr implements the net.Conn interface

func (*Session) RemoteIDString

func (s *Session) RemoteIDString() string

func (*Session) RemoteInfo

func (s *Session) RemoteInfo() *Info

func (*Session) SetDeadline

func (s *Session) SetDeadline(t time.Time) error

SetDeadline implements the net.Conn interface

func (*Session) SetReadDeadline

func (s *Session) SetReadDeadline(t time.Time) error

SetReadDeadline implements the net.Conn interface

func (*Session) SetSnappy

func (s *Session) SetSnappy()

func (*Session) SetWriteDeadline

func (s *Session) SetWriteDeadline(t time.Time) error

SetWriteDeadline implements the net.Conn interface

func (*Session) Streams

func (s *Session) Streams() []network.Stream

Streams implements the transport interface

func (*Session) Write

func (s *Session) Write(b []byte) (int, error)

Write implements the net.Conn interface

func (*Session) WriteRawMsg

func (s *Session) WriteRawMsg(code uint64, buf []byte) error

type Stream

type Stream struct {
	// contains filtered or unexported fields
}

Stream represents a logic stream within a RLPx session

func NewStream

func NewStream(offset uint64, length uint64, conn *Session) *Stream

NewStream constructs a new stream with a given offset and length

func (*Stream) Close

func (s *Stream) Close() error

Close implements the net.Conn interface

func (*Stream) LocalAddr

func (s *Stream) LocalAddr() net.Addr

LocalAddr implements the net.Conn interface

func (*Stream) Protocol

func (s *Stream) Protocol() network.ProtocolSpec

func (*Stream) Read

func (s *Stream) Read(b []byte) (n int, err error)

Read implements the net.Conn interface

func (*Stream) RemoteAddr

func (s *Stream) RemoteAddr() net.Addr

RemoteAddr implements the net.Conn interface

func (*Stream) SetDeadline

func (s *Stream) SetDeadline(t time.Time) error

SetDeadline implements the net.Conn interface

func (*Stream) SetReadDeadline

func (s *Stream) SetReadDeadline(t time.Time) error

SetReadDeadline implements the net.Conn interface

func (*Stream) SetWriteDeadline

func (s *Stream) SetWriteDeadline(t time.Time) error

SetWriteDeadline implements the net.Conn interface

func (*Stream) Write

func (s *Stream) Write(b []byte) (int, error)

Write implements the net.Conn interface

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
t or T : Toggle theme light dark auto
y or Y : Canonical URL