Documentation
¶
Index ¶
- Variables
- func NewID() string
- func SetLogger(l Logger)
- type Content
- type ContentType
- type ContextLogger
- type LogLevel
- type Logger
- type Message
- type MessageType
- type Status
- type Vault
- type Wormhole
- func (w *Wormhole) Close()
- func (w *Wormhole) Connect(ctx context.Context, sender keys.ID, recipient keys.ID, offer *sctp.Addr) error
- func (w *Wormhole) CreateInvite(ctx context.Context, sender keys.ID, recipient keys.ID) (string, error)
- func (w *Wormhole) CreateLocalOffer(ctx context.Context, sender keys.ID, recipient keys.ID) (*sctp.Addr, error)
- func (w *Wormhole) CreateOffer(ctx context.Context, sender keys.ID, recipient keys.ID) (*sctp.Addr, error)
- func (w *Wormhole) FindInviteCode(ctx context.Context, code string) (*api.InviteCodeResponse, error)
- func (w *Wormhole) FindOffer(ctx context.Context, recipient keys.ID, sender keys.ID) (*sctp.Addr, error)
- func (w *Wormhole) Listen(ctx context.Context, sender keys.ID, recipient keys.ID, offer *sctp.Addr) error
- func (w *Wormhole) OnStatus(f func(Status))
- func (w *Wormhole) Read(ctx context.Context) ([]byte, error)
- func (w *Wormhole) ReadMessage(ctx context.Context, ack bool) (*Message, error)
- func (w *Wormhole) SetClock(clock tsutil.Clock)
- func (w *Wormhole) Write(ctx context.Context, b []byte) error
- func (w *Wormhole) WriteMessage(ctx context.Context, id string, b []byte, contentType ContentType) (*Message, error)
Constants ¶
This section is empty.
Variables ¶
var ErrClosed = errors.New("closed")
ErrClosed if we recieve closed message.
var ErrNoResponse = errors.New("no response")
ErrNoResponse error if offer not found for recipient.
var ErrNoiseHandshakeTimeout = errors.New("noise handshake timeout")
ErrNoiseHandshakeTimeout if we timed out during handshake
Functions ¶
Types ¶
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.
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.
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 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 ¶
Wormhole for connecting two participants using webrtc, noise and keys.pub.
func New ¶
New creates a new Wormhole. Server is offer/answer message server, only used to coordinate starting the webrtc channel.
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) ReadMessage ¶
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) WriteMessage ¶
func (w *Wormhole) WriteMessage(ctx context.Context, id string, b []byte, contentType ContentType) (*Message, error)
WriteMessage writes a message.