codec

package
v0.0.0-...-249e25c Latest Latest
Warning

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

Go to latest
Published: Jun 10, 2025 License: AGPL-3.0 Imports: 7 Imported by: 0

Documentation

Index

Constants

View Source
const MessageTypeLen = 1

Variables

View Source
var (
	ErrUnsupportedMessageType    = errors.New("unsupported message type")
	ErrUnsupportedProtocolOption = errors.New("unsupported protocol option")
)

errors ...

View Source
var (
	ErrTooSmall       = errors.New("new size cannot be smaller than buffered messag length")
	ErrBufferTooSmall = errors.New("new size cannot be larger than write buffer")
	ErrNotEnoughSpace = errors.New("write buffer has insufficient space for message")
)

Functions

This section is empty.

Types

type Ack

type Ack struct {
	Address     Address
	DelaySample DelaySample
}

Ack ...

func (*Ack) ByteLen

func (v *Ack) ByteLen() int

ByteLen ...

func (*Ack) Marshal

func (v *Ack) Marshal(b []byte) (size int)

Marshal ...

func (*Ack) Type

func (v *Ack) Type() MessageType

Type ...

func (*Ack) Unmarshal

func (v *Ack) Unmarshal(b []byte) (size int, err error)

Unmarshal ...

type Address

type Address binmap.Bin

Address ...

func NewAddress

func NewAddress(b binmap.Bin) *Address

NewAddress ...

func (Address) Bin

func (v Address) Bin() binmap.Bin

Bin ...

func (Address) ByteLen

func (v Address) ByteLen() int

ByteLen ...

func (Address) Marshal

func (v Address) Marshal(b []byte) int

Marshal ...

func (*Address) Unmarshal

func (v *Address) Unmarshal(b []byte) (int, error)

Unmarshal ...

type Buffer

type Buffer []byte

Buffer ...

func (Buffer) ByteLen

func (v Buffer) ByteLen() int

ByteLen ...

func (Buffer) Marshal

func (v Buffer) Marshal(b []byte) int

Marshal ...

func (*Buffer) Unmarshal

func (v *Buffer) Unmarshal(b []byte) (int, error)

Unmarshal ...

type Cancel

type Cancel struct {
	Address
}

Cancel ...

func (*Cancel) Type

func (v *Cancel) Type() MessageType

Type ...

type Channel

type Channel uint64

Channel ...

func NewChannel

func NewChannel(b uint64) *Channel

NewChannel ...

func (Channel) ByteLen

func (v Channel) ByteLen() int

ByteLen ...

func (Channel) Marshal

func (v Channel) Marshal(b []byte) int

Marshal ...

func (*Channel) Unmarshal

func (v *Channel) Unmarshal(b []byte) (int, error)

Unmarshal ...

type ChannelHeader

type ChannelHeader struct {
	Channel Channel
	Length  uint16
}

ChannelHeader ...

func (*ChannelHeader) ByteLen

func (v *ChannelHeader) ByteLen() int

ByteLen ...

func (*ChannelHeader) Marshal

func (v *ChannelHeader) Marshal(b []byte) (size int)

Marshal ...

func (*ChannelHeader) Unmarshal

func (v *ChannelHeader) Unmarshal(b []byte) (size int, err error)

Unmarshal ...

type Choke

type Choke struct {
	Empty
}

Choke ...

func (*Choke) Type

func (v *Choke) Type() MessageType

Type ...

type ChunkSizeProtocolOption

type ChunkSizeProtocolOption struct {
	Value uint32
}

ChunkSizeProtocolOption ...

func (*ChunkSizeProtocolOption) ByteLen

func (v *ChunkSizeProtocolOption) ByteLen() int

ByteLen ...

func (*ChunkSizeProtocolOption) Marshal

func (v *ChunkSizeProtocolOption) Marshal(b []byte) int

Marshal ...

func (*ChunkSizeProtocolOption) Type

Type ...

func (*ChunkSizeProtocolOption) Unmarshal

func (v *ChunkSizeProtocolOption) Unmarshal(b []byte) (int, error)

