meshcore

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Feb 23, 2026 License: MIT Imports: 17 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Logger = logrus.New()

Logger used by this package.

Functions

This section is empty.

Types

type Acknowledgement

type Acknowledgement struct {
	// Raw packet (optional).
	Raw *Packet `json:"-"`

	// Checksum of message timestamp, text and sender public key.
	Checksum uint32 `json:"checksum"`
}

func (*Acknowledgement) Marshal

func (ack *Acknowledgement) Marshal() []byte

func (*Acknowledgement) Packet

func (ack *Acknowledgement) Packet() *Packet

func (*Acknowledgement) String

func (ack *Acknowledgement) String() string

func (*Acknowledgement) Unmarshal

func (ack *Acknowledgement) Unmarshal(b []byte) error
type Advert struct {
	// Raw packet (optional).
	Raw *Packet `json:"-"`

	PublicKey *crypto.PublicKey `json:"public_key"`
	Time      time.Time         `json:"time"`
	Signature crypto.Signature  `json:"signature"`
	Type      NodeType          `json:"node_type"`
	Position  *Position         `json:"position,omitempty"`
	Feature1  *uint16           `json:"feature1,omitempty"`
	Feature2  *uint16           `json:"feature2,omitempty"`
	Name      string            `json:"name,omitempty"`
}

func (*Advert) Marshal

func (adv *Advert) Marshal() []byte

func (*Advert) Packet

func (adv *Advert) Packet() *Packet

func (*Advert) String

func (adv *Advert) String() string

func (*Advert) Unmarshal

func (adv *Advert) Unmarshal(b []byte) error

type AnonymousRequest

type AnonymousRequest struct {
	// Raw packet (optional).
	Raw *Packet `json:"-"`

	// Destination hash is the first byte of the recipient public key.
	Destination byte `json:"dst"`

	// PublicKey of the sender.
	PublicKey *crypto.PublicKey `json:"public_key"`

	// CipherMAC is the message authenticator.
	CipherMAC uint16 `json:"cipher_mac"`

	// CipherText is the encrypted message.
	CipherText []byte `json:"cipher_text"`
}

func (*AnonymousRequest) Marshal

func (req *AnonymousRequest) Marshal() []byte

func (*AnonymousRequest) Packet

func (req *AnonymousRequest) Packet() *Packet

func (*AnonymousRequest) String

func (req *AnonymousRequest) String() string

func (*AnonymousRequest) Unmarshal

func (req *AnonymousRequest) Unmarshal(b []byte) error

type CompanionError

type CompanionError struct {
	Code byte
}

func (CompanionError) Error

func (err CompanionError) Error() string

type Contact

type Contact struct {
	Name      string
	PublicKey *crypto.PublicKey
}

func (*Contact) Hash

func (contact *Contact) Hash() uint8

type Control

type Control struct {
	// Raw packet (optional).
	Raw *Packet `json:"-"`

	// Type of control packet.
	Type ControlType `json:"type"`

	// Request for discovery.
	Request *ControlDiscoverRequest `json:"request,omitempty"`

	// Response for discovery.
	Response *ControlDiscoverResponse `json:"response,omitempty"`

	// Data contains the data bytes for unknown/unparsed control types.
	Data []byte `json:"data"`
}

func (*Control) Marshal

func (control *Control) Marshal() []byte

func (*Control) Packet

func (control *Control) Packet() *Packet

func (*Control) String

func (control *Control) String() string

func (*Control) Unmarshal

func (control *Control) Unmarshal(b []byte) error

type ControlDiscoverRequest

type ControlDiscoverRequest struct {
	Flags      byte       `json:"flags"`       // upper 4 bits
	PrefixOnly bool       `json:"prefix_only"` // lower 1 bit
	TypeFilter byte       `json:"type_filter"`
	Tag        uint32     `json:"tag"`
	Since      *time.Time `json:"since,omitempty"`
}

func (ControlDiscoverRequest) String

func (req ControlDiscoverRequest) String() string

type ControlDiscoverResponse

