Documentation
¶
Index ¶
- Constants
- func FormatRequest(r Request) string
- func FormatResponseA(name string, addr protocol.Addr) string
- func FormatResponseErr(msg string) string
- func FormatResponseN(name string, netID uint16) string
- func FormatResponseOK() string
- func FormatResponseS(entries []ServiceEntry) string
- type Client
- func (c *Client) LookupA(name string) (protocol.Addr, error)
- func (c *Client) LookupN(name string) (uint16, error)
- func (c *Client) LookupS(networkID, port uint16) ([]ServiceEntry, error)
- func (c *Client) RegisterA(name string, addr protocol.Addr) error
- func (c *Client) RegisterN(name string, netID uint16) error
- func (c *Client) RegisterS(name string, addr protocol.Addr, networkID, port uint16) error
- type Record
- type RecordStore
- func (rs *RecordStore) AllA() map[string]protocol.Addr
- func (rs *RecordStore) Close()
- func (rs *RecordStore) LookupA(name string) (protocol.Addr, error)
- func (rs *RecordStore) LookupN(name string) (uint16, error)
- func (rs *RecordStore) LookupS(networkID, port uint16) []ServiceEntry
- func (rs *RecordStore) RegisterA(name string, addr protocol.Addr)
- func (rs *RecordStore) RegisterN(name string, netID uint16)
- func (rs *RecordStore) RegisterS(name string, addr protocol.Addr, networkID, port uint16)
- func (rs *RecordStore) SetStorePath(path string)
- func (rs *RecordStore) UnregisterA(name string)
- type Request
- type Response
- type Server
- type ServiceEntry
Constants ¶
const ( RecordA = "A" // Name → Virtual Address RecordN = "N" // Network name → Network ID RecordS = "S" // Service discovery )
Record types
const DefaultRecordTTL = 5 * time.Minute
Default TTL for nameserver records.
Variables ¶
This section is empty.
Functions ¶
func FormatRequest ¶
FormatRequest serializes a request to wire format.
func FormatResponseA ¶
FormatResponseA formats an A record response.
func FormatResponseErr ¶
FormatResponseErr formats an error response.
func FormatResponseN ¶
FormatResponseN formats an N record response.
func FormatResponseS ¶
func FormatResponseS(entries []ServiceEntry) string
FormatResponseS formats S record responses (one line per entry).
Types ¶
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client queries a Pilot Protocol nameserver over the overlay.
func NewClient ¶
NewClient creates a nameserver client that will query the given nameserver address.
func (*Client) LookupS ¶
func (c *Client) LookupS(networkID, port uint16) ([]ServiceEntry, error)
LookupS finds services on a network+port.
type Record ¶
type Record struct {
Type string `json:"type"`
Name string `json:"name"`
Address string `json:"address,omitempty"` // for A records
NetID uint16 `json:"network_id,omitempty"` // for N records
Port uint16 `json:"port,omitempty"` // for S records
NodeID uint32 `json:"node_id,omitempty"` // for S records (who registered it)
}
Record is a name record in the nameserver.
type RecordStore ¶
type RecordStore struct {
// contains filtered or unexported fields
}
RecordStore holds all nameserver records in memory.
func NewRecordStore ¶
func NewRecordStore() *RecordStore
func (*RecordStore) AllA ¶
func (rs *RecordStore) AllA() map[string]protocol.Addr
AllA returns all A records.
func (*RecordStore) LookupA ¶
func (rs *RecordStore) LookupA(name string) (protocol.Addr, error)
LookupA resolves a name to an address.
func (*RecordStore) LookupN ¶
func (rs *RecordStore) LookupN(name string) (uint16, error)
LookupN resolves a network name to a network ID.
func (*RecordStore) LookupS ¶
func (rs *RecordStore) LookupS(networkID, port uint16) []ServiceEntry
LookupS finds service providers on a network+port.
func (*RecordStore) RegisterA ¶
func (rs *RecordStore) RegisterA(name string, addr protocol.Addr)
RegisterA adds or updates an A record (name → address).
func (*RecordStore) RegisterN ¶
func (rs *RecordStore) RegisterN(name string, netID uint16)
RegisterN adds a network name record.
func (*RecordStore) RegisterS ¶
func (rs *RecordStore) RegisterS(name string, addr protocol.Addr, networkID, port uint16)
RegisterS registers a service provider.
func (*RecordStore) SetStorePath ¶
func (rs *RecordStore) SetStorePath(path string)
SetStorePath enables persistence to the given file path and loads existing data.
func (*RecordStore) UnregisterA ¶
func (rs *RecordStore) UnregisterA(name string)
UnregisterA removes an A record.
type Request ¶
type Request struct {
Command string // "QUERY" or "REGISTER"
RecordType string // "A", "N", "S"
Name string
Address string // for A and S
NetID uint16 // for N and S
Port uint16 // for S
}
Request is a parsed nameserver request.
func ParseRequest ¶
ParseRequest parses a plain-text nameserver request.
type Response ¶
type Response struct {
Type string // "A", "N", "S", "OK", "ERR"
Name string
Address string
NetID uint16
Port uint16
Services []ServiceEntry // for S responses
Error string // for ERR responses
}
Response is a nameserver response.
func ParseResponse ¶
ParseResponse parses a plain-text nameserver response.
type Server ¶
type Server struct {
// contains filtered or unexported fields
}
Server is the Pilot Protocol nameserver. It runs on the overlay network itself, listening on port 53.
func New ¶
New creates a nameserver backed by a fresh record store. If storePath is non-empty, records are persisted to that file.
func (*Server) ListenAndServe ¶
ListenAndServe listens on Pilot port 53 and handles name queries.
func (*Server) Ready ¶
func (s *Server) Ready() <-chan struct{}
Ready returns a channel that is closed once the server is listening.
func (*Server) Store ¶
func (s *Server) Store() *RecordStore
Store returns the underlying record store for external manipulation.