mainline

package
v0.6.1-0...-0e7be8e Latest Latest
Warning

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

Go to latest
Published: Jul 14, 2023 License: AGPL-3.0 Imports: 16 Imported by: 0

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 Message

type Message struct {
	// Query method (one of 4: "ping", "find_node", "get_peers", "announce_peer")
	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, info_hash []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

type Protocol

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

func NewProtocol

func NewProtocol(laddr *net.UDPAddr, 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.Addr)

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.Addr)
	OnFindNodeQuery              func(*Message, net.Addr)
	OnGetPeersQuery              func(*Message, net.Addr)
	OnAnnouncePeerQuery          func(*Message, net.Addr)
	OnGetPeersResponse           func(*Message, net.Addr)
	OnFindNodeResponse           func(*Message, net.Addr)
	OnPingORAnnouncePeerResponse func(*Message, net.Addr)
}

type QueryArguments

type QueryArguments struct {
	// ID of the quirying 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"`

	// 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 *net.UDPAddr, onMessage func(*Message, net.Addr)) *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.Addr)

type TrawlingResult

type TrawlingResult struct {
	InfoHash metainfo.Hash
	Peer     torrent.Peer
	PeerIP   net.IP
	PeerPort int
}

type TrawlingService

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

func NewTrawlingService

func NewTrawlingService(laddr *net.UDPAddr, eventHandlers TrawlingServiceEventHandlers) *TrawlingService

func (*TrawlingService) Start

func (s *TrawlingService) Start()

func (*TrawlingService) Terminate

func (s *TrawlingService) Terminate()

type TrawlingServiceEventHandlers

type TrawlingServiceEventHandlers struct {
	OnResult func(TrawlingResult)
}

Jump to

Keyboard shortcuts

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