message

package
v0.5.0 Latest Latest
Warning

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

Go to latest
Published: Feb 10, 2023 License: Apache-2.0, MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var MaxEntrySize = maxEntrySize()

Functions

func BlockPresenceSize

func BlockPresenceSize(c cid.Cid) int

Types

type BitSwapMessage

type BitSwapMessage interface {
	// Wantlist returns a slice of unique keys that represent data wanted by
	// the sender.
	Wantlist() []Entry

	// Blocks returns a slice of unique blocks.
	Blocks() []blocks.Block
	// BlockPresences returns the list of HAVE / DONT_HAVE in the message
	BlockPresences() []BlockPresence
	// Haves returns the Cids for each HAVE
	Haves() []cid.Cid
	// DontHaves returns the Cids for each DONT_HAVE
	DontHaves() []cid.Cid
	// PendingBytes returns the number of outstanding bytes of data that the
	// engine has yet to send to the client (because they didn't fit in this
	// message)
	PendingBytes() int32

	// AddEntry adds an entry to the Wantlist.
	AddEntry(key cid.Cid, priority int32, wantType pb.Message_Wantlist_WantType, sendDontHave bool) int

	// Cancel adds a CANCEL for the given CID to the message
	// Returns the size of the CANCEL entry in the protobuf
	Cancel(key cid.Cid) int

	// Remove removes any entries for the given CID. Useful when the want
	// status for the CID changes when preparing a message.
	Remove(key cid.Cid)

	// Empty indicates whether the message has any information
	Empty() bool
	// Size returns the size of the message in bytes
	Size() int

	// A full wantlist is an authoritative copy, a 'non-full' wantlist is a patch-set
	Full() bool

	// AddBlock adds a block to the message
	AddBlock(blocks.Block)
	// AddBlockPresence adds a HAVE / DONT_HAVE for the given Cid to the message
	AddBlockPresence(cid.Cid, pb.Message_BlockPresenceType)
	// AddHave adds a HAVE for the given Cid to the message
	AddHave(cid.Cid)
	// AddDontHave adds a DONT_HAVE for the given Cid to the message
	AddDontHave(cid.Cid)
	// SetPendingBytes sets the number of bytes of data that are yet to be sent
	// to the client (because they didn't fit in this message)
	SetPendingBytes(int32)
	Exportable

	Loggable() map[string]interface{}

	// Reset the values in the message back to defaults, so it can be reused
	Reset(bool)

	// Clone the message fields
	Clone() BitSwapMessage
}

BitSwapMessage is the basic interface for interacting building, encoding, and decoding messages sent on the BitSwap protocol.

func FromMsgReader

func FromMsgReader(r msgio.Reader) (BitSwapMessage, error)

FromPBReader generates a new Bitswap message from a gogo-protobuf reader

func FromNet

func FromNet(r io.Reader) (BitSwapMessage, error)

FromNet generates a new BitswapMessage from incoming data on an io.Reader.

func New

func New(full bool) BitSwapMessage

New returns a new, empty bitswap message

type BlockPresence

type BlockPresence struct {
	Cid  cid.Cid
	Type pb.Message_BlockPresenceType
}

BlockPresence represents a HAVE / DONT_HAVE for a given Cid

type Entry

type Entry struct {
	wantlist.Entry
	Cancel       bool
	SendDontHave bool
}

Entry is a wantlist entry in a Bitswap message, with flags indicating - whether message is a cancel - whether requester wants a DONT_HAVE message - whether requester wants a HAVE message (instead of the block)

func (*Entry) Size

func (e *Entry) Size() int

Get the size of the entry on the wire

func (*Entry) ToPB

func (e *Entry) ToPB() pb.Message_Wantlist_Entry

Get the entry in protobuf form

type Exportable

type Exportable interface {
	// Note that older Bitswap versions use a different wire format, so we need
	// to convert the message to the appropriate format depending on which
	// version of the protocol the remote peer supports.
	ToProtoV0() *pb.Message
	ToProtoV1() *pb.Message
	ToNetV0(w io.Writer) error
	ToNetV1(w io.Writer) error
}

Exportable is an interface for structures than can be encoded in a bitswap protobuf.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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