peerprotocol

package
v1.11.1-alpha Latest Latest
Warning

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

Go to latest
Published: Oct 9, 2022 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// ExtensionIDHandshake is ID for extension handshake message.
	ExtensionIDHandshake = iota
	// ExtensionIDMetadata is ID for metadata extension messages.
	ExtensionIDMetadata
	// ExtensionIDPEX is ID for PEX extension messages.
	ExtensionIDPEX
)
View Source
const (
	// ExtensionKeyMetadata is the key for the metadata extension.
	ExtensionKeyMetadata = "ut_metadata"
	// ExtensionKeyPEX is the key for the PEX extension.
	ExtensionKeyPEX = "ut_pex"
)
View Source
const (
	// ExtensionMetadataMessageTypeRequest is the id of metadata message when requesting a piece.
	ExtensionMetadataMessageTypeRequest = iota
	// ExtensionMetadataMessageTypeData is the id of metadata message when sending the piece data.
	ExtensionMetadataMessageTypeData
	// ExtensionMetadataMessageTypeReject is the id of metadata message when rejecting a piece.
	ExtensionMetadataMessageTypeReject
)
View Source
const (
	Choke MessageID = iota
	Unchoke
	Interested
	NotInterested
	Have
	Bitfield
	Request
	Piece
	Cancel
	Port
	Suggest     = 13
	HaveAll     = 14
	HaveNone    = 15
	Reject      = 16
	AllowedFast = 17
	Extension   = 20
)

Peer message types

Variables

This section is empty.

Functions

This section is empty.

Types

type AllowedFastMessage

type AllowedFastMessage struct{ HaveMessage }

AllowedFastMessage is sent to tell a peer that it can download pieces regardless of choking status.

type BitfieldMessage

type BitfieldMessage struct {
	Data []byte
	// contains filtered or unexported fields
}

BitfieldMessage sent after the peer handshake to exchange piece availability information between peers.

func (BitfieldMessage) ID

func (m BitfieldMessage) ID() MessageID

ID returns the peer protocol message type.

func (*BitfieldMessage) Read added in v0.4.5

func (m *BitfieldMessage) Read(b []byte) (n int, err error)

Read message data into buffer b.

type CancelMessage

type CancelMessage struct{ RequestMessage }

CancelMessage is sent to peer to cancel previosly sent request.

func (CancelMessage) ID

func (m CancelMessage) ID() MessageID

ID returns the peer protocol message type.

type ChokeMessage

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

ChokeMessage is sent to peer that it should not request pieces.

func (ChokeMessage) ID

func (m ChokeMessage) ID() MessageID

ID returns the peer protocol message type.

func (ChokeMessage) Read added in v0.4.5

func (m ChokeMessage) Read(b []byte) (int, error)

type ExtensionHandshakeMessage

type ExtensionHandshakeMessage struct {
	M            map[string]uint8 `bencode:"m"`
	V            string           `bencode:"v"`
	YourIP       string           `bencode:"yourip,omitempty"`
	MetadataSize int              `bencode:"metadata_size,omitempty"`
	RequestQueue int              `bencode:"reqq"`
}

ExtensionHandshakeMessage contains the information to do the extension handshake.

func NewExtensionHandshake

func NewExtensionHandshake(metadataSize uint32, version string, yourip net.IP, requestQueueLength int) ExtensionHandshakeMessage

NewExtensionHandshake returns a new ExtensionHandshakeMessage by filling the struct with given values.

type ExtensionMessage

type ExtensionMessage struct {
	ExtendedMessageID uint8
	Payload           interface{}
}

ExtensionMessage is extension to BitTorrent protocol.

func (ExtensionMessage) ID

func (m ExtensionMessage) ID() MessageID

ID returns the type of a peer message.

func (ExtensionMessage) Read added in v0.4.5

func (m ExtensionMessage) Read([]byte) (int, error)

Read extension message bytes.

func (*ExtensionMessage) UnmarshalBinary

func (m *ExtensionMessage) UnmarshalBinary(data []byte) error

UnmarshalBinary parses extension message.

func (ExtensionMessage) WriteTo added in v0.4.4

func (m ExtensionMessage) WriteTo(w io.Writer) (n int64, err error)

WriteTo writes the bytes into io.Writer.

type ExtensionMetadataMessage