type ControlDiscoverResponse struct {
	Flags     byte     `json:"flags"`     // upper 4 bits
	NodeType  NodeType `json:"node_type"` // lower 4 bits
	SNR       float64  `json:"snr"`
	Tag       uint32   `json:"tag"`
	PublicKey []byte   `json:"public_key"` // 8 or 32 bytes
}

func (ControlDiscoverResponse) String

func (res ControlDiscoverResponse) String() string

type ControlType

type ControlType byte
const (
	DiscoverRequest  ControlType = 0x80
	DiscoverResponse ControlType = 0x90
)

type EncryptedData

type EncryptedData struct {
	// Destination hash is the first byte of the recipient public key.
	Destination byte `json:"dst"`

	// Source hash is the first byte of the sender public key.
	Source byte `json:"src"`

	// CipherMAC is the message authenticator.
	CipherMAC uint16 `json:"cipher_mac"`

	// CipherText is the encrypted message.
	CipherText []byte `json:"cipher_text"`
}

func (*EncryptedData) Marshal

func (enc *EncryptedData) Marshal() []byte

func (*EncryptedData) String

func (enc *EncryptedData) String() string

func (*EncryptedData) Unmarshal

func (enc *EncryptedData) Unmarshal(b []byte) error

type EncryptedGroupData

type EncryptedGroupData struct {
	// ChannelHash is the first byte of the channel public key.
	ChannelHash byte `json:"channel_hash"`

	// CipherMAC is the message authenticator.
	CipherMAC uint16 `json:"cipher_mac"`

	// CipherText is the encrypted message.
	CipherText []byte `json:"cipher_text"`
}

func (*EncryptedGroupData) Marshal

func (enc *EncryptedGroupData) Marshal() []byte

func (*EncryptedGroupData) String

func (enc *EncryptedGroupData) String() string

func (*EncryptedGroupData) Unmarshal

func (enc *EncryptedGroupData) Unmarshal(b []byte) error

type Group

type Group struct {
	Name   string              `json:"name"`
	Hash   [32]byte            `json:"hash"`
	Secret crypto.SharedSecret `json:"-"`
}

func PublicGroup

func PublicGroup(name string) *Group

func SecretGroup

func SecretGroup(name string, key []byte) *Group

func (Group) ChannelHash

func (group Group) ChannelHash() uint8

func (*Group) MarshalJSON

func (group *Group) MarshalJSON() ([]byte, error)

func (*Group) UnmarshalJSON

func (group *Group) UnmarshalJSON(b []byte) error

type GroupData

type GroupData struct {
	// Raw packet (optional).
	Raw *Packet `json:"-"`

	EncryptedGroupData

	// Content contains the group datagram.
	Content []byte `json:"content,omitempty"`
}

func (*GroupData) Decrypt

func (data *GroupData) Decrypt(group *Group) error

func (*GroupData) Packet

func (data *GroupData) Packet() *Packet

func (*GroupData) String

func (data *GroupData) String() string

type GroupText

type GroupText struct {
	// Raw packet (optional).
	Raw *Packet `json:"-"`

	EncryptedGroupData

	// Only available after successful decryption:
	Content *GroupTextContent `json:"content,omitempty"`
}

func (*GroupText) Decrypt

func (text *GroupText) Decrypt(group *Group) error

func (*GroupText) Packet

func (text *GroupText) Packet() *Packet

func (*GroupText) String

func (text *GroupText) String() string

type GroupTextContent

type GroupTextContent struct {
	// Group this was sent on (not part of the packet).
	Group *Group `json:"group"`

	// Time of sending.
	Time time.Time `json:"time"`

	// Flags is generally 0x00 indicating a plain text message.
	Type TextType `json:"type"`

	// Attempt is the number of retries.
	Attempt uint8 `json:"attempt"`

	// Text sent to the group. Typically contains a "<name>: " prefix.
	Text string `json:"text"`
}

func (*GroupTextContent) String

func (text *GroupTextContent) String() string

type Identity

type Identity struct {
	Name       string
	PrivateKey *crypto.PrivateKey
}

func (*Identity) Hash

func (id *Identity) Hash() uint8

type Multipart

