Documentation ¶
Index ¶
- Variables
- type CompactNodeInfo
- type CompactNodeInfos
- type CompactPeer
- type CompactPeers
- type Error
- type IndexingResult
- type IndexingService
- type IndexingServiceEventHandlers
- type Message
- func NewAnnouncePeerQuery(id []byte, implied_port bool, info_hash []byte, port uint16, token []byte) *Message
- func NewAnnouncePeerResponse(t []byte, id []byte) *Message
- func NewFindNodeQuery(id []byte, target []byte) *Message
- func NewFindNodeResponse(t []byte, id []byte, nodes []CompactNodeInfo) *Message
- func NewGetPeersQuery(id []byte, infoHash []byte) *Message
- func NewGetPeersResponseWithNodes(t []byte, id []byte, token []byte, nodes []CompactNodeInfo) *Message
- func NewGetPeersResponseWithValues(t []byte, id []byte, token []byte, values []CompactPeer) *Message
- func NewPingQuery(id []byte) *Message
- func NewPingResponse(t []byte, id []byte) *Message
- func NewSampleInfohashesQuery(id []byte, t []byte, target []byte) *Message
- type Protocol
- type ProtocolEventHandlers
- type QueryArguments
- type ResponseValues
- type Transport
Constants ¶
This section is empty.
Variables ¶
View Source
var (
// Throttle rate that transport will have at Start time. Set <= 0 for unlimited requests.
DefaultThrottleRate = -1
)
View Source
var (
StatsPrintClock = 10 * time.Second
)
Functions ¶
This section is empty.
Types ¶
type CompactNodeInfo ¶
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 ¶
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 IndexingResult ¶
type IndexingResult struct {
// contains filtered or unexported fields
}
func (IndexingResult) InfoHash ¶
func (ir IndexingResult) InfoHash() [20]byte
func (IndexingResult) PeerAddrs ¶
func (ir IndexingResult) PeerAddrs() []net.TCPAddr
type IndexingService ¶
type IndexingService struct {
// contains filtered or unexported fields
}
func NewIndexingService ¶
func NewIndexingService(laddr string, interval time.Duration, maxNeighbors uint, eventHandlers IndexingServiceEventHandlers) *IndexingService
func (*IndexingService) Start ¶
func (is *IndexingService) Start()
func (*IndexingService) Terminate ¶
func (is *IndexingService) Terminate()
type IndexingServiceEventHandlers ¶
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 NewAnnouncePeerResponse ¶
func NewFindNodeQuery ¶
func NewFindNodeResponse ¶
func NewFindNodeResponse(t []byte, id []byte, nodes []CompactNodeInfo) *Message
func NewGetPeersQuery ¶
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 NewPingResponse ¶
type Protocol ¶
type Protocol struct {
// contains filtered or unexported fields
}
func NewProtocol ¶
func NewProtocol(laddr string, eventHandlers ProtocolEventHandlers) (p *Protocol)
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 (*Transport) SetThrottle ¶
Sets the throttle rate at runtime.
Click to show internal directories.
Click to hide internal directories.