Documentation ¶
Index ¶
- Constants
- func GetNodeAddrsCompactMarshaler(nas []krpc.NodeAddr, family AddrFamily) encoding.BinaryMarshaler
- func Read(r io.Reader, data interface{}) error
- func Write(w io.Writer, data interface{}) error
- type Action
- type AddrFamily
- type AnnounceEvent
- type AnnounceRequest
- type AnnounceResponseHeader
- type AnnounceResponsePeers
- type Client
- type ConnClient
- type ConnectionId
- type ConnectionRequest
- type ConnectionResponse
- type DispatchedResponse
- type Dispatcher
- type ErrorResponse
- type InfoHash
- type NewConnClientOpts
- type Options
- type RequestHeader
- type ResponseHeader
- type ScrapeInfohashResult
- type ScrapeRequest
- type ScrapeResponse
- type Transaction
- type TransactionId
- type TransactionResponseHandler
Constants ¶
View Source
const ( AddrFamilyIpv4 = iota + 1 AddrFamilyIpv6 )
View Source
const ConnectRequestConnectionId = 0x41727101980
View Source
const ConnectionIdMissmatchNul = "Connection ID missmatch.\x00"
Variables ¶
This section is empty.
Functions ¶
func GetNodeAddrsCompactMarshaler ¶
func GetNodeAddrsCompactMarshaler(nas []krpc.NodeAddr, family AddrFamily) encoding.BinaryMarshaler
Returns a marshaler for the given node addrs for the specified family.
Types ¶
type AnnounceEvent ¶
type AnnounceEvent int32
func (AnnounceEvent) String ¶
func (e AnnounceEvent) String() string
func (*AnnounceEvent) UnmarshalText ¶
func (me *AnnounceEvent) UnmarshalText(text []byte) error
type AnnounceRequest ¶
type AnnounceRequest struct { InfoHash [20]byte PeerId [20]byte Downloaded int64 Left int64 // If less than 0, math.MaxInt64 will be used for HTTP trackers instead. Uploaded int64 // Apparently this is optional. None can be used for announces done at // regular intervals. Event AnnounceEvent IPAddress uint32 Key int32 NumWant int32 // How many peer addresses are desired. -1 for default. Port uint16 } // 82 bytes
Marshalled as binary by the UDP client, so be careful making changes.
type AnnounceResponseHeader ¶
type AnnounceResponsePeers ¶
type AnnounceResponsePeers interface { encoding.BinaryUnmarshaler NodeAddrs() []krpc.NodeAddr }
type Client ¶
type Client struct { Dispatcher *Dispatcher Writer io.Writer // contains filtered or unexported fields }
Client interacts with UDP trackers via its Writer and Dispatcher. It has no knowledge of connection specifics.
func (*Client) Announce ¶
func (cl *Client) Announce( ctx context.Context, req AnnounceRequest, opts Options, ipv6 func(net.Addr) bool, ) ( respHdr AnnounceResponseHeader, peers AnnounceResponsePeers, err error, )
type ConnClient ¶
type ConnClient struct { Client Client // contains filtered or unexported fields }
Manages a Client with a specific connection.
func NewConnClient ¶
func NewConnClient(opts NewConnClientOpts) (cc *ConnClient, err error)
func (*ConnClient) Announce ¶
func (cc *ConnClient) Announce( ctx context.Context, req AnnounceRequest, opts Options, ) ( h AnnounceResponseHeader, nas AnnounceResponsePeers, err error, )
func (*ConnClient) Close ¶
func (cc *ConnClient) Close() error
func (*ConnClient) LocalAddr ¶
func (cc *ConnClient) LocalAddr() net.Addr
type ConnectionId ¶
type ConnectionId = uint64
type ConnectionRequest ¶
type ConnectionRequest struct { ConnectionId ConnectionId Action Action TransactionId TransactionId }
type ConnectionResponse ¶
type ConnectionResponse struct {
ConnectionId ConnectionId
}
type DispatchedResponse ¶
type DispatchedResponse struct { Header ResponseHeader // Response payload, after the header. Body []byte // Response source address Addr net.Addr }
type Dispatcher ¶
type Dispatcher struct {
// contains filtered or unexported fields
}
Maintains a mapping of transaction IDs to handlers.
func (*Dispatcher) Dispatch ¶
func (me *Dispatcher) Dispatch(b []byte, addr net.Addr) error
The caller owns b.
func (*Dispatcher) NewTransaction ¶
func (me *Dispatcher) NewTransaction(h TransactionResponseHandler) Transaction
type ErrorResponse ¶
type ErrorResponse struct {
Message string
}
func (ErrorResponse) Error ¶
func (me ErrorResponse) Error() string
type NewConnClientOpts ¶
type NewConnClientOpts struct { // The network to operate to use, such as "udp4", "udp", "udp6". Network string // Tracker address Host string // If non-nil, forces either IPv4 or IPv6 in the UDP tracker wire protocol. Ipv6 *bool // Logger to use for internal errors. Logger log.Logger // Custom function to use as a substitute for net.ListenPacket ListenPacket listenPacketFunc }
type RequestHeader ¶
type RequestHeader struct { ConnectionId ConnectionId Action Action TransactionId TransactionId } // 16 bytes
type ResponseHeader ¶
type ResponseHeader struct { Action Action TransactionId TransactionId }
type ScrapeInfohashResult ¶
type ScrapeInfohashResult struct { // I'm not sure why the fields are named differently for HTTP scrapes. // https://www.bittorrent.org/beps/bep_0048.html Seeders int32 `bencode:"complete"` Completed int32 `bencode:"downloaded"` Leechers int32 `bencode:"incomplete"` }
type ScrapeRequest ¶
type ScrapeRequest []InfoHash
type ScrapeResponse ¶
type ScrapeResponse []ScrapeInfohashResult
type Transaction ¶
type Transaction struct {
// contains filtered or unexported fields
}
func (*Transaction) End ¶
func (t *Transaction) End()
func (*Transaction) Id ¶
func (t *Transaction) Id() TransactionId
type TransactionId ¶
type TransactionId = int32
func RandomTransactionId ¶
func RandomTransactionId() TransactionId
type TransactionResponseHandler ¶
type TransactionResponseHandler func(dr DispatchedResponse)
Source Files ¶
Click to show internal directories.
Click to hide internal directories.