type Multipart struct {
	// Raw packet (optional).
	Raw *Packet `json:"-"`

	Remaining uint8       `json:"remaining"`
	Type      PayloadType `json:"type"`
	Data      []byte      `json:"data"`
}

func (*Multipart) Marshal

func (multi *Multipart) Marshal() []byte

func (*Multipart) Packet

func (multi *Multipart) Packet() *Packet

func (*Multipart) String

func (multi *Multipart) String() string

func (*Multipart) Unmarshal

func (multi *Multipart) Unmarshal(b []byte) error

type Node

type Node struct {
	OnPacket (*Packet)
	// contains filtered or unexported fields
}

Node can be any type of MeshCore node.

func NewCompanion

func NewCompanion(conn io.ReadWriteCloser) (*Node, error)

NewCompanion connects to a companion device type (over serial, TCP or BLE).

func (*Node) Close

func (dev *Node) Close() error

func (*Node) Info

func (dev *Node) Info() *radio.Info

func (*Node) Packets

func (dev *Node) Packets() <-chan *Packet

func (*Node) RawPackets

func (dev *Node) RawPackets() <-chan *protocol.Packet

func (*Node) Trace

func (dev *Node) Trace(path []byte) (snr []float64, err error)

type NodeType

type NodeType byte
const (
	Chat NodeType = iota + 1
	Repeater
	Room
	Sensor
)

func (NodeType) String

func (nt NodeType) String() string

type Packet

type Packet struct {
	// SNR is the signal-to-noise ratio.
	SNR float64 `json:"snr"`

	// RSSI is the received signal strength indicator (in dBm).
	RSSI int8 `json:"rssi"`

	// Raw bytes (optional).
	Raw []byte `json:"raw,omitempty"`

	// RouteType is the type of route for this packet.
	RouteType RouteType `json:"route_type"`

	// PayloadType is the type of payload for this packet.
	PayloadType PayloadType `json:"payload_type"`

	// TransportCodes are set by transport route types.
	TransportCodes []uint16 `json:"transport_codes,omitempty"`

	// Path are repeater hashes.
	Path []byte `json:"path"`

	// Payload is the raw (encoded) payload.
	Payload []byte `json:"payload,omitempty"`
}

func (*Packet) Decode

func (packet *Packet) Decode() (Payload, error)

func (*Packet) Hash

func (packet *Packet) Hash() []byte

func (*Packet) MarshalBytes

func (packet *Packet) MarshalBytes() []byte

func (*Packet) MarshalJSON

func (packet *Packet) MarshalJSON() ([]byte, error)

func (*Packet) String

func (packet *Packet) String() string

func (*Packet) UnmarshalBytes

func (packet *Packet) UnmarshalBytes(data []byte) error

type Path

type Path struct {
	// Raw packet (optional).
	Raw *Packet `json:"-"`

	EncryptedData
}

func (*Path) Packet

func (path *Path) Packet() *Packet

type Payload

type Payload interface {
	fmt.Stringer

	// Packet returns the underlying raw packet (if available, can be nil).
	Packet() *Packet

	// Marhal encodes the payload to bytes.
	Marshal() []byte

	// Unmarshal decodes the payload from bytes.
	Unmarshal([]byte) error
}

func Decode

func Decode(data []byte) (Payload, error)

type PayloadType

type PayloadType byte
const (
	TypeRequest PayloadType = iota
	TypeResponse
	TypeText
	TypeAck
	TypeAdvert
	TypeGroupText
	TypeGroupData
	TypeAnonRequest
	TypePath
	TypeTrace
	TypeMultipart
	TypeControl

	TypeRawCustom
)

Payload types.

func (PayloadType) String

func (pt PayloadType) String() string

type Position

type Position struct {
	Latitude  float64 `json:"latitude"`
	Longitude float64 `json:"longitude"`
}

func (*Position) Marshal

func (pos *Position) Marshal() []byte

func (*Position) String

func (pos *Position) String() string

func (*Position) Unmarshal

func (pos *Position) Unmarshal(b []byte) error

type RawCustom

