api

package
v1.1.1-0...-40efbf4 Latest Latest
Warning

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

Go to latest
Published: May 5, 2022 License: GPL-3.0 Imports: 7 Imported by: 8

Documentation

Index

Constants

View Source
const (
	APITypeInvalid        byte = 0x0
	APITypeNil            byte = 0x1
	APITypeInt64          byte = 0x2
	APITypeUint64         byte = 0x3
	APITypeString         byte = 0x4
	APITypeBytes          byte = 0x5
	APITypeBytesBytes     byte = 0x6
	APITypeInterfaceArray byte = 0x7

	APITypePubKeyECC byte = 0x10
	APITypePubKeyRSA byte = 0x11

	APITypeContactArray byte = 0x20
	APITypeChannelArray byte = 0x21
	APITypeProfileArray byte = 0x22
	APITypePeerArray    byte = 0x23

	APITypeContact byte = 0x30
	APITypeChannel byte = 0x31
	APITypeProfile byte = 0x32
	APITypePeer    byte = 0x33

	APITypeBundle byte = 0x40
)

API Parameter Data types

View Source
const (
	// StreamHeaderFlag : this message is a stream header
	StreamHeaderFlag = 0x01
	// ChunkedFlag : this message is a chunked
	ChunkedFlag = 0x02
	// ChannelFlag : this message has a channel name prefix
	ChannelFlag = 0x04
)

Variables

View Source
var (
	ErrInputTooShort = errors.New("input too short")
	ErrLenOverflow   = errors.New("uvarint overflow")
)

Functions

func ArgsFromBytes

func ArgsFromBytes(args []byte) ([]interface{}, error)

ArgsFromBytes - converts a byte array to an interface array

func ArgsToBytes

func ArgsToBytes(args []interface{}) []byte

ArgsToBytes - converts an interface array to a byte array

func BytesBytesFromBytes

func BytesBytesFromBytes(input *[]byte) (*[][]byte, error)

BytesBytesFromBytes - converts an array of byte arrays from a byte array

func BytesBytesToBytes

func BytesBytesToBytes(bba *[][]byte) *[]byte

BytesBytesToBytes - converts an array of byte arrays to a byte array

func ReadBuffer

func ReadBuffer(reader io.Reader) (*[]byte, error)

ReadBuffer - reads a serialized buffer from the wire, returns buffer. If the reader is not an io.ByteReader, it will be wrapped with one internally

func RemoteCallToBytes

func RemoteCallToBytes(call *RemoteCall) *[]byte

RemoteCallToBytes - converts a RemoteCall to a byte array

func RemoteResponseToBytes

func RemoteResponseToBytes(resp *RemoteResponse) *[]byte

RemoteResponseToBytes - converts a RemoteResponse to a byte array

func WriteBuffer

func WriteBuffer(writer io.Writer, b *[]byte) error

WriteBuffer - writes a serialized buffer to the wire

Types

type Action

type Action uint8

Action - API Call ID numbers

const (
	Null          Action = 0
	ID            Action = 1
	Dropoff       Action = 2
	Pickup        Action = 3
	CID           Action = 16
	GetContact    Action = 17
	GetContacts   Action = 18
	AddContact    Action = 19
	DeleteContact Action = 20
	GetChannel    Action = 21
	GetChannels   Action = 22
	AddChannel    Action = 23
	DeleteChannel Action = 24
	GetProfile    Action = 25
	GetProfiles   Action = 26
	AddProfile    Action = 27
	DeleteProfile Action = 28
	LoadProfile   Action = 29
	GetPeer       Action = 30
	GetPeers      Action = 31
	AddPeer       Action = 32
	DeletePeer    Action = 33
	Send          Action = 34
	SendChannel   Action = 35
)

type Bundle

type Bundle struct {
	Data []byte
	Time int64
}

Bundle : mostly-opaque data blob returned by Pickup and passed into Dropoff

type Channel

type Channel struct {
	Name   string `db:"name"`
	Pubkey string `db:"pubkey"`
}

Channel : object that describes a channel (named public key)

type ChannelPriv

type ChannelPriv struct {
	Name    string
	Pubkey  string
	Privkey bc.KeyPair
}

ChannelPriv : object that describes a channel (including private key)

type ChannelPrivB64

type ChannelPrivB64 struct {
	Name    string `db:"name"`
	Privkey string `db:"privkey"`
}

ChannelPrivB64 : object that describes a channel, database version (including private key)

type Chunk

type Chunk struct {
	StreamID uint32 `db:"streamid"`
	ChunkNum uint32 `db:"chunknum"`
	Data     []byte `db:"data"`
}

Chunk header for each chunk

type ConfigValue

type ConfigValue struct {
	Name  string `db:"name"`
	Value string `db:"value"`
}

