transport

package
v0.0.0-...-96bc9f9 Latest Latest
Warning

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

Go to latest
Published: Mar 8, 2024 License: MIT Imports: 23 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrChannelClosed = errors.New("channel closed")

ErrChannelClosed returned when the websocket connection is shut down manually

Functions

func GenerateToken

func GenerateToken(selfID, kid string, sk ed25519.PrivateKey) (string, error)

GenerateToken generates a signed jwt token for use with self services

Types

type Encoder

type Encoder interface {
	MarshalAuth(device, token string, offset int64) ([]byte, error)
	MarshalMessage(id, sender, recipient, mtype string, priority int, ciphertext []byte) ([]byte, error)
	UnmarshalHeader(data []byte) (Header, error)
	UnmarshalNotification(data []byte) (Notification, error)
	UnmarshalMessage(data []byte) (Message, int64, int64, error)
}

Encoder represents the interface an encoder needs to implement to work with a given protocol version

type Header interface {
	Id() []byte
	Msgtype() msgprotov2.MsgType
}

Header represents an event header

type Message

type Message interface {
	Id() []byte
	Sender() []byte
	Recipient() []byte
	CiphertextBytes() []byte
}

Message represents a message event

type Metadata

type Metadata interface {
	Offset() int64
	Timestamp() int64
}

Metadata represents a messages metadata

type Notification

type Notification interface {
	Id() []byte
	Msgtype() msgprotov2.MsgType
	Error() []byte
}

Notification represents a notification event

type Rest

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

Rest client for interacting with self's rest api

func NewRest

func NewRest(config RestConfig) (*Rest, error)

NewRest creates a new rest transport

func (*Rest) BuildURL

func (c *Rest) BuildURL(path string) string

BuildURL builds a url for the given path.

func (*Rest) Delete

func (c *Rest) Delete(path string) ([]byte, error)

Delete perform an http delete request

func (*Rest) Get

func (c *Rest) Get(path string) ([]byte, error)

Get perform an http get request

func (*Rest) Post

func (c *Rest) Post(path string, ctype string, data []byte) ([]byte, error)

Post perform an http post request

func (*Rest) Put

func (c *Rest) Put(path string, ctype string, data []byte) ([]byte, error)

Put perform an http put request

type RestConfig

type RestConfig struct {
	SelfID     string
	KeyID      string
	PrivateKey ed25519.PrivateKey
	APIURL     string
	Client     *http.Client
}

RestConfig configuration for connecting to selfs api

type Websocket

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

Websocket websocket client for self messaging

func NewWebsocket

func NewWebsocket(config WebsocketConfig) (*Websocket, error)

NewWebsocket creates a new websocket connection

func (*Websocket) Close

func (c *Websocket) Close() error

Close closes the messaging clients persistent connection

func (*Websocket) Connect

func (c *Websocket) Connect() error

func (*Websocket) Receive

func (c *Websocket) Receive() ([]byte, string, int64, []byte, error)

Receive receive a message

func (*Websocket) Send

func (c *Websocket) Send(recipients []string, mtype string, priority int, data []byte) error

Send send a message to given recipients. recipient is a combination of "selfID:deviceID"

func (*Websocket) SendAsync

func (c *Websocket) SendAsync(recipients []string, mtype string, priority int, data []byte, callback func(err error))

SendAsync send a message to given recipients with a callback to handle the server response

func (*Websocket) SendAsyncWithID

func (c *Websocket) SendAsyncWithID(id, recipient string, mtype string, priority int, data []byte, callback func(err error))

SendAsync send a message with a given id to a single recipient, with a callback to handle the server response

type WebsocketConfig

type WebsocketConfig struct {
	MessagingURL string
	SelfID       string
	DeviceID     string
	KeyID        string
	Offset       int64
	PrivateKey   ed25519.PrivateKey
	TCPDeadline  time.Duration
	InboxSize    int
	OnConnect    func()
	OnDisconnect func(err error)
	OnPing       func()
	// contains filtered or unexported fields
}

WebsocketConfig configuration for connecting to a websocket

Jump to

Keyboard shortcuts

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