Documentation ¶
Index ¶
- Constants
- type CompactIp
- type Decoder
- type ExtendedHandshakeMessage
- type ExtensionBit
- type ExtensionName
- type ExtensionNumber
- type HandshakeResult
- type Integer
- type Message
- type MessageType
- type PeerExtensionBits
- func (pex PeerExtensionBits) GetBit(bit ExtensionBit) bool
- func (pex *PeerExtensionBits) SetBit(bit ExtensionBit, on bool)
- func (me 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 ¶
View Source
const ( ExtensionBitDHT = 0 // http://www.bittorrent.org/beps/bep_0005.html ExtensionBitExtended = 20 // http://www.bittorrent.org/beps/bep_0010.html ExtensionBitFast = 2 // http://www.bittorrent.org/beps/bep_0006.html )
View Source
const ( HandshakeExtendedID = 0 RequestMetadataExtensionMsgType = 0 DataMetadataExtensionMsgType = 1 RejectMetadataExtensionMsgType = 2 )
View Source
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 ExtendedHandshakeMessage ¶
type ExtendedHandshakeMessage struct { M map[ExtensionName]ExtensionNumber `bencode:"m"` V string `bencode:"v,omitempty"` Reqq int `bencode:"reqq,omitempty"` Encryption bool `bencode:"e,omitempty"` // 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 ExtensionBit ¶
type ExtensionBit uint
type ExtensionName ¶
type ExtensionName string
http://www.bittorrent.org/beps/bep_0010.html
const ( // http://www.bittorrent.org/beps/bep_0011.html ExtensionNamePex ExtensionName = "ut_pex" // http://bittorrent.org/beps/bep_0009.html. Note that there's an // LT_metadata, but I've never implemented it. ExtensionNameMetadata = "ut_metadata" )
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 uint32
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 (Message) MarshalBinary ¶
func (Message) MustMarshalBinary ¶
func (Message) RequestSpec ¶
func (msg Message) RequestSpec() (ret RequestSpec)
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
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 (me 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 ¶
func (*PexMsg) Message ¶
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
Click to show internal directories.
Click to hide internal directories.