protocol

package
v0.0.0-...-1538d9d Latest Latest
Warning

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

Go to latest
Published: Mar 28, 2021 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

View Source
const (
	HaveRequest = iota
	HaveResponse
)
View Source
const (
	FileTransferProtocol = "/p2p/files/0.0.0"
	HandshakeProtocol    = "/p2p/handshake/0.0.0"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type DataExchange

type DataExchange struct {
	File   storage.FileHash
	Chunks []storage.Chunk
}

type Datagram

type Datagram struct {
	Msgs []Msg
}

Datagram holds a protocol datagram

func NewDataGram

func NewDataGram(m ...Msg) *Datagram

type HaveMsg

type HaveMsg struct {
	File     storage.FileHash
	Type     int
	FileSize int
	Chunks   []storage.ChunkID
}

HaveMsg holds a have message storage payload

type Msg

type Msg struct {
	Op   Opcode
	Data MsgData
}

Msg holds a protocol message

func (*Msg) HandleDataExchange

func (m *Msg) HandleDataExchange(pStorage storage.LocalStorage) error

func (*Msg) HandleHave

func (m *Msg) HandleHave(pid PeerID, lStorage storage.LocalStorage, pStorage storage.PeerStorage) (*Datagram, error)

func (*Msg) HandleRequest

func (m *Msg) HandleRequest(pStorage storage.LocalStorage) (*Datagram, error)

func (*Msg) MarshalJSON

func (m *Msg) MarshalJSON() ([]byte, error)

Encode handles the serializing of a message.

See note above Decode for the reason for the custom Encode

func (*Msg) UnmarshalJSON

func (m *Msg) UnmarshalJSON(b []byte) error

Decode handles the deserializing of a message.

We can't get away with off-the-shelf JSON, because we're using an interface type for MsgData, which causes problems on the decode side.

type MsgData

type MsgData interface{}

MsgData holds the storage payload of a message

type MsgError

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

MsgError is an error that happens while handling an incoming message

func (MsgError) Error

func (e MsgError) Error() string

type Opcode

type Opcode uint8

Opcode identifies the type of message

const (
	Handshake Opcode = 0
	Data      Opcode = 1
	Have      Opcode = 3
	Request   Opcode = 8
	Error     Opcode = 255
)

type PeerID

type PeerID interface {
	String() string
}

PeerID identifies a peer To avoid cycle Import

type Protocol

type Protocol interface {
	HandleDatagram(d *Datagram, id PeerID)
	SetDatagramSender(f func(Datagram, PeerID) error)
}

type RequestChunks

type RequestChunks struct {
	File storage.FileHash
	IDs  []storage.ChunkID
}

RequestChunks holds a have message storage payload

func (RequestChunks) String

func (c RequestChunks) String() string

Jump to

Keyboard shortcuts

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