client

package
v0.0.0-...-07264a8 Latest Latest
Warning

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

Go to latest
Published: Sep 19, 2022 License: BSD-2-Clause Imports: 22 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ConnectToNetwork

func ConnectToNetwork(client *xxdk.Cmix, timeout time.Duration) error

ConnectToNetwork connects the client to the network.

func InitClient

func InitClient(password []byte, storeDir, ndfPath string) (*xxdk.Cmix, error)

InitClient initializes and returns a new api.Client. If a session folder already exists, then the client is loaded instead.

func LoadChannel

func LoadChannel(path string) (*crypto.Channel, error)

LoadChannel loads the data from the given file path and deserializes it into a channel.

func MaxMessagePayloadSize

func MaxMessagePayloadSize(maxPayloadSize int, username string) int

MaxMessagePayloadSize returns the maximum size of a payload for the given max payload size and username.

func NewMessage

func NewMessage(maxPayloadSize int, tag Tag, timestamp time.Time,
	username string, payload []byte) ([]byte, error)

NewMessage generates a new message containing the payload and the metadata.

func ReadRsaPrivateKey

func ReadRsaPrivateKey(path, channelName string) (*rsa.PrivateKey, error)

ReadRsaPrivateKey reads the RSA private key PEM from the given file path. If not file path is supplied, the channel name is used instead.

func ReceptionCallback

func ReceptionCallback() (broadcast.ListenerFunc, chan ReceivedBroadcast)

ReceptionCallback generates the listener callback function that the broadcast channel delivers new payloads on. Also returns a channel that receives all received broadcast messages for the UI to use to print messages.

func WriteChannel

func WriteChannel(path string, s *crypto.Channel) error

WriteChannel serialises and write the channel to the given file path. If no path is supplied, it is printed to stdout.

func WriteRsaPrivateKey

func WriteRsaPrivateKey(path, channelName string, pk *rsa.PrivateKey) error

WriteRsaPrivateKey writes the RSA private key PEM to the given file path. If not file path is supplied, the channel name is used instead.

Types

type BroadcastFn

type BroadcastFn func(tag Tag, timestamp time.Time, message []byte) error

BroadcastFn allows the UI to pass the message and its metadata to the broadcast client.

func AsymmetricBroadcastFn

func AsymmetricBroadcastFn(
	c broadcast.Channel, username string, pk *rsa.PrivateKey) (BroadcastFn, int)

AsymmetricBroadcastFn returns the BroadcastFn used to broadcast asymmetric broadcast messages.

func SymmetricBroadcastFn

func SymmetricBroadcastFn(c broadcast.Channel, username string) (BroadcastFn, int)

SymmetricBroadcastFn returns the BroadcastFn used to broadcast symmetric broadcast messages.

type ReceivedBroadcast

type ReceivedBroadcast struct {
	Tag       Tag
	Timestamp time.Time
	Username  string
	Message   []byte
}

ReceivedBroadcast contains the broadcast message and its metadata.

type Tag

type Tag uint8

Tag specifies the type of broadcast message so that it can be handled appropriately on reception.

const (
	// Default indicates a normal chat messages.
	Default Tag = 0

	// Join indicates the user has joined the channel.
	Join Tag = 1

	// Exit indicates the user has left the channel.
	Exit Tag = 2

	// Admin indicates that the sender has a private key and the message is sent
	// asymmetrically.
	Admin Tag = 3
)

func UnmarshalMessage

func UnmarshalMessage(data []byte) (tag Tag, timestamp time.Time,
	username string, payload []byte)

UnmarshalMessage decodes the data into a payload and its metadata.

func (Tag) String

func (t Tag) String() string

String returns a human-readable name for the Tag for debugging purposes. Adheres to the fmt.Stringer interface.

Jump to

Keyboard shortcuts

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