Unmarshal ...

type ChunksPerSignatureProtocolOption

type ChunksPerSignatureProtocolOption struct {
	Value uint32
}

ChunksPerSignatureProtocolOption ...

func (*ChunksPerSignatureProtocolOption) ByteLen

ByteLen ...

func (*ChunksPerSignatureProtocolOption) Marshal

func (v *ChunksPerSignatureProtocolOption) Marshal(b []byte) int

Marshal ...

func (*ChunksPerSignatureProtocolOption) Type

Type ...

func (*ChunksPerSignatureProtocolOption) Unmarshal

func (v *ChunksPerSignatureProtocolOption) Unmarshal(b []byte) (int, error)

Unmarshal ...

type ContentIntegrityProtectionMethodProtocolOption

type ContentIntegrityProtectionMethodProtocolOption struct {
	Value uint8
}

ContentIntegrityProtectionMethodProtocolOption ...

func (*ContentIntegrityProtectionMethodProtocolOption) ByteLen

ByteLen ...

func (*ContentIntegrityProtectionMethodProtocolOption) Marshal

Marshal ...

func (*ContentIntegrityProtectionMethodProtocolOption) Type

Type ...

func (*ContentIntegrityProtectionMethodProtocolOption) Unmarshal

Unmarshal ...

type Data

type Data struct {
	Address   Address
	Timestamp Timestamp
	Data      Buffer
	// contains filtered or unexported fields
}

Data ...

func NewData

func NewData(chunkSize int, b binmap.Bin, t timeutil.Time, d []byte) *Data

NewData ...

func (*Data) ByteLen

func (v *Data) ByteLen() int

ByteLen ...

func (*Data) Marshal

func (v *Data) Marshal(b []byte) (size int)

Marshal ...

func (*Data) Type

func (v *Data) Type() MessageType

Type ...

func (*Data) Unmarshal

func (v *Data) Unmarshal(b []byte) (size int, err error)

Unmarshal ...

type Decoder

type Decoder interface {
	Unmarshal(b []byte) (int, error)
}

Decoder ...

type DelaySample

type DelaySample struct {
	time.Duration
}

DelaySample ...

func (DelaySample) ByteLen

func (v DelaySample) ByteLen() int

ByteLen ...

func (DelaySample) Marshal

func (v DelaySample) Marshal(b []byte) int

Marshal ...

func (*DelaySample) Unmarshal

func (v *DelaySample) Unmarshal(b []byte) (int, error)

Unmarshal ...

type Empty

type Empty struct{}

Empty ...

func (*Empty) ByteLen

func (v *Empty) ByteLen() int

ByteLen ...

func (*Empty) Marshal

func (v *Empty) Marshal(b []byte) int

Marshal ...

func (*Empty) Unmarshal

func (v *Empty) Unmarshal(b []byte) (int, error)

Unmarshal ...

type Encoder

type Encoder interface {
	Marshal(b []byte) int
}

Encoder ...

type End

type End struct {
	Empty
}

End ...

func (*End) Type

func (v *End) Type() MessageType

Type ...

type EpochProtocolOption

type EpochProtocolOption struct {
	Timestamp Timestamp
	Signature Buffer
	// contains filtered or unexported fields
}

EpochProtocolOption ...

func NewEpochProtocolOption

func NewEpochProtocolOption(t timeutil.Time, sig []byte) *EpochProtocolOption

NewEpochProtocolOption ...

func (*EpochProtocolOption) ByteLen

func (v *EpochProtocolOption) ByteLen() int

ByteLen ...

func (*EpochProtocolOption) Marshal

func (v *EpochProtocolOption) Marshal(b []byte) (size int)

Marshal ...

func (*EpochProtocolOption) Type

Type ...

func (*EpochProtocolOption) Unmarshal

func (v *EpochProtocolOption) Unmarshal(b []byte) (size int, err error)

Unmarshal ...

type Handshake

type Handshake struct {
	ChannelID uint32
	Options   ProtocolOptions
	// contains filtered or unexported fields
}

Handshake ...

func NewHandshake

