Documentation
¶
Index ¶
- func WithTimeout(ctx context.Context, timeout time.Duration, cb func(context.Context))
- type Client
- func (c *Client) Close() error
- func (c *Client) ConnectionCount() (uint32, uint32)
- func (c *Client) FetchBlob(ctx context.Context, key string) ([]byte, error)
- func (c *Client) GetGroupMembers(ctx context.Context, groupKey []byte) ([]string, error)
- func (c *Client) GetIDCard(ctx context.Context, h []byte) (*cryptutil.IDCard, error)
- func (c *Client) GetIDCardBin(ctx context.Context, h []byte) ([]byte, error)
- func (c *Client) GetIDCardForRecipient(ctx context.Context, rcv string) (*cryptutil.IDCard, error)
- func (c *Client) GetTime(ctx context.Context) (time.Time, error)
- func (c *Client) IDCard() *cryptutil.IDCard
- func (c *Client) ListenPacket(name string) (net.PacketConn, error)
- func (c *Client) Query(ctx context.Context, target string, body []byte) ([]byte, error)
- func (c *Client) QueryTimeout(timeout time.Duration, target string, body []byte) ([]byte, error)
- func (c *Client) SendTo(ctx context.Context, target string, payload []byte) error
- func (c *Client) SendToWithFrom(ctx context.Context, target string, payload []byte, from string) error
- func (c *Client) SetHandler(endpoint string, handler MessageHandler)
- func (c *Client) StoreBlob(ctx context.Context, key string, value []byte) error
- func (c *Client) TargetId() string
- func (c *Client) WaitOnline(ctx context.Context) error
- type InstantMessage
- type MessageHandler
- type SpotAddr
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func WithTimeout ¶ added in v0.2.3
WithTimeout makes it easy to call a method that requires a context with a specified timeout without having to worry about calling the cancel() method. Go typically suggests using defer, however if processing after a given method is called continues, there is a risk the cancel method will be called much later.
This method on the other hand performs the defer of cancel, which means that cancel will be called properly even in case of a panic.
Usage:
spotlib.WithTimeout(nil, 30*time.Second, func(ctx context.Context) { res, err = c.methodWithCtx(ctx) }
if err := nil { ...
Types ¶
type Client ¶ added in v0.0.3
Client holds information about a client, including its connections to the spot servers
func New ¶ added in v0.0.3
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) ConnectionCount ¶ added in v0.0.4
ConnectionCount returns the number of spot server connections, and the number of said connections which are online (ie. past the handshake step).
func (*Client) FetchBlob ¶ added in v0.2.9
FetchBlob fetches a blob previously stored with StoreBlob. The operation can be slow and is provided as best effort. The data will be decrypted and verified.
func (*Client) GetGroupMembers ¶ added in v0.1.3
func (*Client) GetIDCardBin ¶ added in v0.0.6
GetIDCardBin returns the binary ID card for the given hash
func (*Client) GetIDCardForRecipient ¶ added in v0.0.6
GetIDCardForRecipient returns the ID Card of a given recipient, if any
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
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
QueryTimeout calls Query with the specified timeout
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) StoreBlob ¶ added in v0.2.9
StoreBlob stores the given value under the given key after encrypting it in a way that can only be retrieved by this client specifically, using the same private key. This can be useful to store some settings local to the node that may need to be re-obtained, however this method is to be considered best-effort and shouldn't be used for intensive storage activity. Note also that value will have a limit of slightly less than 49kB.
Data may also be purged after some time without access.
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