carrier

package module
v0.0.0-...-6a39a03 Latest Latest
Warning

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

Go to latest
Published: Mar 3, 2022 License: Apache-2.0 Imports: 22 Imported by: 2

README

carrier for go

opening a channel

    channel, err := carrier.Connect("cDE5PMEV57EDRJGDWHOREDUCTED");
    if err != nil {
        panic(err)
    }
    defer channel.Shutdown();

opening a stream

    stream, err := channel.Open("/v0/icon/pixel");
    if err != nil {
        panic(err);
    }

reading from a stream

    msg, err := stream.Receive();
    if err != nil {
        panic(err);
    }

reading from a stream

    err := stream.Send([]byte{1,2,3});
    if err != nil {
        panic(err);
    }

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BuildId

func BuildId() string

func DecodeHeaders

func DecodeHeaders(b []byte) (map[string][][]byte, error)

func ErrorCheck

func ErrorCheck(e *C.err_Err) error

func MadpackDecode

func MadpackDecode(preshared *madpack.Index, b []byte) (map[string]interface{}, error)

func MadpackEncode

func MadpackEncode(preshared *madpack.Index, m map[string]interface{}) ([]byte, error)

func MakeConnectFn

func MakeConnectFn(v interface{}) C.carrier_connect_connect_t

func MakeDisconnectFn

func MakeDisconnectFn(v interface{}) C.carrier_connect_disconnect_t

func PresharedIndexDiscovery

func PresharedIndexDiscovery() *madpack.Index

func PresharedIndexFrom

func PresharedIndexFrom(b []byte) *madpack.Index

func PresharedIndexSubscribe

func PresharedIndexSubscribe() *madpack.Index

func PresharedIndexTrace

func PresharedIndexTrace() *madpack.Index

Types

type Address

type Address [32]byte // type 6

func AddressFromString

func AddressFromString(from string) (*Address, error)

func (*Address) CPtr

func (self *Address) CPtr() *C.carrier_identity_Address

func (*Address) String

func (self *Address) String() string

type Alias

type Alias [8]byte // type 11

type Async

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

func AsyncNew

func AsyncNew(tail uint) *Async

func (*Async) Base

func (self *Async) Base() *C.io_Async

func (*Async) Delete

func (self *Async) Delete()

type Channel

type Channel struct {
	Revision uint32
	// contains filtered or unexported fields
}

func Connect

func Connect(target_str string, opt ...ConnectOpt) (*Channel, error)

link and connect to target, return the target channel

func Link(target_str string, opt ...ConnectOpt) (*Channel, error)

link but dont connect. return the broker channel

func (*Channel) Open

func (self *Channel) Open(path string, opts ...OpenStreamOptions) (*Stream, error)

func (*Channel) Shutdown

func (self *Channel) Shutdown()

type Conduit

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

broadcast endpoint, a link to all carrier brokers

func StartConduit

func StartConduit(opts ...ConduitConfig) (*Conduit, error)

func (*Conduit) Close

func (self *Conduit) Close()

func (*Conduit) Each

func (self *Conduit) Each(f func(ep *Endpoint))

func (*Conduit) NetTrace

func (self *Conduit) NetTrace() (*NetTraceResult, error)

func (*Conduit) NewVault

func (self *Conduit) NewVault() (*Vault, error)

func (*Conduit) Subscribe

func (self *Conduit) Subscribe() (*Subscriber, error)

type ConduitConfig

type ConduitConfig struct {
	SecretKit *SecretKit
}

type ConnectOpt

type ConnectOpt struct {
	Vault *Vault
}

type Delete

type Delete interface {
	Delete()
}

type Endpoint

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

low level endpoint, a link to a single carrier broker contains a single threaded eventloop and is not thread safe

func DefaultEndpoint

func DefaultEndpoint(tail uint) (*Endpoint, error)

use default vault

func NewEndpoint

func NewEndpoint(tail uint) *Endpoint

allocate uninitialized endpoint memory

func (*Endpoint) Bootstrap

func (self *Endpoint) Bootstrap() error

request broker list from dns

func (*Endpoint) Close

func (self *Endpoint) Close()

immediately stop endpoint

func (*Endpoint) ClusterDoNotMove

func (self *Endpoint) ClusterDoNotMove()

request to be linked static to the first broker in the list

func (*Endpoint) ClusterMoveTarget

func (self *Endpoint) ClusterMoveTarget(target *Target)

request to be linked to same cluster node as target

func (*Endpoint) CoDelete

func (self *Endpoint) CoDelete(destructor Delete)

when cleaning up this endpoint, also cleanup something else

func (*Endpoint) Delete

func (self *Endpoint) Delete()

cleanup

func (self *Endpoint) Link() error

wait for link to broker

func (*Endpoint) Shutdown

func (self *Endpoint) Shutdown() error

signal graceful shutdown

func (*Endpoint) WaitEvent

func (self *Endpoint) WaitEvent() (bool, error)

wait for something to happen on the eventloop returns true if endpoint signaled readyness

func (*Endpoint) Wakeup

func (self *Endpoint) Wakeup() error

interrupt WaitEvent

this is ok to call from any thread

type Error

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

func ErrorNew

func ErrorNew(tail uint) *Error

func (*Error) Check

func (self *Error) Check() error

func (*Error) Delete

func (self *Error) Delete()

type Event

type Event struct {
	T        EventType
	Identity Identity
}