func NewHandshake(channelID uint32) *Handshake

NewHandshake ...

func (*Handshake) ByteLen

func (v *Handshake) ByteLen() (l int)

ByteLen ...

func (*Handshake) Marshal

func (v *Handshake) Marshal(b []byte) (size int)

Marshal ...

func (*Handshake) Type

func (v *Handshake) Type() MessageType

Type ...

func (*Handshake) Unmarshal

func (v *Handshake) Unmarshal(b []byte) (size int, err error)

Unmarshal ...

type Have

type Have struct {
	Address
}

Have ...

func (*Have) Type

func (v *Have) Type() MessageType

Type ...

type Integrity

type Integrity struct {
	Address Address
	Hash    Buffer
	// contains filtered or unexported fields
}

Integrity ...

func (*Integrity) ByteLen

func (v *Integrity) ByteLen() int

ByteLen ...

func (*Integrity) Marshal

func (v *Integrity) Marshal(b []byte) (size int)

Marshal ...

func (*Integrity) Type

func (v *Integrity) Type() MessageType

Type ...

func (*Integrity) Unmarshal

func (v *Integrity) Unmarshal(b []byte) (size int, err error)

Unmarshal ...

type LiveSignatureAlgorithmProtocolOption

type LiveSignatureAlgorithmProtocolOption struct {
	Value uint8
}

LiveSignatureAlgorithmProtocolOption ...

func (*LiveSignatureAlgorithmProtocolOption) ByteLen

ByteLen ...

func (*LiveSignatureAlgorithmProtocolOption) Marshal

Marshal ...

func (*LiveSignatureAlgorithmProtocolOption) Type

Type ...

func (*LiveSignatureAlgorithmProtocolOption) Unmarshal

func (v *LiveSignatureAlgorithmProtocolOption) Unmarshal(b []byte) (int, error)

Unmarshal ...

type LiveWindowProtocolOption

type LiveWindowProtocolOption struct {
	Value uint32
}

LiveWindowProtocolOption ...

func (*LiveWindowProtocolOption) ByteLen

func (v *LiveWindowProtocolOption) ByteLen() int

ByteLen ...

func (*LiveWindowProtocolOption) Marshal

func (v *LiveWindowProtocolOption) Marshal(b []byte) int

Marshal ...

func (*LiveWindowProtocolOption) Type

Type ...

func (*LiveWindowProtocolOption) Unmarshal

func (v *LiveWindowProtocolOption) Unmarshal(b []byte) (int, error)

Unmarshal ...

type MerkleHashTreeFunctionProtocolOption

type MerkleHashTreeFunctionProtocolOption struct {
	Value uint8
}

MerkleHashTreeFunctionProtocolOption ...

func (*MerkleHashTreeFunctionProtocolOption) ByteLen

ByteLen ...

func (*MerkleHashTreeFunctionProtocolOption) Marshal

Marshal ...

func (*MerkleHashTreeFunctionProtocolOption) Type

Type ...

func (*MerkleHashTreeFunctionProtocolOption) Unmarshal

func (v *MerkleHashTreeFunctionProtocolOption) Unmarshal(b []byte) (int, error)

Unmarshal ...

type Message

type Message interface {
	Decoder
	Encoder
	Type() MessageType
	ByteLen() int
}

Message ...

type MessageHandler

type MessageHandler interface {
	HandleHandshake(v Handshake) error
	HandleRestart(v Restart) error
	HandleData(v Data) error
	HandleAck(v Ack) error
	HandleHave(v Have) error
	HandleIntegrity(v Integrity) error
	HandleSignedIntegrity(v SignedIntegrity) error
	HandleRequest(v Request) error
	HandleCancel(v Cancel) error
	HandleChoke(v Choke) error
	HandleUnchoke(v Unchoke) error
	HandlePing(v Ping) error
	HandlePong(v Pong) error
	HandleStreamRequest(v StreamRequest) error
	HandleStreamCancel(v StreamCancel) error
	HandleStreamOpen(v StreamOpen) error
	HandleStreamClose(v StreamClose) error
}

MessageHandler ...

