messaging

package module
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Jul 7, 2021 License: ISC Imports: 20 Imported by: 2

README

Autonomy Messaging Go

The messaging protocol for making communications between Autonomy pods.

Usage

Before using the messaging library, it asumes that a user has already get a new authentication token from the Autonomy API server.

Setup

First, create a messaging client:

messagingClient := messaging.New(
	&http.Client{Timeout: 10 * time.Second},
	"http://localhost:8080",
	"authentication-token",
	"/path/to/messaging.db",
)

And register an account:

messagingClient.RegisterAccount()

After that you need to register pre-keys so that other client can start conversations with you:

messagingClient.RegisterKeys()

Once everything is done, we can create a websocket connection to send and receive messages:

wsClient := messagingClient.NewWSClient()
Send and Receive

WhisperMessages returns a channel of messages.

messages := wsClient.WhisperMessages()
m := <-messages

For sending messages to others, we can use SendWhisperMessages

wsClient.SendWhisperMessages("<destination DID>", device_id, responseBody)

Documentation

Index

Constants

View Source
const (
	MessageTypeUnknown = iota
	MessageTypeCiphertext
	MessageTypeKeyExchange
	MessageTypePrekeyBundle
	MessageTypeReceipt
	MessageTypeUnidentifiedSender
)
View Source
const (
	MasterDeviceId = 1
)

Variables

This section is empty.

Functions

This section is empty.

Types

type AccountAttributes

type AccountAttributes struct {
	RegistrationID uint32 `json:"registrationId"`
}

type Client

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

func New

func New(httpClient *http.Client, endpoint, jwt, storePath string) *Client

func (*Client) Close

func (c *Client) Close() error

Close will terminate the client gracefully

func (*Client) NewWSClient

func (c *Client) NewWSClient() (*WSMessagingClient, error)

NewWSClient creates a websocket client based on the configuration from the HTTP client

func (*Client) PrepareEncryptedMessages

func (c *Client) PrepareEncryptedMessages(recipientID string, deviceID uint32, messages [][]byte) ([]Message, error)

PrepareEncryptedMessages generates encrypted messages by local session and remote recipient key

func (*Client) ReceiveMessages

func (c *Client) ReceiveMessages() ([]*Message, bool, error)

func (*Client) RefreshToken

func (c *Client) RefreshToken(authToken string)

RefreshToken updates current authToken with a new value

func (*Client) RegisterAccount

func (c *Client) RegisterAccount() error

func (*Client) RegisterKeys

func (c *Client) RegisterKeys() error

func (*Client) RegisterTemporaryAccount

func (c *Client) RegisterTemporaryAccount() error

func (*Client) SendMessages

func (c *Client) SendMessages(recipientID string, deviceID uint32, messages [][]byte) error

func (*Client) SessionCipher

func (c *Client) SessionCipher(recipientID string, deviceID uint32) *axolotl.SessionCipher

SessionCipher returns a session cipher with a specific recipient id and device id

type Device

type Device struct {
	ID             uint32       `json:"deviceId"`
	RegistrationID uint32       `json:"registrationId"`
	SignedPreKey   SignedPreKey `json:"signedPreKey"`
	PreKey         PreKey       `json:"preKey"`
}

type LevelDBAxolotlStore

type LevelDBAxolotlStore struct {
	sync.Mutex
	// contains filtered or unexported fields
}

func (*LevelDBAxolotlStore) Close

func (l *LevelDBAxolotlStore) Close() error

Close is to close the database

func (*LevelDBAxolotlStore) ContainsPreKey

func (l *LevelDBAxolotlStore) ContainsPreKey(id uint32) bool

func (*LevelDBAxolotlStore) ContainsSession

func (l *LevelDBAxolotlStore) ContainsSession(recipientID string, deviceID uint32) bool

func (*LevelDBAxolotlStore) ContainsSignedPreKey

func (l *LevelDBAxolotlStore) ContainsSignedPreKey(id uint32) bool

func (*LevelDBAxolotlStore) DeleteAllSessions

func (l *LevelDBAxolotlStore) DeleteAllSessions(string)

func (*LevelDBAxolotlStore) DeleteSession

func (l *LevelDBAxolotlStore) DeleteSession(recipientID string, deviceID uint32)

func (*LevelDBAxolotlStore) GetIdentityKeyPair

func (l *LevelDBAxolotlStore) GetIdentityKeyPair() (*axolotl.IdentityKeyPair, error)

IdentityStore

func (*LevelDBAxolotlStore) GetLocalRegistrationID

func (l *LevelDBAxolotlStore) GetLocalRegistrationID() (uint32, error)

func (*LevelDBAxolotlStore) GetSubDeviceSessions

func (l *LevelDBAxolotlStore) GetSubDeviceSessions(string) []uint32

func (*LevelDBAxolotlStore) IsTrustedIdentity

func (l *LevelDBAxolotlStore) IsTrustedIdentity(string, *axolotl.IdentityKey) bool