type EventType

type EventType string
const (
	PublishEvent   EventType = "Publish"
	UnpublishEvent           = "Unpublish"
)

type IConnect

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

func IConnectStart

func IConnectStart(ep *Endpoint, target *Target) (*IConnect, error)

func (*IConnect) Delete

func (self *IConnect) Delete()

func (*IConnect) OnConnect

func (self *IConnect) OnConnect(f func(self *C.carrier_connect_Connect, cha *C.carrier_channel_Channel))

func (*IConnect) OnDisconnect

func (self *IConnect) OnDisconnect(f func(self *C.carrier_connect_Connect, ep *C.carrier_endpoint_Endpoint))

type Identity

type Identity [32]byte // type 9

func IdentityFromSecret

func IdentityFromSecret(secret *Secret) *Identity

func IdentityFromString

func IdentityFromString(from string) (*Identity, error)

func (*Identity) CPtr

func (self *Identity) CPtr() *C.carrier_identity_Identity

func (*Identity) String

func (self *Identity) String() string

func (*Identity) String58

func (self *Identity) String58() string

type IdentityKit

type IdentityKit struct {
	Identity Identity
	Network  Address

} // type 2

func (*IdentityKit) CPtr

func (*IdentityKit) String

func (self *IdentityKit) String() string

type NetTraceResult

type NetTraceResult struct {
	Publishers         uint64 `json:"publishers"`
	BytesSentPerEpoch  uint64 `json:"bytes_sent_per_epoch"`
	BytesRecvPerEpoch  uint64 `json:"bytes_recv_per_epoch"`
	BytesSentPerSecond uint64 `json:"bytes_sent_per_second"`
	BytesRecvPerSecond uint64 `json:"bytes_recv_per_second"`
}

type OpenStreamOptions

type OpenStreamOptions struct {
	SendHeaders  map[string][][]byte
	OnHeaders    func(headers map[string][][]byte)
	OnMessage    func(msg []byte)
	OnFragmented func(uint32)
	OnClose      func()
	OnPoll       func() *[]byte

	Critical bool
}

type Record

type Record struct {
	Version uint8
	Netaddr net.UDPAddr
	Xaddr   Address
}

func (*Record) ToC

func (self *Record) ToC() C.carrier_vault_Broker

type Secret

type Secret [32]byte // type 3

func CreateSecret

func CreateSecret() (*Secret, error)

func SecretFromString

func SecretFromString(from string) (*Secret, error)

func (*Secret) AsString

func (self *Secret) AsString() string

func (*Secret) CPtr

func (self *Secret) CPtr() *C.carrier_identity_Secret

func (*Secret) Identity

func (self *Secret) Identity() *Identity

func (*Secret) String

func (self *Secret) String() string

no implicit conversion for safety

type SecretKit

type SecretKit struct {
	Identity Secret
	Network  Secret

} // type 1

func SecretKitFromString

func SecretKitFromString(from string) (*SecretKit, error)

func (*SecretKit) AsString

func (self *SecretKit) AsString() string

func (*SecretKit) CPtr

func (self *SecretKit) CPtr() *C.carrier_identity_SecretKit

type Signature

type Signature [64]byte // type 10

type Stream

type Stream struct {
	ResponseHeaders map[string][][]byte
	Index           *madpack.Index
	Rx              chan []byte
	Tx              chan []byte
	Death           chan bool
	// contains filtered or unexported fields
}

func (*Stream) Close

func (self *Stream) Close()

func (*Stream) Receive

func (self *Stream) Receive() (map[string]interface{}, error)

func (*Stream) ReceiveRaw

func (self *Stream) ReceiveRaw() ([]byte, error)

func (*Stream) Send

func (self *Stream) Send(msg map[string]interface{}) error

func (*Stream) SendRaw

func (self *Stream) SendRaw(v []byte) error

type Subscriber

type Subscriber struct {
	EventRx chan Event
}

type Target

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

func TargetFromString

func TargetFromString(from string) (*Target, error)

func (*Target) CPtr

func (self *Target) CPtr() *C.carrier_identity_Target

type Vault

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

func DefaultVault

func DefaultVault() (*Vault, error)

func VaultFromSecretKit

func VaultFromSecretKit(sk *SecretKit) (*Vault, error)

func (*Vault) AddAuthorization

func (self *Vault) AddAuthorization(addme *Identity, path string) error

func (*Vault) Clone

func (self *Vault) Clone() *Vault

/ make a clone

func (*Vault) DelAuthorization

func (self *Vault) DelAuthorization(addme *Identity, path string) error

func (*Vault) Delete

func (self *Vault) Delete()

func (*Vault) GetIdentity

func (self *Vault) GetIdentity() *Identity

func (*Vault) GetIdentityKit

func (self *Vault) GetIdentityKit() *IdentityKit

func (*Vault) GetNetwork

func (self *Vault) GetNetwork() *Address

func (*Vault) GetSecretKit

func (self *Vault) GetSecretKit() *SecretKit

func (*Vault) ListAuthorizations

func (self *Vault) ListAuthorizations(cb func(*Identity, string)) error

func (*Vault) SetNetwork

func (self *Vault) SetNetwork(join *Secret) error

func (*Vault) Take

func (self *Vault) Take() C.carrier_vault_Vault

/ take ownership of the vault back to C

Directories

Path Synopsis
core

Jump to

Keyboard shortcuts

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