type MessageType

type MessageType uint8

MessageType ...

const (
	HandshakeMessage MessageType
	RestartMessage
	DataMessage
	AckMessage
	HaveMessage
	IntegrityMessage
	SignedIntegrityMessage
	RequestMessage
	CancelMessage
	ChokeMessage
	UnchokeMessage
	PingMessage
	PongMessage
	StreamRequestMessage
	StreamCancelMessage
	StreamOpenMessage
	StreamCloseMessage
	EndMessage MessageType = 255
)

message types

func (MessageType) String

func (m MessageType) String() string

String ...

type MinimumVersionProtocolOption

type MinimumVersionProtocolOption struct {
	Value uint8
}

MinimumVersionProtocolOption ...

func (*MinimumVersionProtocolOption) ByteLen

func (v *MinimumVersionProtocolOption) ByteLen() int

ByteLen ...

func (*MinimumVersionProtocolOption) Marshal

func (v *MinimumVersionProtocolOption) Marshal(b []byte) int

Marshal ...

func (*MinimumVersionProtocolOption) Type

Type ...

func (*MinimumVersionProtocolOption) Unmarshal

func (v *MinimumVersionProtocolOption) Unmarshal(b []byte) (int, error)

Unmarshal ...

type Nonce

type Nonce struct {
	Value uint64
}

Nonce ...

func (*Nonce) ByteLen

func (v *Nonce) ByteLen() int

ByteLen ...

func (*Nonce) Marshal

func (v *Nonce) Marshal(b []byte) (size int)

Marshal ...

func (*Nonce) Unmarshal

func (v *Nonce) Unmarshal(b []byte) (size int, err error)

Unmarshal ...

type Ping

type Ping struct {
	Nonce
}

Ping ...

func (*Ping) Type

func (v *Ping) Type() MessageType

Type ...

type Pong

type Pong struct {
	Nonce Nonce
	Delay uint64
}

Pong ...

func (*Pong) ByteLen

func (v *Pong) ByteLen() int

ByteLen ...

func (*Pong) Marshal

func (v *Pong) Marshal(b []byte) (size int)

Marshal ...

func (*Pong) Type

func (v *Pong) Type() MessageType

Type ...

func (*Pong) Unmarshal

func (v *Pong) Unmarshal(b []byte) (size int, err error)

Unmarshal ...

type ProtocolOption

type ProtocolOption interface {
	Decoder
	Encoder
	Type() ProtocolOptionType
	ByteLen() int
}

ProtocolOption ...

type ProtocolOptionType

type ProtocolOptionType uint8

ProtocolOptionType ...

const (
	VersionOption ProtocolOptionType = iota
	MinimumVersionOption
	SwarmIdentifierOption
	ContentIntegrityProtectionMethodOption
	MerkleHashTreeFunctionOption
	LiveSignatureAlgorithmOption
	ChunkAddressingMethodOption
	LiveWindowOption
	SupportedMessagesOption
	ChunkSizeOption
	ChunksPerSignatureOption
	StreamCountOption
	EpochOption
	EndOption ProtocolOptionType = 255
)

protocol options

func (ProtocolOptionType) String

func (m ProtocolOptionType) String() string

String ...

type ProtocolOptions

type ProtocolOptions []ProtocolOption

ProtocolOptions ...

func (ProtocolOptions) Find

Find ...

func (ProtocolOptions) MustFind

MustFind ...

type Reader

type Reader struct {
	ChunkSize              int
	IntegrityHashSize      int
	IntegritySignatureSize int
	Handler                MessageHandler
}

Reader ...

func (Reader) Read

func (v Reader) Read(b []byte) (n int, err error)

type Request

type Request struct {
	Address   Address
	Timestamp Timestamp
}

Request ...

func (*Request) ByteLen

func (v *Request) ByteLen() int

ByteLen ...

func (*Request) Marshal

func (v *Request) Marshal(b []byte) (size int)

Marshal ...

func (*Request) Type

func (v *Request) Type() MessageType

Type ...

func (*Request) Unmarshal

