Documentation
¶
Index ¶
- Constants
- Variables
- func DisableLog()
- func UseLogger(logger btclog.Logger)
- type BitcoinNet
- type FSChaCha20
- type FSChaCha20Poly1305
- type Peer
- func (p *Peer) CompleteHandshake(initiating bool, decoyContentLens []int, btcnet BitcoinNet) error
- func (p *Peer) InitiateV2Handshake(garbageLen int) error
- func (p *Peer) Receive(numBytes int) ([]byte, int, error)
- func (p *Peer) ReceivedPrefix() []byte
- func (p *Peer) RespondV2Handshake(garbageLen int, net BitcoinNet) error
- func (p *Peer) Send(data []byte) (int, error)
- func (p *Peer) ShouldDowngradeToV1() bool
- func (p *Peer) UseReadWriter(rw io.ReadWriter)
- func (p *Peer) V2EncPacket(contents []byte, aad []byte, ignore bool) ([]byte, int, error)
- func (p *Peer) V2ReceivePacket(aad []byte) ([]byte, error)
Constants ¶
const ( // MaxGarbageLen is the maximum size of garbage that either peer is // allowed to send. MaxGarbageLen = 4095 )
const Subsystem = "V2TR"
Variables ¶
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.
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.
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.
type Peer ¶
type Peer struct {
// contains filtered or unexported fields
}
Peer defines the components necessary for sending/receiving data over the v2 transport.
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 ¶
InitiateV2Handshake generates our private key and sends our public key as well as garbage data to our peer.
func (*Peer) ReceivedPrefix ¶
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 ¶
Send sends data to the underlying connection. It returns the number of bytes sent or an error.
func (*Peer) ShouldDowngradeToV1 ¶
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 ¶
V2EncPacket takes the contents and aad and returns a ciphertext.