Documentation ¶
Overview ¶
Package rlpx implements the RLPx transport protocol.
Index ¶
- Constants
- func CalculateNonce(recordCount uint, input []byte) []byte
- func Encrypt(cipher1 cipher.AEAD, fragment []byte, additionalData []byte, ...) (encrypted []byte, err error)
- func HkdfExpandLabel(secret []byte, label string, hashVal []byte, outputLength int) ([]byte, error)
- type AdditionalData
- type Client
- func (c *Client) Cleanup()
- func (c *Client) InitWithSecrets(secret SessionSecret)
- func (c *Client) PerformHandshake() error
- func (c *Client) ReadAndDecrypt(packetType PacketType) (*DataPacket, error)
- func (c *Client) ReadAndDecryptMessage(msg interface{}, packetType PacketType) error
- func (c *Client) SetClientSigningPrivateKey(clientSigningPrivateKey *signaturealgorithm.PrivateKey)
- func (c *Client) SetServer(server *Server)
- func (c *Client) SetServerSigningPublicKey(serverSigningPublicKey *signaturealgorithm.PublicKey)
- func (c *Client) WriteEncrypted(data []byte, context uint64, packetType PacketType) error
- type Conn
- func (c *Conn) Close() error
- func (c *Conn) Handshake(prv *signaturealgorithm.PrivateKey) (*signaturealgorithm.PublicKey, error)
- func (c *Conn) InitWithSecrets(secret SessionSecret)
- func (c *Conn) Read() (code uint64, data []byte, wireSize int, err error)
- func (c *Conn) SetDeadline(deadlineTime time.Time) error
- func (c *Conn) SetReadDeadline(deadlineTime time.Time) error
- func (c *Conn) SetSnappy(snappy bool)
- func (c *Conn) SetWriteDeadline(deadlineTime time.Time) error
- func (c *Conn) Write(code uint64, data []byte) (uint32, error)
- type DataPacket
- type Header
- type PacketType
- type ReadBuffer
- type RlpxSerializer
- func (rs *RlpxSerializer) Deserialize(msg interface{}, reader io.Reader) ([]byte, error)
- func (rs *RlpxSerializer) Serialize(msg interface{}) ([]byte, error)
- func (rs *RlpxSerializer) SerializeDeterministic(msg interface{}, padLen int) ([]byte, error)
- func (rs *RlpxSerializer) SetContext(context string)
- type Serializer
- type Server
- func (s *Server) Cleanup()
- func (s *Server) InitWithSecrets(secret SessionSecret)
- func (s *Server) PerformHandshake() error
- func (s *Server) Read() error
- func (s *Server) ReadAndDecrypt(packetType PacketType) (*DataPacket, error)
- func (s *Server) ReadAndDecryptMessage(msg interface{}, packetType PacketType) error
- func (s *Server) SetClient(client *Client)
- func (s *Server) SetServerSigningPrivateKey(serverSigningPrivateKey *signaturealgorithm.PrivateKey)
- func (s *Server) WriteEncrypted(data []byte, context uint64, packetType PacketType) error
- type SessionSecret
- type WriteBuffer
Constants ¶
const ( PacketTypeHandshake PacketType = 21 PacketTypeApplicationData PacketType = 23 ReadTimeout = time.Second * 10 WriteTimeout = time.Second * 20 )
Variables ¶
This section is empty.
Functions ¶
func CalculateNonce ¶
Types ¶
type AdditionalData ¶
type Client ¶
func NewClient ¶
func NewClient(conn io.ReadWriter, clientSigningPrivateKey *signaturealgorithm.PrivateKey, serverSigningPublicKey *signaturealgorithm.PublicKey, context string) *Client
func (*Client) InitWithSecrets ¶
func (c *Client) InitWithSecrets(secret SessionSecret)
func (*Client) PerformHandshake ¶
func (*Client) ReadAndDecrypt ¶
func (c *Client) ReadAndDecrypt(packetType PacketType) (*DataPacket, error)
func (*Client) ReadAndDecryptMessage ¶
func (c *Client) ReadAndDecryptMessage(msg interface{}, packetType PacketType) error
func (*Client) SetClientSigningPrivateKey ¶
func (c *Client) SetClientSigningPrivateKey(clientSigningPrivateKey *signaturealgorithm.PrivateKey)
func (*Client) SetServerSigningPublicKey ¶
func (c *Client) SetServerSigningPublicKey(serverSigningPublicKey *signaturealgorithm.PublicKey)
func (*Client) WriteEncrypted ¶
func (c *Client) WriteEncrypted(data []byte, context uint64, packetType PacketType) error
type Conn ¶
type Conn struct {
// contains filtered or unexported fields
}
Conn is an RLPx network connection. It wraps a low-level network connection. The underlying connection should not be used for other activity when it is wrapped by Conn.
Before sending messages, a handshake must be performed by calling the Handshake method. This type is not generally safe for concurrent use, but reading and writing of messages may happen concurrently after the handshake.
func NewConn ¶
NewConn wraps the given network connection. If dialDest is non-nil, the connection behaves as the initiator during the handshake.
func (*Conn) Handshake ¶
func (c *Conn) Handshake(prv *signaturealgorithm.PrivateKey) (*signaturealgorithm.PublicKey, error)
Handshake performs the handshake. This must be called before any data is written or read from the connection.
func (*Conn) InitWithSecrets ¶
func (c *Conn) InitWithSecrets(secret SessionSecret)
func (*Conn) Read ¶
Read reads a message from the connection. The returned data buffer is valid until the next call to Read.
func (*Conn) SetDeadline ¶
SetDeadline sets the deadline for all future read and write operations.
func (*Conn) SetReadDeadline ¶
SetReadDeadline sets the deadline for all future read operations.
func (*Conn) SetSnappy ¶
SetSnappy enables or disables snappy compression of messages. This is usually called after the devp2p Hello message exchange when the negotiated version indicates that compression is available on both ends of the connection.
func (*Conn) SetWriteDeadline ¶
SetWriteDeadline sets the deadline for all future write operations.
type DataPacket ¶
type DataPacket struct {
// contains filtered or unexported fields
}
type PacketType ¶
type PacketType byte
type ReadBuffer ¶
type ReadBuffer struct { Data []byte // contains filtered or unexported fields }
ReadBuffer implements buffering for network reads. This type is similar to bufio.Reader, with two crucial differences: the buffer slice is exposed, and the buffer keeps all read data available until reset.
How to use this type:
Keep a ReadBuffer b alongside the underlying network connection. When reading a packet from the connection, first call b.reset(). This empties b.data. Now perform reads through b.read() until the end of the packet is reached. The complete packet data is now available in b.data.
func (*ReadBuffer) Grow ¶
func (b *ReadBuffer) Grow(n int)
Grow ensures the buffer has at least n bytes of unused space.
func (*ReadBuffer) Read ¶
Read reads at least n bytes from r, returning the bytes. The returned slice is valid until the next call to Reset.
func (*ReadBuffer) Reset ¶
func (b *ReadBuffer) Reset()
Reset removes all processed data which was read since the last call to Reset. After Reset, len(b.data) is zero.
type RlpxSerializer ¶
type RlpxSerializer struct {
// contains filtered or unexported fields
}
func (*RlpxSerializer) Deserialize ¶
func (rs *RlpxSerializer) Deserialize(msg interface{}, reader io.Reader) ([]byte, error)
func (*RlpxSerializer) Serialize ¶
func (rs *RlpxSerializer) Serialize(msg interface{}) ([]byte, error)
func (*RlpxSerializer) SerializeDeterministic ¶
func (rs *RlpxSerializer) SerializeDeterministic(msg interface{}, padLen int) ([]byte, error)
func (*RlpxSerializer) SetContext ¶
func (rs *RlpxSerializer) SetContext(context string)
type Serializer ¶
type Serializer interface { Serialize(msg interface{}) ([]byte, error) SerializeDeterministic(msg interface{}, padLen int) ([]byte, error) Deserialize(msg interface{}, reader io.Reader) ([]byte, error) SetContext(context string) }
func NewRlpxSerializer ¶
func NewRlpxSerializer() Serializer
type Server ¶
type Server struct {
// contains filtered or unexported fields
}
func NewServer ¶
func NewServer(conn io.ReadWriter, serverSigningPrivateKey *signaturealgorithm.PrivateKey, context string) *Server
func (*Server) InitWithSecrets ¶
func (s *Server) InitWithSecrets(secret SessionSecret)
func (*Server) PerformHandshake ¶
func (*Server) ReadAndDecrypt ¶
func (s *Server) ReadAndDecrypt(packetType PacketType) (*DataPacket, error)
func (*Server) ReadAndDecryptMessage ¶
func (s *Server) ReadAndDecryptMessage(msg interface{}, packetType PacketType) error
func (*Server) SetServerSigningPrivateKey ¶
func (s *Server) SetServerSigningPrivateKey(serverSigningPrivateKey *signaturealgorithm.PrivateKey)
func (*Server) WriteEncrypted ¶
func (s *Server) WriteEncrypted(data []byte, context uint64, packetType PacketType) error
type SessionSecret ¶
type SessionSecret struct { ClientHandshakeKey []byte ServerHandshakeKey []byte ClientHandshakeIv []byte ServerHandshakeIv []byte ClientApplicationKey []byte ServerApplicationKey []byte ClientApplicationIv []byte ServerApplicationIv []byte ClientHandshakeCipher cipher.AEAD ServerHandshakeCipher cipher.AEAD ClientApplicationCipher cipher.AEAD ServerApplicationCipher cipher.AEAD TranscriptHash []byte // contains filtered or unexported fields }
func NewSessionSecret ¶
func NewSessionSecret(transcriptHash []byte, sharedSecret []byte) (*SessionSecret, error)
func (*SessionSecret) CreateApplicationSecrets ¶
func (ss *SessionSecret) CreateApplicationSecrets(transcriptHash []byte) error
type WriteBuffer ¶
type WriteBuffer struct {
Data []byte
}
WriteBuffer implements buffering for network writes. This is essentially a convenience wrapper around a byte slice.
func (*WriteBuffer) AppendZero ¶
func (b *WriteBuffer) AppendZero(n int) []byte
func (*WriteBuffer) Reset ¶
func (b *WriteBuffer) Reset()