wormhole

package module
v0.0.0-...-c1743e4 Latest Latest
Warning

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

Go to latest
Published: Jan 11, 2024 License: MIT Imports: 13 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrClosed = errors.New("closed")

ErrClosed if we recieve closed message.

View Source
var ErrNoResponse = errors.New("no response")

ErrNoResponse error if offer not found for recipient.

View Source
var ErrNoiseHandshakeTimeout = errors.New("noise handshake timeout")

ErrNoiseHandshakeTimeout if we timed out during handshake

Functions

func NewID

func NewID() string

NewID creates new ID for wormhole messages.

func SetLogger

func SetLogger(l Logger)

SetLogger sets logger for the package.

Types

type Content

type Content struct {
	Data []byte
	Type ContentType
}

Content for message.

type ContentType

type ContentType string

ContentType describes the content type.

const BinaryContent ContentType = "binary"

BinaryContent for binary content.

const UTF8Content ContentType = "utf8"

UTF8Content is UTF8.

type ContextLogger

type ContextLogger interface {
	Debugf(ctx context.Context, format string, args ...interface{})
	Infof(ctx context.Context, format string, args ...interface{})
	Warningf(ctx context.Context, format string, args ...interface{})
	Errorf(ctx context.Context, format string, args ...interface{})
}

ContextLogger interface used in this package with request context.

func NewContextLogger

func NewContextLogger(lev LogLevel) ContextLogger

NewContextLogger ...

type LogLevel

type LogLevel int

LogLevel ...

const (
	// DebugLevel ...
	DebugLevel LogLevel = 3
	// InfoLevel ...
	InfoLevel LogLevel = 2
	// WarnLevel ...
	WarnLevel LogLevel = 1
	// ErrLevel ...
	ErrLevel LogLevel = 0
)

func (LogLevel) String

func (l LogLevel) String() string

type Logger

type Logger interface {
	Debugf(format string, args ...interface{})
	Infof(format string, args ...interface{})
	Warningf(format string, args ...interface{})
	Errorf(format string, args ...interface{})
	Fatalf(format string, args ...interface{})
}

Logger interface used in this package.

func NewLogger

func NewLogger(lev LogLevel) Logger

NewLogger ...

type Message

type Message struct {
	ID        string
	Sender    keys.ID
	Recipient keys.ID
	Content   *Content
	Type      MessageType
}

Message for wormhole.

type MessageType

type MessageType string

MessageType describes wormhole message.

const (
	// Sent for a sent message.
	Sent MessageType = "sent"
	// Pending for a pending message.
	Pending MessageType = "pending"
	// Ack for an acknowledgement.
	Ack MessageType = "ack"
)

type Status

type Status string

Status describes the status of the wormhole connection.

const (
	// SCTPHandshake is attempting to SCTP handshake.
	SCTPHandshake Status = "sctp-handshake"
	// NoiseHandshake is attempting to Noise handshake.
	NoiseHandshake Status = "noise-handshake"
	// Connected ...
	Connected Status = "open"
	// Closed ...
	Closed Status = "closed"
)

type Vault

type Vault interface {
	EdX25519Key(id keys.ID) (*keys.EdX25519Key, error)
	EdX25519Keys() ([]*keys.EdX25519Key, error)
}

Vault is interface for keys.

func NewVault

func NewVault(keys ...*keys.EdX25519Key) Vault

NewVault creates a vault (for testing).

type Wormhole

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

Wormhole for connecting two participants using webrtc, noise and keys.pub.

func New

func New(server string, vault Vault) (*Wormhole, error)

New creates a new Wormhole. Server is offer/answer message server, only used to coordinate starting the webrtc channel.

func (*Wormhole) Close

func (w *Wormhole) Close()

Close wormhole.

func (*Wormhole) Connect

func (w *Wormhole) Connect(ctx context.Context, sender keys.ID, recipient keys.ID, offer *sctp.Addr) error

Connect with an offer.

func (*Wormhole) CreateInvite

func (w *Wormhole) CreateInvite(ctx context.Context, sender keys.ID, recipient keys.ID) (string, error)

CreateInvite creates an invite code for sender/recipient.

func (*Wormhole) CreateLocalOffer

func (w *Wormhole) CreateLocalOffer(ctx context.Context, sender keys.ID, recipient keys.ID) (*sctp.Addr, error)

CreateLocalOffer creates a local offer for testing.

func (*Wormhole) CreateOffer

func (w *Wormhole) CreateOffer(ctx context.Context, sender keys.ID, recipient keys.ID) (*sctp.Addr, error)

CreateOffer creates an offer.

func (*Wormhole) FindInviteCode

func (w *Wormhole) FindInviteCode(ctx context.Context, code string) (*api.InviteCodeResponse, error)

FindInviteCode looks for an invite.

func (*Wormhole) FindOffer

func (w *Wormhole) FindOffer(ctx context.Context, recipient keys.ID, sender keys.ID) (*sctp.Addr, error)

FindOffer looks for an offer from the discovery server.

func (*Wormhole) Listen

func (w *Wormhole) Listen(ctx context.Context, sender keys.ID, recipient keys.ID, offer *sctp.Addr) error

Listen to offer.

func (*Wormhole) OnStatus

func (w *Wormhole) OnStatus(f func(Status))

OnStatus registers status listener.

func (*Wormhole) Read

func (w *Wormhole) Read(ctx context.Context) ([]byte, error)

Read.

func (*Wormhole) ReadMessage

func (w *Wormhole) ReadMessage(ctx context.Context, ack bool) (*Message, error)

ReadMessage reads a message. If ack, will send an ack (unless this message is an ack). If we received a message that the recipient closed, we return ErrClosed.

func (*Wormhole) SetClock

func (w *Wormhole) SetClock(clock tsutil.Clock)

SetClock sets wormhole clock.

func (*Wormhole) Write

func (w *Wormhole) Write(ctx context.Context, b []byte) error

Write data.

func (*Wormhole) WriteMessage

func (w *Wormhole) WriteMessage(ctx context.Context, id string, b []byte, contentType ContentType) (*Message, error)

WriteMessage writes a message.

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

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