nameserver

package
v1.2.2 Latest Latest
Warning

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

Go to latest
Published: Feb 17, 2026 License: AGPL-3.0 Imports: 13 Imported by: 0

Documentation

Index

Constants

View Source
const (
	RecordA = "A" // Name → Virtual Address
	RecordN = "N" // Network name → Network ID
	RecordS = "S" // Service discovery
)

Record types

View Source
const DefaultRecordTTL = 5 * time.Minute

Default TTL for nameserver records.

Variables

This section is empty.

Functions

func FormatRequest

func FormatRequest(r Request) string

FormatRequest serializes a request to wire format.

func FormatResponseA

func FormatResponseA(name string, addr protocol.Addr) string

FormatResponseA formats an A record response.

func FormatResponseErr

func FormatResponseErr(msg string) string

FormatResponseErr formats an error response.

func FormatResponseN

func FormatResponseN(name string, netID uint16) string

FormatResponseN formats an N record response.

func FormatResponseOK

func FormatResponseOK() string

FormatResponseOK formats a success 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

func NewClient(d *driver.Driver, nsAddr protocol.Addr) *Client

NewClient creates a nameserver client that will query the given nameserver address.

func (*Client) LookupA

func (c *Client) LookupA(name string) (protocol.Addr, error)

LookupA resolves a name to a virtual address.

func (*Client) LookupN

func (c *Client) LookupN(name string) (uint16, error)

LookupN resolves a network name to a network ID.

func (*Client) LookupS

func (c *Client) LookupS(networkID, port uint16) ([]ServiceEntry, error)

LookupS finds services on a network+port.

func (*Client) RegisterA

func (c *Client) RegisterA(name string, addr protocol.Addr) error

RegisterA registers a name → address mapping.

func (*Client) RegisterN

func (c *Client) RegisterN(name string, netID uint16) error

RegisterN registers a network name → network ID mapping.

func (*Client) RegisterS

func (c *Client) RegisterS(name string, addr protocol.Addr, networkID, port uint16) error

RegisterS registers a service.

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) Close

func (rs *RecordStore) Close()

Close stops the reaper goroutine.

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

func ParseRequest(line string) (Request, error)

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

func ParseResponse(text string) (Response, error)

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

func New(d *driver.Driver, storePath string) *Server

New creates a nameserver backed by a fresh record store. If storePath is non-empty, records are persisted to that file.

func (*Server) Close

func (s *Server) Close() error

Close shuts down the nameserver.

func (*Server) ListenAndServe

func (s *Server) ListenAndServe() error

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.

type ServiceEntry

type ServiceEntry struct {
	Name      string        `json:"name"`
	Address   protocol.Addr `json:"address"`
	Port      uint16        `json:"port"`
	CreatedAt time.Time     `json:"-"` // for TTL expiry (L6 fix)
}

ServiceEntry is a provider of a service.

Jump to

Keyboard shortcuts

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