Documentation
¶
Overview ¶
Package endpointticket encodes and decodes Rust-compatible iroh endpoint tickets.
An endpoint ticket is a compact string form of an endpoint address for out-of-band sharing. The string starts with "endpoint" followed by lowercase base32 without padding.
The Go API is not stable before v1 and may change in any v0 release.
Index ¶
- Constants
- Variables
- func Decode(s string) (netaddr.EndpointAddr, error)
- func Encode(addr netaddr.EndpointAddr) string
- func EncodeString(t TicketCodec) string
- func RegisterEndpoint(r *Registry) error
- func ShortAddr(addr netaddr.EndpointAddr) netaddr.EndpointAddr
- type Decoder
- type ParseError
- type ParseErrorKind
- type Registry
- type Ticket
- func (t Ticket) Addr() netaddr.EndpointAddr
- func (t Ticket) EncodeBytes() []byte
- func (t Ticket) EncodeString() string
- func (t Ticket) Kind() string
- func (t Ticket) MarshalText() ([]byte, error)
- func (t Ticket) Short() Ticket
- func (t Ticket) String() string
- func (t *Ticket) UnmarshalText(text []byte) error
- type TicketCodec
Examples ¶
Constants ¶
const ( // Kind is the string prefix for endpoint tickets. Kind = "endpoint" // MaxAddrs is the maximum number of addresses accepted in a ticket. // It is a memory-exhaustion guard, not a wire-compatibility limit. MaxAddrs = 65536 )
Variables ¶
var ( // ErrTrailingBytes is returned when a ticket has extra data after the // endpoint address. ErrTrailingBytes = errors.New("endpoint ticket: trailing bytes") // ErrTruncated is returned when a ticket ends before a complete field. ErrTruncated = errors.New("endpoint ticket: truncated") // ErrVarintOverflow is returned when a varint field exceeds 64 bits. ErrVarintOverflow = errors.New("endpoint ticket: varint overflow") )
var ( // ErrMissingPrefix is returned when a ticket does not start with // "endpoint". ErrMissingPrefix = &ParseError{Kind: ParseErrorKindKind, Expected: Kind} // ErrEncoding is returned when the ticket payload is not valid base32. ErrEncoding = &ParseError{Kind: ParseErrorKindEncoding} // ErrDecode is returned when the decoded bytes are not a valid endpoint // ticket payload. ErrDecode = &ParseError{Kind: ParseErrorKindPostcard} // ErrVerify is returned when decoded bytes fail semantic validation. ErrVerify = &ParseError{Kind: ParseErrorKindVerify} )
Functions ¶
func Decode ¶
func Decode(s string) (netaddr.EndpointAddr, error)
Decode parses s as an endpoint ticket and returns its endpoint address.
Example ¶
package main
import (
"fmt"
"github.com/tmc/go-iroh/endpointticket"
)
func main() {
addr, err := endpointticket.Decode("endpointacxfr74igmsbvsbnn73wcecg5vt3kbzncqwfrdiampuufwnhkublmaqacbuhi5dqhixs6zdfojyc43lffyxqcad7aaaadaai")
if err != nil {
panic(err)
}
fmt.Println(addr.ID)
fmt.Println(len(addr.Addrs()))
}
Output: ae58ff8833241ac82d6ff7611046ed67b5072d142c588d0063e942d9a75502b6 2
func Encode ¶
func Encode(addr netaddr.EndpointAddr) string
Encode returns the ticket string for addr.
func EncodeString ¶
func EncodeString(t TicketCodec) string
EncodeString returns t's canonical string form.
func RegisterEndpoint ¶
RegisterEndpoint registers the endpoint ticket decoder in r.
func ShortAddr ¶
func ShortAddr(addr netaddr.EndpointAddr) netaddr.EndpointAddr
ShortAddr returns addr with direct IP and custom addresses removed.
Types ¶
type Decoder ¶
type Decoder func([]byte) (TicketCodec, error)
Decoder decodes a ticket from its byte representation.
type ParseError ¶
type ParseError struct {
Kind ParseErrorKind
Expected string
Message string
Err error
}
ParseError reports a structured ticket parse failure.
func (*ParseError) Error ¶
func (e *ParseError) Error() string
func (*ParseError) Is ¶
func (e *ParseError) Is(target error) bool
func (*ParseError) Unwrap ¶
func (e *ParseError) Unwrap() error
type ParseErrorKind ¶
type ParseErrorKind string
ParseErrorKind classifies ticket parse failures.
const ( // ParseErrorKindKind means the ticket string had the wrong kind prefix. ParseErrorKindKind ParseErrorKind = "kind" // ParseErrorKindEncoding means the ticket payload was not valid base32. ParseErrorKindEncoding ParseErrorKind = "encoding" // ParseErrorKindPostcard means the payload looked like this ticket kind but // did not decode as the ticket byte format. ParseErrorKindPostcard ParseErrorKind = "postcard" // ParseErrorKindVerify means decoded bytes failed semantic validation. ParseErrorKindVerify ParseErrorKind = "verify" )
type Registry ¶
type Registry struct {
// contains filtered or unexported fields
}
Registry decodes tickets by kind.
func NewRegistry ¶
func NewRegistry() *Registry
NewRegistry returns an empty ticket decoder registry.
func (*Registry) DecodeBytes ¶
func (r *Registry) DecodeBytes(kind string, b []byte) (TicketCodec, error)
DecodeBytes decodes bytes as a ticket of kind.
func (*Registry) DecodeString ¶
func (r *Registry) DecodeString(s string) (TicketCodec, error)
DecodeString decodes s using the registered kind prefix.
type Ticket ¶
type Ticket struct {
// contains filtered or unexported fields
}
Ticket is an endpoint ticket.
func DecodeBytes ¶
DecodeBytes decodes an endpoint ticket from its byte representation.
func DecodeString ¶
DecodeString parses s as an endpoint ticket.
func Short ¶
func Short(addr netaddr.EndpointAddr) Ticket
Short returns a ticket for addr containing only the endpoint id and relay URLs.
func (Ticket) Addr ¶
func (t Ticket) Addr() netaddr.EndpointAddr
Addr returns the endpoint address in t.
func (Ticket) EncodeBytes ¶
EncodeBytes returns the ticket's byte representation.
func (Ticket) EncodeString ¶
EncodeString returns the encoded ticket string.
func (Ticket) MarshalText ¶
MarshalText implements encoding.TextMarshaler.
func (*Ticket) UnmarshalText ¶
UnmarshalText implements encoding.TextUnmarshaler.
type TicketCodec ¶
TicketCodec is the generic shape of an iroh ticket implementation.
It mirrors Rust's iroh_tickets::Ticket trait: a ticket has a lowercase kind prefix, a byte representation, and a canonical string form of kind plus base32-without-padding bytes.