bittorrent

package
v0.4.6 Latest Latest
Warning

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

Go to latest
Published: May 2, 2024 License: MIT Imports: 8 Imported by: 0

Documentation

Overview

Package bittorrent provides bittorrent related structures

Index

Constants

View Source
const DHT = ReservedBit(64)

DHT is ReservedBit for BT DHT

View Source
const Extension = ReservedBit(44)

Extension is ReservedBit for bittorrent extensions

Variables

View Source
var ErrInvalidHandshake = errors.New("invalid bittorrent handshake")

ErrInvalidHandshake is returned when a handshake contained invalid format

Functions

This section is empty.

Types

type Bitfield

type Bitfield struct {
	// length in bits
	Length uint32 `bencode:"bits"`
	// bitfield data
	Data []byte `bencode:"bitfield"`
}

Bitfield is a serializable bitmap for bittorrent

func NewBitfield

func NewBitfield(bits uint32, value []byte) *Bitfield

NewBitfield creates new bitfield given number of bits and initial value

func (*Bitfield) AND

func (bf *Bitfield) AND(other *Bitfield) *Bitfield

AND returns copy of Bitfield with bitwise AND applied from other Bitfield

func (*Bitfield) BDecode

func (bf *Bitfield) BDecode(r io.Reader) (err error)

BDecode for fs storage

func (*Bitfield) BEncode

func (bf *Bitfield) BEncode(w io.Writer) (err error)

BEncode for fs storage

func (*Bitfield) Completed

func (bf *Bitfield) Completed() bool

Completed returns true if this Bitfield is 100% set

func (*Bitfield) Copy

func (bf *Bitfield) Copy() *Bitfield

Copy returns an immutable copy of this bitfield

func (*Bitfield) CopyFrom

func (bf *Bitfield) CopyFrom(other *Bitfield)

CopyFrom copies state from other into itself

func (*Bitfield) CountSet

func (bf *Bitfield) CountSet() (sum int)

CountSet counts how many bits are set

func (*Bitfield) Equals

func (bf *Bitfield) Equals(other *Bitfield) bool

Equals checks if a Bitfield is equal to anoter

func (*Bitfield) FindRarest

func (bf *Bitfield) FindRarest(others []*Bitfield, exclude func(uint32) bool) (idx uint32, has bool)

FindRarest finds the set bit we have that is rarest in others

func (*Bitfield) Has

func (bf *Bitfield) Has(index uint32) bool

Has returns true if we have a bit at index set

func (*Bitfield) Inverted

func (bf *Bitfield) Inverted() (i *Bitfield)

Inverted gets copy of current Bitfield with all bits inverted

func (Bitfield) MarshalJSON

func (bf Bitfield) MarshalJSON() (data []byte, err error)

MarshalJSON implements json.Marshaller

func (*Bitfield) OR

func (bf *Bitfield) OR(other *Bitfield) *Bitfield

OR returns Bitfield with bitwise OR applied from other Bitfield

func (*Bitfield) Percent

func (bf *Bitfield) Percent() string

Percent returns string represnetation of percent done

func (*Bitfield) Progress

func (bf *Bitfield) Progress() (fl float64)

Progress returns precent done as a float between 0 and 1

func (*Bitfield) SelfOR

func (bf *Bitfield) SelfOR(other *Bitfield)

SelfOR applies bitwise OR from other Bitfield to itself

func (*Bitfield) Set

func (bf *Bitfield) Set(index uint32)

Set sets a big at index

func (*Bitfield) ToWireMessage

func (bf *Bitfield) ToWireMessage() common.WireMessage

ToWireMessage serializes to bittorrent wire message

func (*Bitfield) UnmarshalJSON

func (bf *Bitfield) UnmarshalJSON(data []byte) (err error)

UnmarshalJSON implements json.Marhsaller

func (*Bitfield) Unset

func (bf *Bitfield) Unset(index uint32)

Unset unsets a big at index

func (*Bitfield) XOR

func (bf *Bitfield) XOR(other *Bitfield) *Bitfield

XOR returns Bitfield with bitwise XOR applied from other Bitfield

func (*Bitfield) Zero

func (bf *Bitfield) Zero()

Zero sets all bits to zero

type Handshake

type Handshake struct {
	Reserved Reserved
	Infohash common.Infohash
	PeerID   common.PeerID
}

Handshake is a bittorrent protocol handshake info

func (*Handshake) FromBytes

func (h *Handshake) FromBytes(data []byte) (err error)

FromBytes parses bittorrent handshake from byteslice

func (*Handshake) Recv

func (h *Handshake) Recv(r io.Reader) (err error)

Recv reads handshake via reader

func (*Handshake) Send

func (h *Handshake) Send(w io.Writer) (err error)

Send sends handshake via writer

type Reserved

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

Reserved is reserved data in handshake

func (Reserved) Has

func (r Reserved) Has(bit ReservedBit) bool

Has returns true if reserved bit is set

func (*Reserved) Set

func (r *Reserved) Set(bit ReservedBit)

Set sets a reserved bit

type ReservedBit

type ReservedBit uint8

ReservedBit is a bit set in reserved data

Directories

Path Synopsis
swarm package provides compelete bittorrent client that tracks 1 swarm
swarm package provides compelete bittorrent client that tracks 1 swarm

Jump to

Keyboard shortcuts

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