mainline

package
v0.11.0 Latest Latest
Warning

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

Go to latest
Published: Feb 22, 2020 License: AGPL-3.0 Imports: 15 Imported by: 2

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type CompactNodeInfo

type CompactNodeInfo struct {
	ID   []byte
	Addr net.UDPAddr
}

func UnmarshalCompactNodeInfos

func UnmarshalCompactNodeInfos(b []byte) (ret []CompactNodeInfo, err error)

func (CompactNodeInfo) MarshalBinary

func (cni CompactNodeInfo) MarshalBinary() []byte

func (*CompactNodeInfo) UnmarshalBinary

func (cni *CompactNodeInfo) UnmarshalBinary(b []byte) error

type CompactNodeInfos

type CompactNodeInfos []CompactNodeInfo

func (CompactNodeInfos) MarshalBencode

func (cnis CompactNodeInfos) MarshalBencode() ([]byte, error)

func (*CompactNodeInfos) UnmarshalBencode

func (cnis *CompactNodeInfos) UnmarshalBencode(b []byte) (err error)

This allows bencode.Unmarshal to do better than a string or []byte.

type CompactPeer

type CompactPeer struct {
	IP   net.IP
	Port int
}

Represents peer address in either IPv6 or IPv4 form.

func UnmarshalCompactPeers

func UnmarshalCompactPeers(b []byte) (ret []CompactPeer, err error)

func (CompactPeer) MarshalBencode

func (cp CompactPeer) MarshalBencode() (ret []byte, err error)

func (*CompactPeer) UnmarshalBencode

func (cp *CompactPeer) UnmarshalBencode(b []byte) (err error)

func (*CompactPeer) UnmarshalBinary

func (cp *CompactPeer) UnmarshalBinary(b []byte) error

type CompactPeers

type CompactPeers []CompactPeer

func (CompactPeers) MarshalBinary

func (cps CompactPeers) MarshalBinary() (ret []byte, err error)

func (*CompactPeers) UnmarshalBencode

func (cps *CompactPeers) UnmarshalBencode(b []byte) (err error)

This allows bencode.Unmarshal to do better than a string or []byte.

type Error

type Error struct {
	Code    int
	Message []byte
}

func (Error) MarshalBencode

func (e Error) MarshalBencode() ([]byte, error)

func (*Error) UnmarshalBencode

func (e *Error) UnmarshalBencode(b []byte) (err error)

type IndexingResult added in v0.8.0

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

func (IndexingResult) InfoHash added in v0.8.0

func (ir IndexingResult) InfoHash() [20]byte

func (IndexingResult) PeerAddrs added in v0.8.0

func (ir IndexingResult) PeerAddrs() []net.TCPAddr

type IndexingService added in v0.8.0

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

func NewIndexingService added in v0.8.0

func NewIndexingService(laddr string, interval time.Duration, maxNeighbors uint, eventHandlers IndexingServiceEventHandlers) *IndexingService

func (*IndexingService) Start added in v0.8.0

func (is *IndexingService) Start()

func (*IndexingService) Terminate added in v0.8.0

func (is *IndexingService) Terminate()

type IndexingServiceEventHandlers added in v0.8.0

type IndexingServiceEventHandlers struct {
	OnResult func(IndexingResult)
}

type Message

type Message struct {
	// Query method. One of 5:
	//   - "ping"
	//   - "find_node"
	//   - "get_peers"
	//   - "announce_peer"
	//   - "sample_infohashes" (added by BEP 51)
	Q string `bencode:"q,omitempty"`
	// named QueryArguments sent with a query
	A QueryArguments `bencode:"a,omitempty"`
	// required: transaction ID
	T []byte `bencode:"t"`
	// required: type of the message: q for QUERY, r for RESPONSE, e for ERROR
	Y string `bencode:"y"`
	// RESPONSE type only
	R ResponseValues `bencode:"r,omitempty"`
	// ERROR type only
	E Error `bencode:"e,omitempty"`
}

func NewAnnouncePeerQuery

func NewAnnouncePeerQuery(id []byte, implied_port bool, info_hash []byte, port uint16, token []byte) *Message

func NewAnnouncePeerResponse

func NewAnnouncePeerResponse(t []byte, id []byte) *Message

func NewFindNodeQuery

func NewFindNodeQuery(id []byte, target []byte) *Message

func NewFindNodeResponse

func NewFindNodeResponse(t []byte, id []byte, nodes []CompactNodeInfo) *Message

func NewGetPeersQuery

func NewGetPeersQuery(id []byte, infoHash []byte) *Message

func NewGetPeersResponseWithNodes

func NewGetPeersResponseWithNodes(t []byte, id []byte, token []byte, nodes []CompactNodeInfo) *Message

func NewGetPeersResponseWithValues

func NewGetPeersResponseWithValues(t []byte, id []byte, token []byte, values []CompactPeer) *Message

func NewPingQuery

