Help us shape the future of Go! Take the 2026 Go Developer Survey

msg

package
v1.3.98 Latest Latest
Warning

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

Go to latest
Published: Sep 30, 2026 License: AGPL-3.0 Imports: 5 Imported by: 0

Documentation

Overview

Package msg pkg/cxo/node/msg/msg.go c2-net-cxo

Index

Constants

View Source
const (
	PingType = 1 + iota // 1
	PongType            // 2

	SynType // 3
	AckType // 4

	OkType  // 5
	ErrType // 6

	SubType   // 7
	UnsubType // 8

	RqListType // 9
	ListType   // 10

	RootType // 11

	RqObjectType // 12
	ObjectType   // 13

	RqPreviewType // 14

	RqPeersType // 15
	PeersType   // 16
)

Types

View Source
const Version uint16 = 3

Version is current protocol version

Variables

View Source
var (
	// ErrEmptyMessage occurs when you
	// try to Decode an empty slice
	ErrEmptyMessage = errors.New("empty message")
	// ErrIncomplieDecoding occurs when incoming message
	// decoded correctly but the decoding doesn't use
	// entire encoded message
	ErrIncomplieDecoding = errors.New("incomplete decoding")
)

Functions

This section is empty.

Types

type Ack

type Ack struct {
	NodeID cipher.PubKey // node id
}

An Ack is response for the Syn if handshake has been accepted. Otherwise, the Err returned

func (*Ack) Encode

func (a *Ack) Encode() []byte

Encode the Ack

func (*Ack) Type

func (*Ack) Type() Type

Type implements Msg interface

type Err

type Err struct {
	Err string // reason
}

A Err is common error reply

func (*Err) Encode

func (e *Err) Encode() []byte

Encode the Err

func (*Err) Type

func (*Err) Type() Type

Type implements Msg interface

type InvalidTypeError

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

An InvalidTypeError represents decoding error when incoming message is malformed and its type invalid

func (InvalidTypeError) Error

func (e InvalidTypeError) Error() string

Error implements builting error interface

func (InvalidTypeError) Type

func (e InvalidTypeError) Type() Type

Type return Type which cause the error

type List

type List struct {
	Feeds []cipher.PubKey
}

A List is reply for RqList

func (*List) Encode

func (l *List) Encode() []byte

Encode the List

func (*List) Type

func (*List) Type() Type

Type implements Msg interface

type Msg

type Msg interface {
	Type() Type     // type of the message to encode
	Encode() []byte // encode the message to []byte prefixed with the Type
}

A Msg is common interface for CXO messages

func Decode

func Decode(p []byte) (msg Msg, err error)

Decode encoded Type-prefixed data to message. It can returns encoding errors or InvalidTypeError

type Object

type Object struct {
	Value []byte // encoded object in person
}

An Object reperesents encoded object

func (*Object) Encode

func (o *Object) Encode() []byte

Encode the Object

func (*Object) Type

func (*Object) Type() Type

Type implements Msg interface

type Ok

type Ok struct{}

An Ok is common success reply

func (*Ok) Encode

func (*Ok) Encode() []byte

Encode the Ok

func (*Ok) Type

func (*Ok) Type() Type

Type implements Msg interface

type PeerInfo

type PeerInfo struct {
	PubKey   cipher.PubKey
	Metadata []byte
	TCPAddr  string
	UDPAddr  string
}

PeerInfo contains information peer

type Peers

type Peers struct {
	Feed cipher.PubKey
	List []PeerInfo
}

Peers is reply to RqPeers

func (*Peers) Encode

func (ps *Peers) Encode() []byte

Encode the Peers

func (*Peers) Type

func (ps *Peers) Type() Type

Type implemensts Msg interface

type Ping

type Ping struct{}

A Ping messege

func (*Ping) Encode

func (*Ping) Encode() []byte

Encode the Ping

func (*Ping) Type

func (*Ping) Type() Type

Type implements Msg interface

type Pong

type Pong struct{}

A Pong messege

func (*Pong) Encode

func (*Pong) Encode() []byte

Encode the Pong

func (*Pong) Type

func (*Pong) Type() Type

Type implements Msg interface

type Root

type Root struct {
	Feed  cipher.PubKey // feed }
	Nonce uint64        // head } Root selector
	Seq   uint64        // seq  }

	Value []byte // encoded Root in person

	Sig cipher.Sig // signature
}

A Root sent from one node to another one to update root object of feed described in Feed field of the message

func (*Root) Encode

func (r *Root) Encode() []byte

Encode the Root

func (*Root) Type

func (*Root) Type() Type

Type implements Msg interface

type RqList

type RqList struct{}

A RqList is request of list of feeds

func (*RqList) Encode

func (*RqList) Encode() []byte

Encode the RqList

func (*RqList) Type

func (*RqList) Type() Type

Type implements Msg interface

type RqObject

type RqObject struct {
	Key cipher.SHA256 // request
}

A RqObject represents a Msg that request a data by hash

func (*RqObject) Encode

func (r *RqObject) Encode() []byte

Encode the RqObject

func (*RqObject) Type

func (*RqObject) Type() Type

Type implements Msg interface

type RqPeers

type RqPeers struct {
	Feed cipher.PubKey
}

RqPeers is request of peers

func (*RqPeers) Encode

func (r *RqPeers) Encode() []byte

Encode the RqPeers

func (*RqPeers) Type

func (r *RqPeers) Type() Type

Type implements Msg interface

type RqPreview

type RqPreview struct {
	Feed cipher.PubKey
}

RqPreview is request for feeds preview

func (*RqPreview) Encode

func (r *RqPreview) Encode() []byte

Encode the RqPreview

func (*RqPreview) Type

func (r *RqPreview) Type() Type

Type implements Msg interface

type Sub

type Sub struct {
	Feed cipher.PubKey
}

A Sub message is request for subscription

func (*Sub) Encode

func (s *Sub) Encode() []byte

Encode the Sub

func (*Sub) Type

func (*Sub) Type() Type

Type implements Msg interface

type Syn

type Syn struct {
	Protocol uint16
	NodeID   cipher.PubKey // node id
}

A Syn is handshake initiator message

func (*Syn) Encode

func (s *Syn) Encode() []byte

Encode the Syn

func (*Syn) Type

func (*Syn) Type() Type

Type implements Msg interface

type Type

type Type uint8

A Type represent msg prefix

func (Type) String

func (m Type) String() string

String implements fmt.Stringer interface

type Unsub

type Unsub struct {
	Feed cipher.PubKey
}

An Unsub used to notify remote peer about unsubscribing from a feed

func (*Unsub) Encode

func (u *Unsub) Encode() []byte

Encode the Unsub

func (*Unsub) Type

func (*Unsub) Type() Type

Type implements Msg interface

Jump to

Keyboard shortcuts

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