ConfigValue - Name/Value pairs of configuration strings

type Contact

type Contact struct {
	Name   string `db:"name"`
	Pubkey string `db:"pubkey"`
}

Contact : object that describes a contact (named public key)

type Event

type Event struct {
	Severity LogLevel
	Type     EventType
	Data     []interface{}
}

Event - Ratnet Events

type EventType

type EventType int

EventType - type of event

const (
	Log EventType = iota
)

type ExportedNode

type ExportedNode struct {
	ContentKey  string
	ContentType string
	RoutingKey  string
	RoutingType string
	Policies    []Policy

	Profiles []ProfilePrivB64
	Channels []ChannelPrivB64
	Peers    []Peer
	Contacts []Contact
	Router   Router
}

ExportedNode - Node Config structure for export

type ImportExport

type ImportExport interface {
	// Import node from JSON
	Import(jsonConfig []byte) error
	// Export node to JSON
	Export() ([]byte, error)
}

ImportExport - makes a node exportable/importable when activated by build tag

type ImportedNode

type ImportedNode struct {
	ContentKey  string
	ContentType string
	RoutingKey  string
	RoutingType string
	Policies    []map[string]interface{}

	Profiles []ProfilePrivB64
	Channels []ChannelPrivB64
	Peers    []Peer
	Contacts []Contact
	Router   map[string]interface{}
}

ImportedNode - Node Config structure for import

type JSON

type JSON interface {
	// MarshalJSON : Serialize this type to JSON
	MarshalJSON() (b []byte, e error)
}

JSON - includes the JSON serializer

type LogLevel

type LogLevel int

LogLevel - Severity value for events

const (
	Info LogLevel = iota
	Debug
	Warning
	Error
	Critical
)

Info is the lowest, Critical the highest

type Msg

type Msg struct {
	Name         string
	Content      *bytes.Buffer
	IsChan       bool
	PubKey       bc.PubKey
	Chunked      bool
	StreamHeader bool
}

Msg : object that describes the messages passed between nodes

type Node

type Node interface {

	// Local Access Only (Not Exposed Through RPC API)
	Start() error
	Stop()
	GetPolicies() []Policy
	SetPolicy(policies ...Policy)
	Router() Router
	SetRouter(router Router)
	GetChannelPrivKey(name string) (string, error)
	Handle(msg Msg) (bool, error)
	Forward(msg Msg) error
	IsRunning() bool

	// Chunking
	// AddStream - inform node of receipt of a stream header
	AddStream(streamID uint32, totalChunks uint32, channelName string) error
	// AddChunk - inform node of receipt of a chunk
	AddChunk(streamID uint32, chunkNum uint32, data []byte) error

	// FlushOutbox : Empties the outbox of messages older than maxAgeSeconds
	FlushOutbox(maxAgeSeconds int64)

	// AdminRPC :
	AdminRPC(transport Transport, call RemoteCall) (interface{}, error)

	// PublicRPC :
	PublicRPC(transport Transport, call RemoteCall) (interface{}, error)

	// ID : get the routing public key (1)
	ID() (bc.PubKey, error)

	// Dropoff : Deliver a batch of messages to this node (2)
	Dropoff(bundle Bundle) error

	// Pickup : Get outgoing messages from this node (3)
	Pickup(routingPub bc.PubKey, lastTime int64, maxBytes int64, channelNames ...string) (Bundle, error)

	// CID : Return content key (16)
	CID() (bc.PubKey, error)

	// GetContact : Return a contact by name (17)
	GetContact(name string) (*Contact, error)
	// GetContacts : Return a list of contacts (18)
	GetContacts() ([]Contact, error)
	// AddContact : Add or Update a contact key (19)
	AddContact(name string, key string) error
	// DeleteContact : Remove a contact (20)
	DeleteContact(name string) error

	// GetChannel : Return a channel by name (21)
	GetChannel(name string) (*Channel, error)
	// GetChannels : Return list of channels known to this node (22)
	GetChannels() ([]Channel, error)
	// AddChannel : Add a channel to this node's database (23)
	AddChannel(name string, privkey string) error
	// DeleteChannel : Remove a channel from this node's database (24)
	DeleteChannel(name string) error

	// GetProfile : Retrieve a Profile by name (25)
	GetProfile(name string) (*Profile, error)
	// GetProfiles : Retrieve the list of profiles for this node (26)
	GetProfiles() ([]Profile, error)
	// AddProfile : Add or Update a profile to this node's database (27)
	AddProfile(name string, enabled bool) error
	// DeleteProfile : Remove a profile from this node's database (28)
	DeleteProfile(name string) error
	// LoadProfile : Load a profile key from the database as the content key (29)
	LoadProfile(name string) (bc.PubKey, error)

	// GetPeer : Retrieve a peer by name (30)
	GetPeer(name string) (*Peer, error)
	// GetPeers : Retrieve this node's list of peers (31)
	GetPeers(group ...string) ([]Peer, error)
	// AddPeer : Add or Update a peer configuration (32)
	AddPeer(name string, enabled bool, uri string, group ...string) error
	// DeletePeer : Remove a peer from this node's database (33)
	DeletePeer(name string) error

	// Send : Transmit a message to a single key (34) <deprecated>
	Send(contactName string, data []byte, pubkey ...bc.PubKey) error
	// SendChannel : Transmit a message to a channel (35) <deprecated>
	SendChannel(channelName string, data []byte, pubkey ...bc.PubKey) error

	// SendMsg : Transmit a message object (36)
	SendMsg(msg Msg) error

	// Channels
	// In : Returns the In channel of this node
	In() chan Msg
	// Out : Returns the Out channel of this node
	Out() chan Msg
	// Events : Returns the Err channel of this node
	Events() chan Event

	ImportExport
}

