Documentation ¶
Index ¶
- Constants
- type CompactIp
- type Decoder
- type ExtendedHandshakeMessage
- type ExtendedMetadataRequestMsg
- type ExtendedMetadataRequestMsgType
- type ExtensionBit
- type ExtensionName
- type ExtensionNumber
- type HandshakeResult
- type Integer
- type IntegerKind
- type Message
- type MessageType
- type PeerExtensionBits
- func (pex PeerExtensionBits) GetBit(bit ExtensionBit) bool
- func (pex *PeerExtensionBits) SetBit(bit ExtensionBit, on bool)
- func (pex PeerExtensionBits) String() string
- func (pex PeerExtensionBits) SupportsDHT() bool
- func (pex PeerExtensionBits) SupportsExtended() bool
- func (pex PeerExtensionBits) SupportsFast() bool
- type PexMsg
- type PexPeerFlags
- type RequestSpec
Constants ¶
const ( // http://www.bittorrent.org/beps/bep_0011.html ExtensionNamePex ExtensionName = "ut_pex" ExtensionDeleteNumber ExtensionNumber = 0 )
const ( ExtensionBitDht = 0 // http://www.bittorrent.org/beps/bep_0005.html ExtensionBitFast = 2 // http://www.bittorrent.org/beps/bep_0006.html ExtensionBitV2 = 7 // "Hybrid torrent legacy to v2 upgrade" ExtensionBitAzureusExtensionNegotiation1 = 16 ExtensionBitAzureusExtensionNegotiation2 = 17 // LibTorrent Extension Protocol, http://www.bittorrent.org/beps/bep_0010.html ExtensionBitLtep = 20 // https://wiki.theory.org/BitTorrent_Location-aware_Protocol_1 ExtensionBitLocationAwareProtocol = 43 ExtensionBitAzureusMessagingProtocol = 63 // https://www.bittorrent.org/beps/bep_0004.html )
https://www.bittorrent.org/beps/bep_0004.html https://wiki.theory.org/BitTorrentSpecification.html#Reserved_Bytes
const ( // http://bittorrent.org/beps/bep_0009.html. Note that there's an // LT_metadata, but I've never implemented it. ExtensionNameMetadata = "ut_metadata" )
const IntegerMax = math.MaxUint32
const (
Protocol = "\x13BitTorrent protocol"
)
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type CompactIp ¶
Marshals to the smallest compact byte representation.
func (CompactIp) MarshalBencode ¶
type Decoder ¶
type Decoder struct { R *bufio.Reader // This must return *[]byte where the slices can fit data for piece messages. I think we store // *[]byte in the pool to avoid an extra allocation every time we put the slice back into the // pool. The chunk size should not change for the life of the decoder. Pool *sync.Pool MaxLength Integer // TODO: Should this include the length header or not? }
type ExtendedHandshakeMessage ¶
type ExtendedHandshakeMessage struct { M map[ExtensionName]ExtensionNumber `bencode:"m"` V string `bencode:"v,omitempty"` Reqq int `bencode:"reqq,omitempty"` // The only mention of this I can find is in https://www.bittorrent.org/beps/bep_0011.html // for bit 0x01. Encryption bool `bencode:"e"` // BEP 9 MetadataSize int `bencode:"metadata_size,omitempty"` // The local client port. It would be redundant for the receiving side of // a connection to send this. Port int `bencode:"p,omitempty"` YourIp CompactIp `bencode:"yourip,omitempty"` Ipv4 CompactIp `bencode:"ipv4,omitempty"` Ipv6 net.IP `bencode:"ipv6,omitempty"` }
type ExtendedMetadataRequestMsg ¶ added in v1.29.0
type ExtendedMetadataRequestMsg struct { Piece int `bencode:"piece"` TotalSize int `bencode:"total_size"` Type ExtendedMetadataRequestMsgType `bencode:"msg_type"` }
func (ExtendedMetadataRequestMsg) PieceSize ¶ added in v1.29.0
func (me ExtendedMetadataRequestMsg) PieceSize() int
Returns the expected piece size for this request message. This is needed to determine the offset into an extension message payload that the request metadata piece data starts.
type ExtendedMetadataRequestMsgType ¶ added in v1.29.0
type ExtendedMetadataRequestMsgType int
const ( HandshakeExtendedID = 0 RequestMetadataExtensionMsgType ExtendedMetadataRequestMsgType = 0 DataMetadataExtensionMsgType ExtendedMetadataRequestMsgType = 1 RejectMetadataExtensionMsgType ExtendedMetadataRequestMsgType = 2 )
type ExtensionBit ¶
type ExtensionBit uint
type ExtensionNumber ¶
type ExtensionNumber int
http://www.bittorrent.org/beps/bep_0010.html
func (*ExtensionNumber) UnmarshalBinary ¶ added in v1.34.0
func (me *ExtensionNumber) UnmarshalBinary(b []byte) error
type HandshakeResult ¶
type HandshakeResult struct { PeerExtensionBits PeerID [20]byte metainfo.Hash }
func Handshake ¶
func Handshake( sock io.ReadWriter, ih *metainfo.Hash, peerID [20]byte, extensions PeerExtensionBits, ) ( res HandshakeResult, err error, )
ih is nil if we expect the peer to declare the InfoHash, such as when the peer initiated the connection. Returns ok if the Handshake was successful, and err if there was an unexpected condition other than the peer simply abandoning the Handshake.
type Integer ¶
type Integer IntegerKind
func (*Integer) UnmarshalBinary ¶ added in v1.34.0
type IntegerKind ¶ added in v1.48.1
type IntegerKind = uint32
An alias for the underlying type of Integer. This is needed for fuzzing.
type Message ¶
type Message struct { Keepalive bool Type MessageType Index, Begin, Length Integer Piece []byte Bitfield []bool ExtendedID ExtensionNumber ExtendedPayload []byte Port uint16 }
This is a lazy union representing all the possible fields for messages. Go doesn't have ADTs, and I didn't choose to use type-assertions.
func MakeCancelMessage ¶
func MetadataExtensionRequestMsg ¶ added in v1.29.0
func MetadataExtensionRequestMsg(peerMetadataExtensionId ExtensionNumber, piece int) Message
func (Message) MarshalBinary ¶
func (Message) MustMarshalBinary ¶
func (Message) RequestSpec ¶
func (msg Message) RequestSpec() (ret RequestSpec)
func (*Message) UnmarshalBinary ¶ added in v1.34.0
type MessageType ¶
type MessageType byte
const ( // BEP 3 Choke MessageType = 0 Unchoke MessageType = 1 Interested MessageType = 2 NotInterested MessageType = 3 Have MessageType = 4 Bitfield MessageType = 5 Request MessageType = 6 Piece MessageType = 7 Cancel MessageType = 8 // BEP 5 Port MessageType = 9 // BEP 6 - Fast extension Suggest MessageType = 0x0d // 13 HaveAll MessageType = 0x0e // 14 HaveNone MessageType = 0x0f // 15 Reject MessageType = 0x10 // 16 AllowedFast MessageType = 0x11 // 17 // BEP 10 Extended MessageType = 20 )
func (MessageType) FastExtension ¶
func (mt MessageType) FastExtension() bool
func (MessageType) String ¶
func (i MessageType) String() string
func (*MessageType) UnmarshalBinary ¶ added in v1.34.0
func (mt *MessageType) UnmarshalBinary(b []byte) error
type PeerExtensionBits ¶
type PeerExtensionBits [8]byte
func NewPeerExtensionBytes ¶
func NewPeerExtensionBytes(bits ...ExtensionBit) (ret PeerExtensionBits)
func (PeerExtensionBits) GetBit ¶
func (pex PeerExtensionBits) GetBit(bit ExtensionBit) bool
func (*PeerExtensionBits) SetBit ¶
func (pex *PeerExtensionBits) SetBit(bit ExtensionBit, on bool)
func (PeerExtensionBits) String ¶
func (pex PeerExtensionBits) String() string
func (PeerExtensionBits) SupportsDHT ¶
func (pex PeerExtensionBits) SupportsDHT() bool
func (PeerExtensionBits) SupportsExtended ¶
func (pex PeerExtensionBits) SupportsExtended() bool
func (PeerExtensionBits) SupportsFast ¶
func (pex PeerExtensionBits) SupportsFast() bool
type PexMsg ¶
type PexMsg struct { Added krpc.CompactIPv4NodeAddrs `bencode:"added"` AddedFlags []PexPeerFlags `bencode:"added.f"` Added6 krpc.CompactIPv6NodeAddrs `bencode:"added6"` Added6Flags []PexPeerFlags `bencode:"added6.f"` Dropped krpc.CompactIPv4NodeAddrs `bencode:"dropped"` Dropped6 krpc.CompactIPv6NodeAddrs `bencode:"dropped6"` }
func LoadPexMsg ¶ added in v1.16.0
Unmarshals and returns a PEX message.
func (*PexMsg) Message ¶ added in v1.16.0
func (m *PexMsg) Message(pexExtendedId ExtensionNumber) Message
type PexPeerFlags ¶
type PexPeerFlags byte
const ( PexPrefersEncryption PexPeerFlags = 1 << iota PexSeedUploadOnly PexSupportsUtp PexHolepunchSupport PexOutgoingConn )
func (PexPeerFlags) Get ¶
func (me PexPeerFlags) Get(f PexPeerFlags) bool
type RequestSpec ¶
type RequestSpec struct {
Index, Begin, Length Integer
}
func (RequestSpec) String ¶
func (me RequestSpec) String() string