discover

package
v0.12.0-beta0 Latest Latest
Warning

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

Go to latest
Published: Aug 20, 2015 License: MPL-2.0 Imports: 21 Imported by: 0

Documentation

Overview

Package discover implements the device discovery protocol.

Index

Constants

View Source
const (
	AnnouncementMagic = 0x9D79BC40
	QueryMagic        = 0x2CA856F6
)

Variables

View Source
var (
	DefaultErrorRetryInternval     = 60 * time.Second
	DefaultGlobalBroadcastInterval = 1800 * time.Second
)
View Source
var (
	ErrIncorrectMagic = errors.New("incorrect magic number")
)

Functions

func Register

func Register(proto string, factory Factory)

Types

type Announce

type Announce struct {
	Magic uint32
	This  Device
	Extra []Device // max:16
}

func (Announce) AppendXDR

func (o Announce) AppendXDR(bs []byte) ([]byte, error)

func (*Announce) DecodeXDR

func (o *Announce) DecodeXDR(r io.Reader) error

func (*Announce) DecodeXDRFrom

func (o *Announce) DecodeXDRFrom(xr *xdr.Reader) error

func (Announce) EncodeXDR

func (o Announce) EncodeXDR(w io.Writer) (int, error)

func (Announce) EncodeXDRInto

func (o Announce) EncodeXDRInto(xw *xdr.Writer) (int, error)

func (Announce) MarshalXDR

func (o Announce) MarshalXDR() ([]byte, error)

func (Announce) MustMarshalXDR

func (o Announce) MustMarshalXDR() []byte

func (*Announce) UnmarshalXDR

func (o *Announce) UnmarshalXDR(bs []byte) error

type Announcer

type Announcer interface {
	Announcement() Announce
}

type CacheEntry

type CacheEntry struct {
	Address string
	Seen    time.Time
}

type Client

type Client interface {
	Lookup(device protocol.DeviceID) (Announce, error)
	StatusOK() bool
	Address() string
	Stop()
}

func New

func New(addr string, announcer Announcer) (Client, error)

type Device

type Device struct {
	ID        []byte   // max:32
	Addresses []string // max:16
	Relays    []Relay  // max:16
}

func (Device) AppendXDR

func (o Device) AppendXDR(bs []byte) ([]byte, error)

func (*Device) DecodeXDR

func (o *Device) DecodeXDR(r io.Reader) error

func (*Device) DecodeXDRFrom

func (o *Device) DecodeXDRFrom(xr *xdr.Reader) error

func (Device) EncodeXDR

func (o Device) EncodeXDR(w io.Writer) (int, error)

func (Device) EncodeXDRInto

func (o Device) EncodeXDRInto(xw *xdr.Writer) (int, error)

func (Device) MarshalXDR

func (o Device) MarshalXDR() ([]byte, error)

func (Device) MustMarshalXDR

func (o Device) MustMarshalXDR() []byte

func (*Device) UnmarshalXDR

func (o *Device) UnmarshalXDR(bs []byte) error

type Discoverer

type Discoverer struct {
	// contains filtered or unexported fields
}

func NewDiscoverer

func NewDiscoverer(id protocol.DeviceID, addresses []string, relaySvc *relay.Svc) *Discoverer

func (*Discoverer) All

func (d *Discoverer) All() map[protocol.DeviceID][]CacheEntry

func (*Discoverer) Announcement

func (d *Discoverer) Announcement() Announce

func (*Discoverer) ExtAnnounceOK

func (d *Discoverer) ExtAnnounceOK() map[string]bool

func (*Discoverer) Hint

func (d *Discoverer) Hint(device string, addrs []string)

func (*Discoverer) Lookup

func (d *Discoverer) Lookup(device protocol.DeviceID) ([]string, []string)

Lookup returns a list of addresses the device is available at, as well as a list of relays the device is supposed to be available on sorted by the sum of latencies between this device, and the device in question.

func (*Discoverer) StartGlobal

func (d *Discoverer) StartGlobal(servers []string, extPort uint16)

func (*Discoverer) StartLocal

func (d *Discoverer) StartLocal(localPort int, localMCAddr string)

func (*Discoverer) StopGlobal

func (d *Discoverer) StopGlobal()

type Factory

type Factory func(*url.URL, Announcer) (Client, error)

type Query

type Query struct {
	Magic    uint32
	DeviceID []byte // max:32
}

func (Query) AppendXDR

func (o Query) AppendXDR(bs []byte) ([]byte, error)

func (*Query) DecodeXDR

func (o *Query) DecodeXDR(r io.Reader) error

func (*Query) DecodeXDRFrom

func (o *Query) DecodeXDRFrom(xr *xdr.Reader) error

func (Query) EncodeXDR

func (o Query) EncodeXDR(w io.Writer) (int, error)

func (Query) EncodeXDRInto

func (o Query) EncodeXDRInto(xw *xdr.Writer) (int, error)

func (Query) MarshalXDR

func (o Query) MarshalXDR() ([]byte, error)

func (Query) MustMarshalXDR

func (o Query) MustMarshalXDR() []byte

func (*Query) UnmarshalXDR

func (o *Query) UnmarshalXDR(bs []byte) error

type Relay

type Relay struct {
	Address string // max:256
	Latency int32
}

func (Relay) AppendXDR

func (o Relay) AppendXDR(bs []byte) ([]byte, error)

func (*Relay) DecodeXDR

func (o *Relay) DecodeXDR(r io.Reader) error

func (*Relay) DecodeXDRFrom

func (o *Relay) DecodeXDRFrom(xr *xdr.Reader) error

func (Relay) EncodeXDR

func (o Relay) EncodeXDR(w io.Writer) (int, error)

func (Relay) EncodeXDRInto

func (o Relay) EncodeXDRInto(xw *xdr.Writer) (int, error)

func (Relay) MarshalXDR

func (o Relay) MarshalXDR() ([]byte, error)

func (Relay) MustMarshalXDR

func (o Relay) MustMarshalXDR() []byte

func (*Relay) UnmarshalXDR

func (o *Relay) UnmarshalXDR(bs []byte) error

type UDPClient

type UDPClient struct {
	// contains filtered or unexported fields
}

func (*UDPClient) Address

func (d *UDPClient) Address() string

func (*UDPClient) Lookup

func (d *UDPClient) Lookup(device protocol.DeviceID) (Announce, error)

func (*UDPClient) Start

func (d *UDPClient) Start(uri *url.URL) error

func (*UDPClient) StatusOK

func (d *UDPClient) StatusOK() bool

func (*UDPClient) Stop

func (d *UDPClient) Stop()

Jump to

Keyboard shortcuts

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