protocol

package
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Apr 9, 2026 License: MIT Imports: 14 Imported by: 0

Documentation

Index

Constants

View Source
const (
	FTFilename        byte = 0x01
	FTFileSize        byte = 0x02
	FTFileType        byte = 0x03
	FTFileFormat      byte = 0x04
	FTSources         byte = 0x15
	FTCompleteSources byte = 0x30
	FTFileSizeHi      byte = 0x3A
	FTMediaLength     byte = 0xD3
	FTMediaBitrate    byte = 0xD4
	FTMediaCodec      byte = 0xD5
)
View Source
const (
	OpUndefined      byte = 0x00
	EdonkeyHeader    byte = 0xE3
	EdonkeyProt      byte = 0xE3
	PackedProt       byte = 0xD4
	EMuleProt        byte = 0xC5
	KadCompressedUDP byte = 0xE5
	KademliaHeader   byte = 0xE4

	PacketHeaderSize = 6
)
View Source
const (
	TagTypeString = 0x02
	TagTypeUint32 = 0x03
	TagTypeUint16 = 0x08
	TagTypeUint8  = 0x09
	TagTypeUint64 = 0x0B
	TagTypeStr1   = 0x11
)

Variables

View Source
var (
	Terminal = MustHashFromString("31D6CFE0D16AE931B73C59D7E0C089C0")
	LibED2K  = MustHashFromString("31D6CFE0D14CE931B73C59D7E0C04BC0")
	EMule    = MustHashFromString("31D6CFE0D10EE931B73C59D7E0C06FC0")
	Invalid  Hash
)

Functions

func ReadBytes

func ReadBytes(src *bytes.Reader, size int) ([]byte, error)

func ReadInt32

func ReadInt32(src *bytes.Reader) (int32, error)

func ReadUInt16

func ReadUInt16(src *bytes.Reader) (uint16, error)

func ReadUInt32

func ReadUInt32(src *bytes.Reader) (uint32, error)

func ReadUInt64

func ReadUInt64(src *bytes.Reader) (uint64, error)

func WriteEndpoint

func WriteEndpoint(dst *bytes.Buffer, endpoint Endpoint) error

func WriteHash

func WriteHash(dst *bytes.Buffer, hash Hash) error

func WriteInt32

func WriteInt32(dst *bytes.Buffer, value int32) error

func WriteUInt16

func WriteUInt16(dst *bytes.Buffer, value uint16) error

func WriteUInt32

func WriteUInt32(dst *bytes.Buffer, value uint32) error

func WriteUInt64

func WriteUInt64(dst *bytes.Buffer, value uint64) error

Types

type BitField

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

func NewBitField

func NewBitField(size int) BitField

func (*BitField) Assign

func (b *BitField) Assign(raw []byte, bits int)

func (BitField) Bits

func (b BitField) Bits() []bool

func (BitField) BytesCount

func (b BitField) BytesCount() int

func (*BitField) ClearAll

func (b *BitField) ClearAll()

func (*BitField) ClearBit

func (b *BitField) ClearBit(index int)

func (BitField) Count

func (b BitField) Count() int

func (*BitField) Get

func (b *BitField) Get(src *bytes.Reader) error

func (BitField) GetBit

func (b BitField) GetBit(index int) bool

func (BitField) Len

func (b BitField) Len() int

func (BitField) Put

func (b BitField) Put(dst *bytes.Buffer) error

func (*BitField) Resize

func (b *BitField) Resize(size int)

func (*BitField) ResizeWith

func (b *BitField) ResizeWith(size int, val bool)

func (*BitField) SetAll

func (b *BitField) SetAll()

func (*BitField) SetBit

func (b *BitField) SetBit(index int)

type ByteContainer16

type ByteContainer16 struct {
	Value []byte
}

func ByteContainer16FromString

func ByteContainer16FromString(value string) ByteContainer16

func (ByteContainer16) AsString

func (b ByteContainer16) AsString() string

func (ByteContainer16) BytesCount

func (b ByteContainer16) BytesCount() int

func (*ByteContainer16) Get

func (b *ByteContainer16) Get(src *bytes.Reader) error

func (ByteContainer16) Put

func (b ByteContainer16) Put(dst *bytes.Buffer) error

type Endpoint

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

func EndpointFromInet

func EndpointFromInet(addr *net.TCPAddr) Endpoint

func EndpointFromString

func EndpointFromString(addr string, port int) (Endpoint, error)

func NewEndpoint

func NewEndpoint(ip int32, port int) Endpoint

func ReadEndpoint

func ReadEndpoint(src *bytes.Reader) (Endpoint, error)

func (*Endpoint) Assign

func (e *Endpoint) Assign(ip int32, port int) Endpoint

func (*Endpoint) AssignEndpoint

func (e *Endpoint) AssignEndpoint(point Endpoint) Endpoint

func (Endpoint) Compare

func (e Endpoint) Compare(other Endpoint) int

func (Endpoint) Defined

func (e Endpoint) Defined() bool

func (Endpoint) Equal

func (e Endpoint) Equal(other Endpoint) bool

func (Endpoint) HashCode

func (e Endpoint) HashCode() int32

func (Endpoint) IP

func (e Endpoint) IP() int32

func (Endpoint) IsZero

func (e Endpoint) IsZero() bool

func (Endpoint) MarshalJSON

func (e Endpoint) MarshalJSON() ([]byte, error)

func (Endpoint) Port

func (e Endpoint) Port() int

func (*Endpoint) SetIP

func (e *Endpoint) SetIP(ip int32)

func (*Endpoint) SetPort

func (e *Endpoint) SetPort(port int)

func (Endpoint) String

func (e Endpoint) String() string

