nameserver

package module
v0.2.1 Latest Latest
Warning

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

Go to latest
Published: May 29, 2026 License: AGPL-3.0 Imports: 14 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

nameserver

ci codecov

Nameserver plugin for the Pilot Protocol daemon. Resolves human-readable hostnames to virtual pilot addresses over the overlay (port 53). Supports A records (hostname to address), N records (network name to network ID), and S records (service discovery).

Install

import "github.com/pilot-protocol/nameserver"

Usage

s := nameserver.NewService(nameserver.Config{
    StorePath: "~/.pilot/records.json",
})
rt.Register(s)

Layout

File What it does
wire.go DNS-like wire format: query/response frames over the pilot stream.
records.go RecordStore — JSON-backed record store and lookup index.
server.go Accept loop and per-query dispatch.
client.go Lookup, Register — caller-side helpers.
service.go *Service — coreapi.Service adapter. Build tag !no_nameserver.
service_disabled.go Stub when build tag no_nameserver is set.

Build tags

Tag Effect
no_nameserver Compiles a stub whose Start is a no-op.

License

AGPL-3.0-or-later. See LICENSE.

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 Dialer, 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 Dialer

type Dialer interface {
	DialAddrTimeout(dst protocol.Addr, port uint16, timeout time.Duration) (net.Conn, error)
}

Dialer abstracts the ability to open a connection to a Pilot overlay address. Satisfied by *driver.Driver (via a thin wrapper in cmd/nameserver).

type PortListener

type PortListener interface {
	Listen(port uint16) (net.Listener, error)
}

PortListener abstracts the ability to listen on a Pilot overlay port. Satisfied by *driver.Driver (via a thin wrapper in cmd/nameserver).

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

func (rs *RecordStore) Reap()

Reap forces an immediate removal of expired records.

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

func (rs *RecordStore) SetTTL(d time.Duration)

SetTTL overrides the default record TTL.

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.

Trust boundary note: the nameserver responds to DNS queries from any registered node without trust gating. This is intentional — DNS is a public lookup service (like real-world DNS), and hostname→address mappings are not considered private. Private nodes are protected at the resolve/connect layer, not at name resolution.

func New

func New(pl PortListener, 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 Service

type Service struct{}

Service is the L11 plugin lifecycle adapter for the nameserver. The daemon does not register this today — cmd/nameserver is a standalone binary that uses nameserver.New / *Server.ListenAndServe directly. The adapter exists so the plugin package conforms to the L10 Service contract and so the no_nameserver build tag has a meaningful counterpart (see service_disabled.go).

When this plugin is eventually wired into cmd/daemon's plugin runtime, this Service will own the *Server lifecycle. Today its Start/Stop are no-ops; it is registered nowhere.

func NewService

func NewService() *Service

NewService returns a Service ready for daemon.RegisterPlugin (when cmd/daemon eventually starts registering it). Distinct from nameserver.New, which constructs the standalone *Server used by cmd/nameserver.

func (*Service) Name

func (s *Service) Name() string

func (*Service) Order

func (s *Service) Order() int

func (*Service) Start

func (s *Service) Start(_ context.Context, _ coreapi.Deps) error

func (*Service) Stop

func (s *Service) Stop(_ context.Context) error

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