func NewPingQuery(id []byte) *Message

func NewPingResponse

func NewPingResponse(t []byte, id []byte) *Message

func NewSampleInfohashesQuery added in v0.8.0

func NewSampleInfohashesQuery(id []byte, t []byte, target []byte) *Message

type Protocol

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

func NewProtocol

func NewProtocol(laddr string, eventHandlers ProtocolEventHandlers) (p *Protocol)

func (*Protocol) CalculateToken

func (p *Protocol) CalculateToken(address net.IP) []byte

func (*Protocol) SendMessage

func (p *Protocol) SendMessage(msg *Message, addr *net.UDPAddr)

func (*Protocol) Start

func (p *Protocol) Start()

func (*Protocol) Terminate

func (p *Protocol) Terminate()

func (*Protocol) VerifyToken

func (p *Protocol) VerifyToken(address net.IP, token []byte) bool

type ProtocolEventHandlers

type ProtocolEventHandlers struct {
	OnPingQuery                  func(*Message, *net.UDPAddr)
	OnFindNodeQuery              func(*Message, *net.UDPAddr)
	OnGetPeersQuery              func(*Message, *net.UDPAddr)
	OnAnnouncePeerQuery          func(*Message, *net.UDPAddr)
	OnGetPeersResponse           func(*Message, *net.UDPAddr)
	OnFindNodeResponse           func(*Message, *net.UDPAddr)
	OnPingORAnnouncePeerResponse func(*Message, *net.UDPAddr)

	// Added by BEP 51
	OnSampleInfohashesQuery    func(*Message, *net.UDPAddr)
	OnSampleInfohashesResponse func(*Message, *net.UDPAddr)

	OnCongestion func()
}

type QueryArguments

type QueryArguments struct {
	// ID of the querying Node
	ID []byte `bencode:"id"`
	// InfoHash of the torrent
	InfoHash []byte `bencode:"info_hash,omitempty"`
	// ID of the node sought
	Target []byte `bencode:"target,omitempty"`
	// Token received from an earlier get_peers query
	Token []byte `bencode:"token,omitempty"`
	// Senders torrent port
	Port int `bencode:"port,omitempty"`
	// Use senders apparent DHT port
	ImpliedPort int `bencode:"implied_port,omitempty"`

	// Indicates whether the querying node is seeding the torrent it announces.
	// Defined in BEP 33 "DHT Scrapes" for `announce_peer` queries.
	Seed int `bencode:"seed,omitempty"`

	// If 1, then the responding node should try to fill the `values` list with non-seed items on a
	// best-effort basis."
	// Defined in BEP 33 "DHT Scrapes" for `get_peers` queries.
	NoSeed int `bencode:"noseed,omitempty"`
	// If 1, then the responding node should add two fields to the "r" dictionary in the response:
	//   - `BFsd`: Bloom Filter (256 bytes) representing all stored seeds for that infohash
	//   - `BFpe`: Bloom Filter (256 bytes) representing all stored peers (leeches) for that
	//             infohash
	// Defined in BEP 33 "DHT Scrapes" for `get_peers` queries.
	Scrape int `bencode:"noseed,omitempty"`
}

type ResponseValues

type ResponseValues struct {
	// ID of the querying node
	ID []byte `bencode:"id"`
	// K closest nodes to the requested target
	Nodes CompactNodeInfos `bencode:"nodes,omitempty"`
	// Token for future announce_peer
	Token []byte `bencode:"token,omitempty"`
	// Torrent peers
	Values []CompactPeer `bencode:"values,omitempty"`

	// The subset refresh interval in seconds. Added by BEP 51.
	Interval int `bencode:"interval,omitempty"`
	// Number of infohashes in storage. Added by BEP 51.
	Num int `bencode:"num,omitempty"`
	// Subset of stored infohashes, N × 20 bytes. Added by BEP 51.
	Samples []byte `bencode:"samples,omitempty"`

	// If `scrape` is set to 1 in the `get_peers` query then the responding node should add the
	// below two fields to the "r" dictionary in the response:
	// Defined in BEP 33 "DHT Scrapes" for responses to `get_peers` queries.
	// Bloom Filter (256 bytes) representing all stored seeds for that infohash:
	BFsd *bloom.BloomFilter `bencode:"BFsd,omitempty"`
	// Bloom Filter (256 bytes) representing all stored peers (leeches) for that infohash:
	BFpe *bloom.BloomFilter `bencode:"BFpe,omitempty"`
}

type Transport

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

func NewTransport

func NewTransport(laddr string, onMessage func(*Message, *net.UDPAddr), onCongestion func()) *Transport

func (*Transport) Start

func (t *Transport) Start()

func (*Transport) Terminate

func (t *Transport) Terminate()

func (*Transport) WriteMessages

func (t *Transport) WriteMessages(msg *Message, addr *net.UDPAddr)

Jump to

Keyboard shortcuts

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