type ExtensionMetadataMessage struct {
	Type      int    `bencode:"msg_type"`
	Piece     uint32 `bencode:"piece"`
	TotalSize int    `bencode:"total_size,omitempty"`
	Data      []byte `bencode:"-"`
}

ExtensionMetadataMessage is the message for the Metadata extension.

type ExtensionPEXMessage

type ExtensionPEXMessage struct {
	Added   string `bencode:"added"`
	Dropped string `bencode:"dropped"`
}

ExtensionPEXMessage is the message for the PEX extension.

type HaveAllMessage

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

HaveAllMessage can be sent to peer to indicate that we are a seed for this torrent.

func (HaveAllMessage) ID

func (m HaveAllMessage) ID() MessageID

ID returns the peer protocol message type.

func (HaveAllMessage) Read added in v0.4.5

func (m HaveAllMessage) Read(b []byte) (int, error)

type HaveMessage

type HaveMessage struct {
	Index uint32
}

HaveMessage indicates a peer has the piece with index.

func (HaveMessage) ID

func (m HaveMessage) ID() MessageID

ID returns the peer protocol message type.

func (HaveMessage) Read added in v0.4.5

func (m HaveMessage) Read(b []byte) (int, error)

type HaveNoneMessage

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

HaveNoneMessage is sent to peer to tell that we don't have any pieces.

func (HaveNoneMessage) ID

func (m HaveNoneMessage) ID() MessageID

ID returns the peer protocol message type.

func (HaveNoneMessage) Read added in v0.4.5

func (m HaveNoneMessage) Read(b []byte) (int, error)

type InterestedMessage

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

InterestedMessage is sent to peer that we want to request pieces if you unchoke us.

func (InterestedMessage) ID

ID returns the peer protocol message type.

func (InterestedMessage) Read added in v0.4.5

func (m InterestedMessage) Read(b []byte) (int, error)

type Message

type Message interface {
	io.Reader
	ID() MessageID
}

Message is a Peer message of BitTorrent protocol.

type MessageID

type MessageID uint8

MessageID is identifier for messages sent between peers.

func (MessageID) String

func (m MessageID) String() string

type NotInterestedMessage

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

NotInterestedMessage is sent to peer that we don't want any peer from you.

func (NotInterestedMessage) ID

ID returns the peer protocol message type.

func (NotInterestedMessage) Read added in v0.4.5

func (m NotInterestedMessage) Read(b []byte) (int, error)

type PieceMessage

type PieceMessage struct {
	Index, Begin uint32
}

PieceMessage is sent when a peer wants to upload piece data.

func (PieceMessage) ID

func (m PieceMessage) ID() MessageID

ID returns the peer protocol message type.

func (PieceMessage) Read added in v0.4.5

func (m PieceMessage) Read(b []byte) (int, error)

Read message data into buffer b.

type PortMessage added in v0.8.0

type PortMessage struct {
	Port uint16
}

PortMessage is sent to announce the UDP port number of DHT node run by the peer.

func (PortMessage) ID added in v0.8.0

func (m PortMessage) ID() MessageID

ID returns the peer protocol message type.

func (PortMessage) Read added in v0.8.0

func (m PortMessage) Read(b []byte) (n int, err error)

Read message data into buffer b.

type RejectMessage

type RejectMessage struct{ RequestMessage }

RejectMessage is sent to peer to tell that we are rejecting a request from you.

func (RejectMessage) ID

func (m RejectMessage) ID() MessageID

ID returns the peer protocol message type.

type RequestMessage

type RequestMessage struct {
	Index, Begin, Length uint32
}

RequestMessage is sent when a peer needs a certain piece.

func (RequestMessage) ID

func (m RequestMessage) ID() MessageID

ID returns the peer protocol message type.

func (RequestMessage) Read added in v0.4.5

func (m RequestMessage) Read(b []byte) (int, error)

Read message data into buffer b.

type UnchokeMessage

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

UnchokeMessage is sent to peer that it can request pieces.

func (UnchokeMessage) ID

func (m UnchokeMessage) ID() MessageID

ID returns the peer protocol message type.

func (UnchokeMessage) Read added in v0.4.5

func (m UnchokeMessage) Read(b []byte) (int, error)

Jump to

Keyboard shortcuts

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