func (v *Request) Unmarshal(b []byte) (size int, err error)

Unmarshal ...

type Restart

type Restart struct {
	Empty
}

Restart ...

func (*Restart) Type

func (v *Restart) Type() MessageType

Type ...

type SignedIntegrity

type SignedIntegrity struct {
	Address   Address
	Timestamp Timestamp
	Signature Buffer
	// contains filtered or unexported fields
}

SignedIntegrity ...

func (*SignedIntegrity) ByteLen

func (v *SignedIntegrity) ByteLen() int

ByteLen ...

func (*SignedIntegrity) Marshal

func (v *SignedIntegrity) Marshal(b []byte) (size int)

Marshal ...

func (*SignedIntegrity) Type

func (v *SignedIntegrity) Type() MessageType

Type ...

func (*SignedIntegrity) Unmarshal

func (v *SignedIntegrity) Unmarshal(b []byte) (size int, err error)

Unmarshal ...

type Stream

type Stream uint16

Stream ...

func NewStream

func NewStream(b uint16) *Stream

NewStream ...

func (Stream) ByteLen

func (v Stream) ByteLen() int

ByteLen ...

func (Stream) Marshal

func (v Stream) Marshal(b []byte) int

Marshal ...

func (*Stream) Unmarshal

func (v *Stream) Unmarshal(b []byte) (int, error)

Unmarshal ...

type StreamAddress

type StreamAddress struct {
	Stream  Stream
	Address Address
}

StreamAddress ...

func (*StreamAddress) ByteLen

func (v *StreamAddress) ByteLen() int

ByteLen ...

func (*StreamAddress) Marshal

func (v *StreamAddress) Marshal(b []byte) (size int)

Marshal ...

func (*StreamAddress) Unmarshal

func (v *StreamAddress) Unmarshal(b []byte) (size int, err error)

Unmarshal ...

type StreamCancel

type StreamCancel struct {
	Stream
}

StreamCancel ...

func (*StreamCancel) Type

func (v *StreamCancel) Type() MessageType

Type ...

type StreamClose

type StreamClose struct {
	Stream
}

StreamClose ...

func (*StreamClose) Type

func (v *StreamClose) Type() MessageType

Type ...

type StreamCountProtocolOption

type StreamCountProtocolOption struct {
	Value uint16
}

StreamCountProtocolOption ...

func (*StreamCountProtocolOption) ByteLen

func (v *StreamCountProtocolOption) ByteLen() int

ByteLen ...

func (*StreamCountProtocolOption) Marshal

func (v *StreamCountProtocolOption) Marshal(b []byte) int

Marshal ...

func (*StreamCountProtocolOption) Type

Type ...

func (*StreamCountProtocolOption) Unmarshal

func (v *StreamCountProtocolOption) Unmarshal(b []byte) (int, error)

Unmarshal ...

type StreamOpen

type StreamOpen struct {
	StreamAddress
}

StreamOpen ...

func (*StreamOpen) Type

func (v *StreamOpen) Type() MessageType

Type ...

type StreamRequest

type StreamRequest struct {
	StreamAddress
}

StreamRequest ...

func (*StreamRequest) Type

func (v *StreamRequest) Type() MessageType

Type ...

type SwarmIdentifierProtocolOption

type SwarmIdentifierProtocolOption []byte

SwarmIdentifierProtocolOption ...

func NewSwarmIdentifierProtocolOption

func NewSwarmIdentifierProtocolOption(id []byte) *SwarmIdentifierProtocolOption

NewSwarmIdentifierProtocolOption ...

func (*SwarmIdentifierProtocolOption) ByteLen

func (v *SwarmIdentifierProtocolOption) ByteLen() int

ByteLen ...

func (*SwarmIdentifierProtocolOption) Marshal

func (v *SwarmIdentifierProtocolOption) Marshal(b []byte) (size int)

Marshal ...

func (*SwarmIdentifierProtocolOption) Type

Type ...

func (*SwarmIdentifierProtocolOption) Unmarshal

func (v *SwarmIdentifierProtocolOption) Unmarshal(b []byte) (size int, err error)