func (Endpoint) ToTCPAddr

func (e Endpoint) ToTCPAddr() (*net.TCPAddr, error)

func (*Endpoint) UnmarshalJSON

func (e *Endpoint) UnmarshalJSON(data []byte) error

type Hash

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

func HashFromBytes

func HashFromBytes(value []byte) (Hash, error)

func HashFromData

func HashFromData(value []byte) (Hash, error)

func HashFromHashSet

func HashFromHashSet(hashes []Hash) Hash

func HashFromString

func HashFromString(value string) (Hash, error)

func MustHashFromString

func MustHashFromString(value string) Hash

func RandomHash

func RandomHash(eMule bool) (Hash, error)

func ReadHash

func ReadHash(src *bytes.Reader) (Hash, error)

func (*Hash) Assign

func (h *Hash) Assign(other Hash) Hash

func (Hash) At

func (h Hash) At(index int) byte

func (Hash) Bytes

func (h Hash) Bytes() []byte

func (Hash) Compare

func (h Hash) Compare(other Hash) int

func (Hash) Equal

func (h Hash) Equal(other Hash) bool

func (Hash) IsZero

func (h Hash) IsZero() bool

func (Hash) MarshalJSON

func (h Hash) MarshalJSON() ([]byte, error)

func (*Hash) Set

func (h *Hash) Set(index int, value byte)

func (Hash) String

func (h Hash) String() string

func (*Hash) UnmarshalJSON

func (h *Hash) UnmarshalJSON(data []byte) error

type PacketCombiner

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

func NewPacketCombiner

func NewPacketCombiner() PacketCombiner

func (*PacketCombiner) Pack

func (p *PacketCombiner) Pack(typeName string, object Serializable) ([]byte, error)

func (*PacketCombiner) PackPayload

func (p *PacketCombiner) PackPayload(typeName string, object Serializable, payload []byte) ([]byte, int, error)

func (*PacketCombiner) Register

func (p *PacketCombiner) Register(key PacketKey, typeName string, factory packetFactory)

func (PacketCombiner) ServiceSize

func (p PacketCombiner) ServiceSize(header PacketHeader) int

func (*PacketCombiner) SetServiceSizer

func (p *PacketCombiner) SetServiceSizer(fn serviceSizer)

func (*PacketCombiner) Unpack

func (p *PacketCombiner) Unpack(header PacketHeader, src []byte) (Serializable, error)

func (*PacketCombiner) UnpackFrame

func (p *PacketCombiner) UnpackFrame(frame []byte) (PacketHeader, Serializable, error)

type PacketHeader

type PacketHeader struct {
	Protocol byte
	Size     int32
	Packet   byte
}

func (PacketHeader) BytesCount

func (p PacketHeader) BytesCount() int

func (*PacketHeader) Get

func (p *PacketHeader) Get(src *bytes.Reader) error

func (PacketHeader) IsDefined

func (p PacketHeader) IsDefined() bool

func (PacketHeader) Key

func (p PacketHeader) Key() PacketKey

func (PacketHeader) Put

func (p PacketHeader) Put(dst *bytes.Buffer) error

func (*PacketHeader) Reset

func (p *PacketHeader) Reset()

func (*PacketHeader) ResetWithKey

func (p *PacketHeader) ResetWithKey(key PacketKey, size int32)

func (PacketHeader) SizePacket

func (p PacketHeader) SizePacket() int32

func (PacketHeader) String

func (p PacketHeader) String() string

type PacketKey

type PacketKey struct {
	Protocol byte
	Packet   byte
}

func PK

func PK(protocol, packet byte) PacketKey

func (PacketKey) Compare

func (p PacketKey) Compare(other PacketKey) int

func (PacketKey) NormalizedProtocol

func (p PacketKey) NormalizedProtocol() byte

func (PacketKey) String

func (p PacketKey) String() string

type Serializable

type Serializable interface {
	Get(src *bytes.Reader) error
	Put(dst *bytes.Buffer) error
	BytesCount() int
}

type SimpleTag

type SimpleTag struct {
	Type   byte
	ID     byte
	Name   string
	String string
	UInt32 uint32
	UInt64 uint64
}

func NewStringTag

func NewStringTag(id byte, value string) SimpleTag

func NewUInt32Tag

func NewUInt32Tag(id byte, value uint32) SimpleTag

func (SimpleTag) BytesCount

func (t SimpleTag) BytesCount() int

func (*SimpleTag) Get

func (t *SimpleTag) Get(src *bytes.Reader) error

func (SimpleTag) Put

func (t SimpleTag) Put(dst *bytes.Buffer) error

type TagList

type TagList []SimpleTag

func (TagList) BytesCount

func (t TagList) BytesCount() int

func (*TagList) Get

func (t *TagList) Get(src *bytes.Reader) error

func (TagList) Put

func (t TagList) Put(dst *bytes.Buffer) error

type TransferResumeData

type TransferResumeData struct {
	Hashes           []Hash
	Pieces           BitField
	DownloadedBlocks []data.PieceBlock
	Peers            []Endpoint
}

func (TransferResumeData) MarshalJSON

func (r TransferResumeData) MarshalJSON() ([]byte, error)

func (*TransferResumeData) UnmarshalJSON

func (r *TransferResumeData) UnmarshalJSON(data []byte) error

type WithoutDataPacket

type WithoutDataPacket struct{}

func (WithoutDataPacket) BytesCount

func (w WithoutDataPacket) BytesCount() int

func (*WithoutDataPacket) Get

func (w *WithoutDataPacket) Get(_ *bytes.Reader) error

func (WithoutDataPacket) Put

func (w WithoutDataPacket) Put(_ *bytes.Buffer) error

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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