v2transport

package module
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Jun 6, 2025 License: ISC Imports: 14 Imported by: 1

Documentation

Index

Constants

View Source
const (

	// MaxGarbageLen is the maximum size of garbage that either peer is
	// allowed to send.
	MaxGarbageLen = 4095
)
View Source
const Subsystem = "V2TR"

Variables

View Source
var (

	// ErrUseV1Protocol is returned when the initiating peer is attempting
	// to use the V1 protocol.
	ErrUseV1Protocol = fmt.Errorf("use v1 protocol instead")

	// ErrShouldDowngradeToV1 is returned when we send the peer our
	// ellswift key and they immediately hang up. This indicates that they
	// don't understand v2 transport and interpreted the 64-byte key as a
	// v1 message header + message. This will (always?) decode to an
	// invalid command and checksum. The caller should try connecting to
	// the peer with the OG v1 transport.
	ErrShouldDowngradeToV1 = fmt.Errorf("should downgrade to v1")
)

Functions

func DisableLog

func DisableLog()

DisableLog disables all library log output. Logging output is disabled by default until UseLogger is called.

func UseLogger

func UseLogger(logger btclog.Logger)

UseLogger uses a specified Logger to output package logging info.

Types

type BitcoinNet

type BitcoinNet uint32

BitcoinNet is a type used to represent the Bitcoin network that we're connecting to.

NOTE: This is identical to the wire.BitcoinNet type, but allows us to shed a large module dependency.

type FSChaCha20

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

FSChaCha20 is a stream cipher that is used to encrypt the length of the packets. This cipher is rekeyed when chunkCtr reaches a multiple of rekeyInterval.

func NewFSChaCha20

func NewFSChaCha20(initialKey []byte) (*FSChaCha20, error)

NewFSChaCha20 initializes a new FSChaCha20 cipher instance.

func (*FSChaCha20) Crypt

func (f *FSChaCha20) Crypt(text []byte) ([]byte, error)

Crypt is used to either encrypt or decrypt text. This function is used for both encryption and decryption as the two operations are identical.

type FSChaCha20Poly1305

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

FSChaCha20Poly1305 is a wrapper around ChaCha20Poly1305 that changes its nonce after every message and is rekeyed after every rekeying interval.

func NewFSChaCha20Poly1305

func NewFSChaCha20Poly1305(initialKey []byte) (*FSChaCha20Poly1305, error)

NewFSChaCha20Poly1305 creates a new instance of FSChaCha20Poly1305.

func (*FSChaCha20Poly1305) Decrypt

func (f *FSChaCha20Poly1305) Decrypt(aad, ciphertext []byte) ([]byte, error)

Decrypt decrypts the ciphertext using the assosicated data, returning the plaintext or an error.

func (*FSChaCha20Poly1305) Encrypt

func (f *FSChaCha20Poly1305) Encrypt(aad, plaintext []byte) ([]byte, error)

Encrypt encrypts the plaintext using the associated data, returning the ciphertext or an error.

type Peer

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

Peer defines the components necessary for sending/receiving data over the v2 transport.

func NewPeer

func NewPeer() *Peer

NewPeer returns a new instance of Peer.

func (*Peer) CompleteHandshake

func (p *Peer) CompleteHandshake(initiating bool, decoyContentLens []int,
	btcnet BitcoinNet) error

CompleteHandshake finishes the v2 protocol negotiation and optionally sends decoy packets after sending the garbage terminator.

func (*Peer) InitiateV2Handshake

func (p *Peer) InitiateV2Handshake(garbageLen int) error

InitiateV2Handshake generates our private key and sends our public key as well as garbage data to our peer.

func (*Peer) Receive

func (p *Peer) Receive(numBytes int) ([]byte, int, error)

Receive receives numBytes bytes from the underlying connection.

func (*Peer) ReceivedPrefix

func (p *Peer) ReceivedPrefix() []byte

ReceivedPrefix returns the partial header bytes we've already received.

func (*Peer) RespondV2Handshake

func (p *Peer) RespondV2Handshake(garbageLen int, net BitcoinNet) error

RespondV2Handshake responds to the initiator, determines if the initiator wants to use the v2 protocol and if so returns our ElligatorSwift-encoded public key followed by our garbage data over. If the initiator does not want to use the v2 protocol, we'll instead revert to the v1 protocol.

func (*Peer) Send

func (p *Peer) Send(data []byte) (int, error)

Send sends data to the underlying connection. It returns the number of bytes sent or an error.

func (*Peer) ShouldDowngradeToV1

func (p *Peer) ShouldDowngradeToV1() bool

ShouldDowngradeToV1 returns true if the v2 handshake failed in a way that suggests the peer does not support v2 and a v1 connection should be attempted.

func (*Peer) UseReadWriter

func (p *Peer) UseReadWriter(rw io.ReadWriter)

UseWriterReader uses the passed-in ReadWriter to Send/Receive to/from.

func (*Peer) V2EncPacket

func (p *Peer) V2EncPacket(contents []byte, aad []byte, ignore bool) ([]byte,
	int, error)

V2EncPacket takes the contents and aad and returns a ciphertext.

func (*Peer) V2ReceivePacket

func (p *Peer) V2ReceivePacket(aad []byte) ([]byte, error)

V2ReceivePacket takes the aad and decrypts a received packet.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL