spotlib

package module
v0.2.2 Latest Latest
Warning

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

Go to latest
Published: Sep 3, 2024 License: MIT Imports: 29 Imported by: 1

README

GoDoc

spotlib

Spot connection library, allows accessing Spot and sending end to end encrypted messages to other participants.

Usage

c, err := spotlib.New()
if err != nil {
    return err
}
go func() {
    for ev := range c.Events.On("status") {
        if emmiter.Arg[int](ev, 0) == 1 {
            // we are online!
        }
    }
}()
c.SetHandler("endpoint", func(msg *spotproto.Message) ([]byte, error) {
    // handle message
    ...
})

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Client added in v0.0.3

type Client struct {
	Events *emitter.Hub
	// contains filtered or unexported fields
}

Client holds information about a client, including its connections to the spot servers

func New added in v0.0.3

func New(params ...any) (*Client, error)

New starts a new Client and establishes connection to the Spot system. If any key is passed, the first key will be used as the main signing key.

func (*Client) Close added in v0.1.1

func (c *Client) Close() error

func (*Client) ConnectionCount added in v0.0.4

func (c *Client) ConnectionCount() (uint32, uint32)

ConnectionCount returns the number of spot server connections, and the number of said connections which are online (ie. past the handshake step).

func (*Client) GetGroupMembers added in v0.1.3

func (c *Client) GetGroupMembers(ctx context.Context, groupKey []byte) ([]string, error)

func (*Client) GetIDCard added in v0.0.6

func (c *Client) GetIDCard(ctx context.Context, h []byte) (*cryptutil.IDCard, error)

GetIDCard returns the ID card for the given hash

func (*Client) GetIDCardBin added in v0.0.6

func (c *Client) GetIDCardBin(ctx context.Context, h []byte) ([]byte, error)

GetIDCardBin returns the binary ID card for the given hash

func (*Client) GetIDCardForRecipient added in v0.0.6

func (c *Client) GetIDCardForRecipient(ctx context.Context, rcv string) (*cryptutil.IDCard, error)

GetIDCardForRecipient returns the ID Card of a given recipient, if any

func (*Client) IDCard added in v0.0.6

func (c *Client) IDCard() *cryptutil.IDCard

IDCard returns our own IDCard

func (*Client) ListenPacket added in v0.1.4

func (c *Client) ListenPacket(name string) (net.PacketConn, error)

ListenPacket returns a net.PacketConn object that can be used to easily exchange encrypted packets with other peers without having to think about the underlying parts.

func (*Client) Query added in v0.0.3

func (c *Client) Query(ctx context.Context, target string, body []byte) ([]byte, error)

Query sends a request & waits for the response. If the target is a key (starts with k:) the message will be encrypted & signed so only the recipient can open it.

func (*Client) QueryTimeout added in v0.0.6

func (c *Client) QueryTimeout(timeout time.Duration, target string, body []byte) ([]byte, error)

QueryTimeout calls Query with the specified timeout

func (*Client) SendTo added in v0.0.6

func (c *Client) SendTo(ctx context.Context, target string, payload []byte) error

SendTo encrypts and sends a payload to the given target

func (*Client) SendToWithFrom added in v0.1.4

func (c *Client) SendToWithFrom(ctx context.Context, target string, payload []byte, from string) error

SendToWithFrom encrypts and sends a payload to the given target, with the option to set the sender endpoint

func (*Client) SetHandler added in v0.0.6

func (c *Client) SetHandler(endpoint string, handler MessageHandler)

func (*Client) TargetId added in v0.0.4

func (c *Client) TargetId() string

TargetId returns the local client ID that can be used to transmit messages

func (*Client) WaitOnline added in v0.2.1

func (c *Client) WaitOnline()

type InstantMessage added in v0.0.3

type InstantMessage struct {
	ID        uuid.UUID
	Flags     uint64
	Recipient string
	Sender    string
	Body      []byte
	Encrypted bool
	SignedBy  [][]byte // contains the public keys that signed the message when decoding
}

func DecodeInstantMessage added in v0.0.3

func DecodeInstantMessage(buf []byte, res *cryptutil.OpenResult, err error) (*InstantMessage, error)

DecodeInstantMessage will return a InstantMessage for a given bottle, after checking the source and various details

func (*InstantMessage) Bottle added in v0.0.3

func (im *InstantMessage) Bottle() *cryptutil.Bottle

func (*InstantMessage) Bytes added in v0.0.3

func (im *InstantMessage) Bytes() []byte

func (*InstantMessage) MarshalBinary added in v0.0.3

func (im *InstantMessage) MarshalBinary() ([]byte, error)

func (*InstantMessage) ReadFrom added in v0.0.3

func (im *InstantMessage) ReadFrom(r io.Reader) (int64, error)

func (*InstantMessage) UnmarshalBinary added in v0.0.3

func (im *InstantMessage) UnmarshalBinary(r []byte) error

type MessageHandler added in v0.0.6

type MessageHandler func(msg *spotproto.Message) ([]byte, error)

type SpotAddr added in v0.1.4

type SpotAddr string

SpotAddr is a type implementing net.Addr that represents a spot address (typically, k:xxx/yyy)

func (SpotAddr) Network added in v0.1.4

func (s SpotAddr) Network() string

func (SpotAddr) String added in v0.1.4

func (s SpotAddr) String() string

Jump to

Keyboard shortcuts

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