Documentation ¶
Overview ¶
Package common provides common data structures
Index ¶
- Constants
- Variables
- func ReadWireMessages(r io.Reader, f func(WireMessage) error, msg []byte) (err error)
- type Infohash
- type Peer
- type PeerID
- type PieceData
- type PieceRequest
- type WireMessage
- func (msg WireMessage) GetHave() (h uint32)
- func (msg WireMessage) GetPieceRequest() (req *PieceRequest)
- func (msg WireMessage) KeepAlive() bool
- func (msg WireMessage) Len() uint32
- func (msg WireMessage) MessageID() WireMessageType
- func (msg WireMessage) Payload() []byte
- func (msg *WireMessage) Reset()
- func (msg WireMessage) VisitPieceData(v func(*PieceData))
- type WireMessageType
Constants ¶
const BitField = WireMessageType(5)
BitField is messageid for bitfield message
const Cancel = WireMessageType(8)
Cancel is messageid for a Cancel message, used to cancel a pending request
const Choke = WireMessageType(0)
Chock is message id for choke message
const Extended = WireMessageType(20)
Extended is messageid for ExtendedOptions message
const Have = WireMessageType(4)
Have is messageid for have message
const Interested = WireMessageType(2)
Interested is messageid for interested message
const Invalid = WireMessageType(255)
special for invalid
const MaxWireMessageSize = 32 * 1024
const NotInterested = WireMessageType(3)
NotInterested is messageid for not-interested message
const Piece = WireMessageType(7)
Piece is messageid for response to Request message
const Request = WireMessageType(6)
Request is messageid for piece request message
const UnChoke = WireMessageType(1)
UnChoke is message id for unchoke message
Variables ¶
var ErrBadInfoHashLen = errors.New("bad infohash length")
ErrBadInfoHashLen is error indicating that the infohash is a bad size
var ErrBadMagnetURI = errors.New("bad magnet URI")
var ErrInvalidPiece = errors.New("invalid piece")
ErrInvalidPiece is an error for when a piece has invalid sha1sum
var ErrToBig = errors.New("message too big")
var KeepAlive = WireMessage([]byte{0, 0, 0, 0})
KeepAlive makes a WireMessage of size 0
Functions ¶
func ReadWireMessages ¶
read wire messages from reader and call a function on each it gets reads until reader is done
Types ¶
type Infohash ¶
type Infohash [20]byte
Infohash is a bittorrent infohash buffer
func DecodeInfohash ¶
DecodeInfohash decodes infohash buffer from hex string
type Peer ¶
type Peer struct { Compact i2p.Base32Addr `bencode:"-"` IP string `bencode:"ip"` Port int `bencode:"port"` ID PeerID `bencode:"peer id"` }
Peer provides info for a bittorrent swarm peer
type PeerID ¶
type PeerID [20]byte
PeerID is a buffer for bittorrent peerid
func GeneratePeerID ¶
func GeneratePeerID() (id PeerID)
GeneratePeerID generates a new peer id for XD
type PieceData ¶
PieceData is a bittorrent piece response
func (PieceData) ToWireMessage ¶
func (p PieceData) ToWireMessage() WireMessage
ToWireMessage serialize to BitTorrent wire message
type PieceRequest ¶
PieceRequest is a request for a bittorrent piece
func (PieceRequest) Cancel ¶
func (pc PieceRequest) Cancel() WireMessage
func (*PieceRequest) Copy ¶
func (pc *PieceRequest) Copy(r *PieceRequest)
func (*PieceRequest) Equals ¶
func (r *PieceRequest) Equals(other *PieceRequest) bool
func (*PieceRequest) Matches ¶
func (r *PieceRequest) Matches(d *PieceData) bool
return true if piecedata matches this piece request
func (PieceRequest) ToWireMessage ¶
func (req PieceRequest) ToWireMessage() WireMessage
ToWireMessage serialize to BitTorrent wire message
type WireMessage ¶
type WireMessage []byte
WireMessage is a serializable bittorrent wire message
func NewCancel ¶
func NewCancel(idx, offset, length uint32) WireMessage
func NewInterested ¶
func NewInterested() WireMessage
NewInterested creates a new Interested message
func NewNotInterested ¶
func NewNotInterested() WireMessage
NewNotInterested creates a new NotInterested message
func NewWireMessage ¶
func NewWireMessage(id WireMessageType, bodyParts ...[]byte) (msg WireMessage)
NewWireMessage creates new wire message with id and many byteslices for the body
func (WireMessage) GetHave ¶
func (msg WireMessage) GetHave() (h uint32)
GetHave gets the piece index of a have message
func (WireMessage) GetPieceRequest ¶
func (msg WireMessage) GetPieceRequest() (req *PieceRequest)
GetPieceRequest gets piece request from wire message
func (WireMessage) KeepAlive ¶
func (msg WireMessage) KeepAlive() bool
KeepAlive returns true if this message is a keepalive message
func (WireMessage) Len ¶
func (msg WireMessage) Len() uint32
Len returns the length of the body of this message
func (WireMessage) MessageID ¶
func (msg WireMessage) MessageID() WireMessageType
MessageID returns the id of this message
func (WireMessage) Payload ¶
func (msg WireMessage) Payload() []byte
Payload returns a byteslice for the body of this message
func (*WireMessage) Reset ¶
func (msg *WireMessage) Reset()
func (WireMessage) VisitPieceData ¶
func (msg WireMessage) VisitPieceData(v func(*PieceData))
VisitPieceData gets this wire message as a PieceData if applicable
type WireMessageType ¶
type WireMessageType byte
WireMessageType is type for wire message id
func (WireMessageType) Byte ¶
func (t WireMessageType) Byte() byte
func (WireMessageType) String ¶
func (t WireMessageType) String() string
String returns a string name of this wire message id