Node : abstract base type for RatNet implementations

type OutboxMsg

type OutboxMsg struct {
	Channel   string `db:"channel"`
	Msg       []byte `db:"msg"`
	Timestamp int64  `db:"timestamp"`
}

OutboxMsg : object that describes an outbox message

type Patch

type Patch struct {
	From string
	To   []string
}

Patch : defines a mapping from an incoming channel to one or more destination channels.

type Peer

type Peer struct {
	Name    string `db:"name"`
	Enabled bool   `db:"enabled"`
	URI     string `db:"uri"`
	Group   string `db:"peergroup"`
}

Peer : object that describes a peer (transport connection instructions)

type PeerInfo

type PeerInfo struct {
	LastPollLocal  int64
	LastPollRemote int64
	TotalBytesTX   int64
	TotalBytesRX   int64
	RoutingPub     bc.PubKey
}

PeerInfo - last contact info for peers

type Policy

type Policy interface {
	RunPolicy() error
	Stop()
	GetTransport() Transport

	JSON
}

Policy : defines a "Connection Policy" object

type Profile

type Profile struct {
	Name    string `db:"name"`
	Enabled bool   `db:"enabled"`
	Pubkey  string `db:"pubkey"`
}

Profile : object that describes a profile

type ProfilePriv

type ProfilePriv struct {
	Name    string
	Enabled bool
	Privkey bc.KeyPair
}

ProfilePriv : object that describes a profile (including private key)

type ProfilePrivB64

type ProfilePrivB64 struct {
	Name    string `db:"name"`
	Enabled bool   `db:"enabled"`
	Privkey string `db:"privkey"`
}

ProfilePrivB64 : object that describes a profile, database version (including private key)

type RemoteCall

type RemoteCall struct {
	Action Action
	Args   []interface{}
}

RemoteCall : defines a Remote Procedure Call

func RemoteCallFromBytes

func RemoteCallFromBytes(input *[]byte) (*RemoteCall, error)

RemoteCallFromBytes - converts a RemoteCall from a byte array

type RemoteResponse

type RemoteResponse struct {
	Error string
	Value interface{}
}

RemoteResponse : defines a response returned from a Remote Procedure Call

func RemoteResponseFromBytes

func RemoteResponseFromBytes(input *[]byte) (*RemoteResponse, error)

RemoteResponseFromBytes - converts a RemoteResponse from a byte array

func (*RemoteResponse) IsErr

func (r *RemoteResponse) IsErr() bool

IsErr - is this response an error?

func (*RemoteResponse) IsNil

func (r *RemoteResponse) IsNil() bool

IsNil - is this response Nil?

type Router

type Router interface {
	// Route : Determine what to do with the given message, and then have the node do it.
	Route(node Node, msg []byte) error
	// Patch : Add a mapping from an incoming channel to one or more destination channels
	Patch(patch Patch)
	// GetPatches : Returns an array with the mappings of incoming channels to destination channels
	GetPatches() []Patch

	JSON
}

Router : defines an interface for a stateful Routing object

type StreamHeader

type StreamHeader struct {
	StreamID    uint32 `db:"streamid"`
	NumChunks   uint32 `db:"parts"`
	ChannelName string `db:"channel"`
}

StreamHeader manifest for a chunked transfer (database version)

type Transport

type Transport interface {
	Listen(listen string, adminMode bool)
	Name() string
	RPC(host string, method Action, args ...interface{}) (interface{}, error)
	Stop()

	ByteLimit() int64 // limit on bytes per bundle for this transport
	SetByteLimit(limit int64)

	JSON
}

Transport - Interface to implement in a RatNet-compatable pluggable transport module

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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