protocol

package
v0.0.0-...-d71c197 Latest Latest
Warning

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

Go to latest
Published: Jun 5, 2022 License: CC0-1.0 Imports: 14 Imported by: 0

Documentation

Index

Constants

View Source
const (
	AllowedClockSkew = time.Second * 5
)

Variables

View Source
var (
	ErrDestinationBadChar = errors.New("destination contains forbidden character")
	ErrVerbBadChar        = errors.New("verb contains forbidden character")
	ErrNoPrivateKey       = errors.New("no private key with sender permission found")
	ErrFormat             = errors.New("message format corrupt")
	ErrSignature          = errors.New("signature corrupt")
	ErrPeerPermission     = errors.New("peer key or permission not known")
	ErrClockSkew          = errors.New("message outside of time window")
)

Functions

func MatchWildcards

func MatchWildcards(s, pattern string) bool

MatchWildcards returns true if s matches pattern '*' matches between dots may only occur once between dots. '**' matches beyond dots. May only appear at end of pattern.

func NewUUID

func NewUUID(uuid ...[]byte) []byte

NewUUID creates a new UUID. If the given one is too long, it will be hashed. If none is given, a random one is created.

func RandomBytes

func RandomBytes(l int) []byte

Types

type Base58Bytes

type Base58Bytes []byte

func (*Base58Bytes) MarshalJSON

func (b58b *Base58Bytes) MarshalJSON() ([]byte, error)

func (*Base58Bytes) UnmarshalJSON

func (b58b *Base58Bytes) UnmarshalJSON(d []byte) error

type Config

type Config struct {
	NATSUrl          []string
	NATSCredsFile    string
	Subject          string
	DefaultKey       Base58Bytes
	Destination      string
	AllowedClockSkew time.Duration
	Identities       Identities
	Peers            Peers
}

func NewConfig

func NewConfig() *Config

func (*Config) IsSelf

func (config *Config) IsSelf(publicKey []byte) bool

func (*Config) PotentialReceivers

func (config *Config) PotentialReceivers(destination string) Peers

func (*Config) PrivateKey

func (config *Config) PrivateKey(publicKey []byte, verb ...string) []byte

func (*Config) String

func (config *Config) String() string

type Identities

type Identities []Identity

type Identity

type Identity struct {
	PublicKey   Base58Bytes
	PrivateKey  Base58Bytes
	Permissions []string
}

func (*Identity) HasPermission

func (identity *Identity) HasPermission(verb ...string) bool

func (*Identity) Peer

func (identity *Identity) Peer(destination string) *Peer

func (*Identity) String

func (identity *Identity) String() string

type Message

type Message struct {
	SenderPublicKey Base58Bytes
	SenderSignature Base58Bytes
	Destination     string
	RequestReply    bool
	SendTimeNano    int64
	UUID            []byte
	Verb            string
	Payload         string
	Hash            []byte
}

func DecodeMessage

func DecodeMessage(c *Config, msg []byte) (*Message, error)

func DecodeReply

func DecodeReply(c *Config, msg []byte) (*Message, error)

func (*Message) EncodeMessage

func (msg *Message) EncodeMessage(c *Config) ([]byte, error)

func (*Message) EncodeReply

func (msg *Message) EncodeReply(c *Config) ([]byte, error)

func (*Message) Match

func (msg *Message) Match(c *Config, matches ...MsgMatch) bool

type MsgMatch

type MsgMatch func(*Config, *Message) bool

func MatchDestination

func MatchDestination(destination ...string) MsgMatch

func MatchSenderPublicKey

func MatchSenderPublicKey(publicKey []byte) MsgMatch

func MatchUUID

func MatchUUID(uuid []byte) MsgMatch

func MatchVerb

func MatchVerb(verb ...string) MsgMatch

type Peer

type Peer struct {
	PublicKey   Base58Bytes
	Destination string
	Permissions []string
}

func (*Peer) Copy

func (peer *Peer) Copy() *Peer

func (*Peer) HasPermission

func (peer *Peer) HasPermission(verb ...string) bool

func (*Peer) String

func (peer *Peer) String() string

type Peers

type Peers []Peer

func (Peers) Destination

func (peers Peers) Destination(pubkey []byte) string

func (Peers) Known

func (peers Peers) Known(publicKey []byte, verb ...string) bool

func (Peers) Remove

func (peers Peers) Remove(peer []byte) Peers

Jump to

Keyboard shortcuts

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