udp

package
v1.32.0 Latest Latest
Warning

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

Go to latest
Published: Sep 30, 2021 License: MPL-2.0 Imports: 14 Imported by: 13

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Read

func Read(r io.Reader, data interface{}) error

func Write

func Write(w io.Writer, data interface{}) error

Types

type Action

type Action int32
const (
	ActionConnect Action = iota
	ActionAnnounce
	ActionScrape
	ActionError

	ConnectRequestConnectionId = 0x41727101980
)

type AnnounceEvent

type AnnounceEvent int32

func (AnnounceEvent) String

func (e AnnounceEvent) String() string

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 AnnounceResponseHeader struct {
	Interval int32
	Leechers int32
	Seeders  int32
}

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
}

func (*Client) Announce

func (cl *Client) Announce(
	ctx context.Context, req AnnounceRequest, peers AnnounceResponsePeers, opts Options,
) (
	respHdr AnnounceResponseHeader, err error,
)

func (*Client) Scrape

func (cl *Client) Scrape(
	ctx context.Context, ihs []InfoHash,
) (
	out ScrapeResponse, err error,
)

type ConnClient

type ConnClient struct {
	Client Client
	// contains filtered or unexported fields
}

func NewConnClient

func NewConnClient(opts NewConnClientOpts) (cc *ConnClient, err error)

func (*ConnClient) Announce

func (c *ConnClient) Announce(
	ctx context.Context, req AnnounceRequest, opts Options,
) (
	h AnnounceResponseHeader, nas AnnounceResponsePeers, err error,
)

func (*ConnClient) Close

func (c *ConnClient) Close() error

type ConnectionId

type ConnectionId = int64

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
	Body   []byte
}

type Dispatcher

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

func (*Dispatcher) Dispatch

func (me *Dispatcher) Dispatch(b []byte) error

The caller owns b.

func (*Dispatcher) NewTransaction

func (me *Dispatcher) NewTransaction(h TransactionResponseHandler) Transaction

type InfoHash

type InfoHash = [20]byte

type NewConnClientOpts

type NewConnClientOpts struct {
	Network string
	Host    string
	Ipv6    *bool
}

type Options

type Options struct {
	RequestUri string
}

func (Options) Encode

func (opts Options) Encode() (ret []byte)

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 {
	Seeders   int32
	Completed int32
	Leechers  int32
}

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)

Jump to

Keyboard shortcuts

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