func (*LevelDBAxolotlStore) LoadPreKey

func (l *LevelDBAxolotlStore) LoadPreKey(id uint32) (*axolotl.PreKeyRecord, error)

PreKeyStore

func (*LevelDBAxolotlStore) LoadSession

func (l *LevelDBAxolotlStore) LoadSession(recipientID string, deviceID uint32) (*axolotl.SessionRecord, error)

SessionStore

func (*LevelDBAxolotlStore) LoadSignedPreKey

func (l *LevelDBAxolotlStore) LoadSignedPreKey(id uint32) (*axolotl.SignedPreKeyRecord, error)

SignedPreKeyStore

func (*LevelDBAxolotlStore) LoadSignedPreKeys

func (l *LevelDBAxolotlStore) LoadSignedPreKeys() []axolotl.SignedPreKeyRecord

func (*LevelDBAxolotlStore) RemovePreKey

func (l *LevelDBAxolotlStore) RemovePreKey(id uint32)

func (*LevelDBAxolotlStore) RemoveSignedPreKey

func (l *LevelDBAxolotlStore) RemoveSignedPreKey(id uint32)

func (*LevelDBAxolotlStore) SaveIdentity

func (l *LevelDBAxolotlStore) SaveIdentity(id string, key *axolotl.IdentityKey) error

func (*LevelDBAxolotlStore) StoreIdentityKeyPair

func (l *LevelDBAxolotlStore) StoreIdentityKeyPair(kp *axolotl.IdentityKeyPair) error

func (*LevelDBAxolotlStore) StorePreKey

func (l *LevelDBAxolotlStore) StorePreKey(id uint32, r *axolotl.PreKeyRecord) error

func (*LevelDBAxolotlStore) StoreRegistrationID

func (l *LevelDBAxolotlStore) StoreRegistrationID(id uint32) error

func (*LevelDBAxolotlStore) StoreSession

func (l *LevelDBAxolotlStore) StoreSession(recipientID string, deviceID uint32, r *axolotl.SessionRecord) error

func (*LevelDBAxolotlStore) StoreSignedPreKey

func (l *LevelDBAxolotlStore) StoreSignedPreKey(id uint32, r *axolotl.SignedPreKeyRecord) error

type Message

type Message struct {
	Guid               uuid.UUID `json:"guid"`
	Type               int32     `json:"type"`
	Source             string    `json:"source"`
	SourceDevice       uint32    `json:"sourceDevice"`
	DestDeviceID       uint32    `json:"destinationDeviceId"`
	DestRegistrationID uint32    `json:"destinationRegistrationId"`
	Content            []byte    `json:"content"`
	ServerTimestamp    int64     `json:"serverTimestamp"`
}

type Messages

type Messages struct {
	Destination string    `json:"destination"`
	Messages    []Message `json:"messages"`
	Timestamp   int64     `json:"timestamp"`
}

type MessagingCommand

type MessagingCommand struct {
	ID      string      `json:"id"`
	Command string      `json:"command"`
	Args    interface{} `json:"args"`
}

type MessagingCommandResponse

type MessagingCommandResponse struct {
	ID    string `json:"id"`
	OK    int    `json:"ok"`
	Error string `json:"errors"`
}

type PreKey

type PreKey struct {
	ID        uint32 `json:"keyId"`
	PublicKey []byte `json:"publicKey"`
}

type PrekeyState

type PrekeyState struct {
	IdentityKey []byte   `json:"identityKey"`
	Devices     []Device `json:"devices"`
}

type PrivateKeyStore

type PrivateKeyStore interface {
	StoreIdentityKeyPair(*axolotl.IdentityKeyPair) error
	StoreRegistrationID(uint32) error
	Close() error
}

type SignedPreKey

type SignedPreKey struct {
	ID        uint32 `json:"keyId"`
	PublicKey []byte `json:"publicKey"`
	Signature []byte `json:"signature"`
}

type WSMessagePayload

type WSMessagePayload struct {
	Type string          `json:"type"`
	Data json.RawMessage `json:"data"`
}

WSMessagePayload is the websocket wrapped message for signal message and command response

type WSMessagingClient

type WSMessagingClient struct {
	sync.Mutex
	// contains filtered or unexported fields
}

func (*WSMessagingClient) Close

func (c *WSMessagingClient) Close()

Close will close the websocket connection which leads the cleaning process being triggered

func (*WSMessagingClient) Command

Command sends messaging command through messaging websocket client

func (*WSMessagingClient) SendWhisperMessages

func (c *WSMessagingClient) SendWhisperMessages(to string, deviceID uint32, messages [][]byte) MessagingCommandResponse

SendWhisperMessages is a shortcuts for send messages via websocket connection

func (*WSMessagingClient) WhisperMessages

func (c *WSMessagingClient) WhisperMessages() <-chan *Message

WhisperMessages starts a process to process incoming messages and returns a read channel of decrypted signal messages

Jump to

Keyboard shortcuts

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