Documentation ¶
Index ¶
- Constants
- func CheckExtReserved(reserved uint64) bool
- func ReadMessage(reader io.Reader) ([]byte, error)
- func ReadMessageInto(reader io.Reader, buf *bytes.Buffer) error
- func ReadMessageWithLimit(reader io.Reader, limit uint32) ([]byte, error)
- func SetExtReserved(reserved *uint64)
- func WriteExtensionMessage(writer io.Writer, id byte, content []byte) error
- func WriteMessage(writer io.Writer, id byte, payload []byte) error
- type ExtHSGetter
- type ExtHSPutter
- type ExtMsgSender
- type ExtProtocol
- type Extension
- type FetchMetaExt
- func (fm *FetchMetaExt) AfterHandshake(hs ExtHSGetter, sender *ExtMsgSender) error
- func (fm *FetchMetaExt) BeforeHandshake(hs ExtHSPutter)
- func (fm *FetchMetaExt) CheckDone() bool
- func (fm *FetchMetaExt) FetchRawMeta() (RawMeta, error)
- func (fm *FetchMetaExt) HandleMessage(content []byte, sender *ExtMsgSender) error
- func (fm *FetchMetaExt) IsSupoort() bool
- func (fm *FetchMetaExt) MapKey() string
- func (fm *FetchMetaExt) Unsupport()
- type Meta
- type MetaOutline
- type RawMeta
- type Stream
- type TexExtension
- func (tex *TexExtension) AfterHandshake(hs ExtHSGetter, sender *ExtMsgSender) error
- func (tex *TexExtension) BeforeHandshake(hs ExtHSPutter)
- func (tex *TexExtension) HandleMessage(content []byte, sender *ExtMsgSender) error
- func (tex *TexExtension) IsSupoort() bool
- func (tex *TexExtension) MapKey() string
- func (tex *TexExtension) More() bool
- func (tex *TexExtension) TrackerList() []string
- func (tex *TexExtension) Unsupport()
Constants ¶
const ( // ExtID is extension message id. ExtID byte = 20 // ExtReserved is reserved field in handshake when peer wire ExtReserved = 0x100000 )
const (
// Protocol is "BitTorrent protocol"
Protocol = "BitTorrent protocol"
)
Variables ¶
This section is empty.
Functions ¶
func CheckExtReserved ¶
CheckExtReserved returns true if reserved support extension
func ReadMessage ¶
ReadMessage read a message from stream
func ReadMessageInto ¶
ReadMessageInto will reset the buffer and read message into it
func ReadMessageWithLimit ¶
ReadMessageWithLimit read a message from stream
func SetExtReserved ¶
func SetExtReserved(reserved *uint64)
SetExtReserved set extesntion reserved on handshake
func WriteExtensionMessage ¶
WriteExtensionMessage write extension message to writer
Types ¶
type ExtHSGetter ¶
type ExtHSGetter struct {
// contains filtered or unexported fields
}
ExtHSGetter can get entry from handshake.
func (*ExtHSGetter) Get ¶
func (g *ExtHSGetter) Get(k string, ptr interface{}) bool
Get entry from handshake
type ExtHSPutter ¶
type ExtHSPutter struct {
// contains filtered or unexported fields
}
ExtHSPutter only can put entry into handshake
func (*ExtHSPutter) Put ¶
func (p *ExtHSPutter) Put(k string, v interface{})
Put entry into handshake
type ExtMsgSender ¶
type ExtMsgSender struct {
// contains filtered or unexported fields
}
ExtMsgSender used for send extension message
func (*ExtMsgSender) SendBytes ¶
func (sender *ExtMsgSender) SendBytes(content []byte) error
SendBytes will send content
type ExtProtocol ¶
type ExtProtocol struct {
// contains filtered or unexported fields
}
ExtProtocol is extension center
func NewExtProtocol ¶
func NewExtProtocol(exts ...Extension) *ExtProtocol
NewExtProtocol returns a new extension center
func (*ExtProtocol) HandlePayload ¶
func (proto *ExtProtocol) HandlePayload(payload []byte, w io.Writer) error
HandlePayload handle extention message
func (*ExtProtocol) RegistExt ¶
func (proto *ExtProtocol) RegistExt(ext Extension)
RegistExt regists extension into center
func (*ExtProtocol) WriteHandshake ¶
func (proto *ExtProtocol) WriteHandshake(w io.Writer) error
WriteHandshake sends handshake
type Extension ¶
type Extension interface { MapKey() string BeforeHandshake(hs ExtHSPutter) // AfterHandshake will call after handsahke if peer support this extension AfterHandshake(hs ExtHSGetter, sender *ExtMsgSender) error // Unsupport will call after handshake if peer not support this extension. Unsupport() HandleMessage(content []byte, sender *ExtMsgSender) error }
Extension is extension
type FetchMetaExt ¶
type FetchMetaExt struct {
// contains filtered or unexported fields
}
FetchMetaExt is extension can fetch metadata
func NewFetchMetaExt ¶
func NewFetchMetaExt(infoHash string) *FetchMetaExt
NewFetchMetaExt returns a new FetchMetaExt
func (*FetchMetaExt) AfterHandshake ¶
func (fm *FetchMetaExt) AfterHandshake(hs ExtHSGetter, sender *ExtMsgSender) error
AfterHandshake implements Extension.AfterHandshake
func (*FetchMetaExt) BeforeHandshake ¶
func (fm *FetchMetaExt) BeforeHandshake(hs ExtHSPutter)
BeforeHandshake implements Extension.BeforeHandshake
func (*FetchMetaExt) CheckDone ¶
func (fm *FetchMetaExt) CheckDone() bool
CheckDone if download all pieces returns true else false
func (*FetchMetaExt) FetchRawMeta ¶
func (fm *FetchMetaExt) FetchRawMeta() (RawMeta, error)
FetchRawMeta get the raw metadata
func (*FetchMetaExt) HandleMessage ¶
func (fm *FetchMetaExt) HandleMessage(content []byte, sender *ExtMsgSender) error
HandleMessage implements Extension.HandleMessage
func (*FetchMetaExt) IsSupoort ¶
func (fm *FetchMetaExt) IsSupoort() bool
IsSupoort returns true if peer support this extension other false. Should use it after extesion handshake
func (*FetchMetaExt) MapKey ¶
func (fm *FetchMetaExt) MapKey() string
MapKey implements Extension.MapKey
func (*FetchMetaExt) Unsupport ¶
func (fm *FetchMetaExt) Unsupport()
Unsupport implements Extension.Unsupport
type Meta ¶
type Meta struct { Name string `bencode:"name"` Length *uint64 `bencode:"length,omitempty"` PieceLength uint `bencode:"piece length"` Pieces []byte `bencode:"pieces"` Files []struct { Path []string `bencode:"path"` Length uint64 `bencode:"length"` } `bencode:"files,omitempty"` }
Meta is meta
type MetaOutline ¶
MetaOutline is outline of metadata
type RawMeta ¶
type RawMeta bencode.RawMessage
RawMeta is raw metadata
func FetchMetadata ¶
FetchMetadata fetch metadata from host.
func (RawMeta) FillOutline ¶
func (rm RawMeta) FillOutline(mo MetaOutline) error
FillOutline can fill MetaOutline
type Stream ¶
type Stream interface { io.Writer io.Reader io.Closer Protocol() string Reserved() uint64 InfoHash() string PeerID() string }
Stream is a BitProtocol stream
type TexExtension ¶
type TexExtension struct {
// contains filtered or unexported fields
}
TexExtension is tracker exchange extension
func NewTexExtension ¶
func NewTexExtension(trlist []string) *TexExtension
NewTexExtension returns a new TexExtension
func (*TexExtension) AfterHandshake ¶
func (tex *TexExtension) AfterHandshake(hs ExtHSGetter, sender *ExtMsgSender) error
AfterHandshake will call after handsahke if peer support this extension
func (*TexExtension) BeforeHandshake ¶
func (tex *TexExtension) BeforeHandshake(hs ExtHSPutter)
BeforeHandshake implements Extension.BeforeHandshake
func (*TexExtension) HandleMessage ¶
func (tex *TexExtension) HandleMessage(content []byte, sender *ExtMsgSender) error
HandleMessage implements Extension.HandleMessage
func (*TexExtension) IsSupoort ¶
func (tex *TexExtension) IsSupoort() bool
IsSupoort returns true if peer support this extension other false. Should use it after extesion handshake
func (*TexExtension) MapKey ¶
func (tex *TexExtension) MapKey() string
MapKey implements Extension.MapKey
func (*TexExtension) More ¶
func (tex *TexExtension) More() bool
More returns peer have more tracker or not
func (*TexExtension) TrackerList ¶
func (tex *TexExtension) TrackerList() []string
TrackerList returns tracker list
func (*TexExtension) Unsupport ¶
func (tex *TexExtension) Unsupport()
Unsupport will call after handshake if peer not support this extension.