type RawCustom struct {
	// Raw packet (optional).
	Raw *Packet `json:"-"`

	// Data in the payload.
	Data []byte `json:"data"`
}

func (*RawCustom) Marshal

func (raw *RawCustom) Marshal() []byte

func (*RawCustom) Packet

func (raw *RawCustom) Packet() *Packet

func (*RawCustom) String

func (raw *RawCustom) String() string

func (*RawCustom) Unmarshal

func (raw *RawCustom) Unmarshal(b []byte) error

type Request

type Request struct {
	// Raw packet (optional).
	Raw *Packet `json:"-"`

	EncryptedData

	// Only available after successful decryption:
	Content *RequestContent `json:"content,omitempty"`
}

func (*Request) Packet

func (req *Request) Packet() *Packet

func (*Request) String

func (req *Request) String() string

type RequestContent

type RequestContent struct {
	// Time of sending the request.
	Time time.Time `json:"time"`

	// Type of request.
	Type RequestType `json:"type"`

	// Data is the request payload.
	Data []byte `json:"data"`
}

func (*RequestContent) String

func (req *RequestContent) String() string

type RequestType

type RequestType byte
const (
	GetStats RequestType = iota + 1
	KeepAlive
	GetTelemetryData
	GetMinMaxAvgData
	GetAccessList
	GetNeighbors
	GetOwnerInfo
)

func (RequestType) String

func (rt RequestType) String() string

type Response

type Response struct {
	// Raw packet (optional).
	Raw *Packet `json:"-"`

	EncryptedData

	// Only available after successful decryption:
	Content *ResponseContent `json:"content,omitempty"`
}

func (*Response) Packet

func (res *Response) Packet() *Packet

func (*Response) String

func (res *Response) String() string

type ResponseContent

type ResponseContent struct {
	// Tag.
	Tag uint32 `json:"tag"`

	// Content of the response.
	Content []byte `json:"content"`
}

func (*ResponseContent) String

func (res *ResponseContent) String() string

type RouteType

type RouteType byte
const (
	TransportFlood RouteType = iota
	Flood
	Direct
	TransportDirect
)

Route types.

func (RouteType) HasTransportCodes

func (rt RouteType) HasTransportCodes() bool

HasTransportCodes indicates if this route type has transport codes in the packet.

func (RouteType) IsDirect

func (rt RouteType) IsDirect() bool

IsDirect is a direct routing type.

func (RouteType) IsFlood

func (rt RouteType) IsFlood() bool

IsFlood is a flood routing type.

func (RouteType) String

func (rt RouteType) String() string

type Text

type Text struct {
	// Raw packet (optional).
	Raw *Packet `json:"-"`

	EncryptedData

	// Only available after successful decryption:
	Content *TextContent `json:"content,omitempty"`
}

func (*Text) Packet

func (text *Text) Packet() *Packet

type TextContent

type TextContent struct {
	// Time of sending the message.
	Time time.Time `json:"time"`

	// Type of text.
	Type TextType `json:"type"`

	// Attempt for thie packet.
	Attempt uint8 `json:"attempt"`

	// Message contains the text message.
	Message []byte `json:"message"`
}

type TextType

type TextType byte
const (
	PlainText TextType = iota
	CLICommand
	SignedPlainText
)

type Trace

type Trace struct {
	// Raw packet (optional).
	Raw *Packet `json:"-"`

	Tag      uint32 `json:"tag"`
	AuthCode uint32 `json:"authcode"`
	Flags    byte   `json:"flags"`
	Path     []byte `json:"path"`
}

func (*Trace) Marshal

func (trace *Trace) Marshal() []byte

func (*Trace) Packet

func (trace *Trace) Packet() *Packet

func (*Trace) String

func (trace *Trace) String() string

func (*Trace) Unmarshal

func (trace *Trace) Unmarshal(b []byte) error

Directories

Path Synopsis
jwt
Package jwt implements JSON Web Tokens (JWT) using Meshcore Ed25519 keys
Package jwt implements JSON Web Tokens (JWT) using Meshcore Ed25519 keys

Jump to

Keyboard shortcuts

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