Unmarshal ...

type Timestamp

type Timestamp struct {
	timeutil.Time
}

Timestamp ...

func (Timestamp) ByteLen

func (v Timestamp) ByteLen() int

ByteLen ...

func (Timestamp) Marshal

func (v Timestamp) Marshal(b []byte) int

Marshal ...

func (*Timestamp) Unmarshal

func (v *Timestamp) Unmarshal(b []byte) (int, error)

Unmarshal ...

type Unchoke

type Unchoke struct {
	Empty
}

Unchoke ...

func (*Unchoke) Type

func (v *Unchoke) Type() MessageType

Type ...

type VersionProtocolOption

type VersionProtocolOption struct {
	Value uint8
}

VersionProtocolOption ...

func (*VersionProtocolOption) ByteLen

func (v *VersionProtocolOption) ByteLen() int

ByteLen ...

func (*VersionProtocolOption) Marshal

func (v *VersionProtocolOption) Marshal(b []byte) int

Marshal ...

func (*VersionProtocolOption) Type

Type ...

func (*VersionProtocolOption) Unmarshal

func (v *VersionProtocolOption) Unmarshal(b []byte) (int, error)

Unmarshal ...

type Writer

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

Writer ...

func NewWriter

func NewWriter(w ioutil.BufferedWriteFlusher) Writer

NewWriter ...

func (*Writer) Available

func (w *Writer) Available() int

func (*Writer) Dirty

func (w *Writer) Dirty() bool

Dirty ...

func (*Writer) Flush

func (w *Writer) Flush() error

Flush ...

func (*Writer) Len

func (w *Writer) Len() int

Len ...

func (*Writer) Reset

func (w *Writer) Reset()

func (*Writer) Write

func (w *Writer) Write(m Message) (int, error)

Write ...

func (*Writer) WriteAck

func (w *Writer) WriteAck(m Ack) (int, error)

WriteAck ...

func (*Writer) WriteCancel

func (w *Writer) WriteCancel(m Cancel) (int, error)

WriteCancel ...

func (*Writer) WriteChoke

func (w *Writer) WriteChoke(m Choke) (int, error)

WriteChoke ...

func (*Writer) WriteData

func (w *Writer) WriteData(m Data) (int, error)

WriteData ...

func (*Writer) WriteHandshake

func (w *Writer) WriteHandshake(m Handshake) (int, error)

WriteHandshake ...

func (*Writer) WriteHave

func (w *Writer) WriteHave(m Have) (int, error)

WriteHave ...

func (*Writer) WriteIntegrity

func (w *Writer) WriteIntegrity(m Integrity) (int, error)

WriteIntegrity ...

func (*Writer) WritePing

func (w *Writer) WritePing(m Ping) (int, error)

WritePing ...

func (*Writer) WritePong

func (w *Writer) WritePong(m Pong) (int, error)

WritePong ...

func (*Writer) WriteRequest

func (w *Writer) WriteRequest(m Request) (int, error)

WriteRequest ...

func (*Writer) WriteRestart

func (w *Writer) WriteRestart(m Restart) (int, error)

WriteRestart ...

func (*Writer) WriteSignedIntegrity

func (w *Writer) WriteSignedIntegrity(m SignedIntegrity) (int, error)

WriteSignedIntegrity ...

func (*Writer) WriteStreamCancel

func (w *Writer) WriteStreamCancel(m StreamCancel) (int, error)

WriteStreamCancel ...

func (*Writer) WriteStreamClose

func (w *Writer) WriteStreamClose(m StreamClose) (int, error)

WriteStreamClose ...

func (*Writer) WriteStreamOpen

func (w *Writer) WriteStreamOpen(m StreamOpen) (int, error)

WriteStreamOpen ...

func (*Writer) WriteStreamRequest

func (w *Writer) WriteStreamRequest(m StreamRequest) (int, error)

WriteStreamRequest ...

func (*Writer) WriteUnchoke

func (w *Writer) WriteUnchoke(m Unchoke) (int, error)

WriteUnchoke ...

Jump to

Keyboard shortcuts

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