Documentation
¶
Index ¶
- Variables
- func CollectPeers(static []string, timeout time.Duration, maxParallel int) ([]string, error)
- func DialTCP(peerIPv6 string, port int) (net.Conn, error)
- func DialUDP(peerIPv6 string, port int) (net.PacketConn, error)
- func FilterAlivePeers(peers []string, timeout time.Duration, maxParallel int) []string
- func ListenTCP(port int) (net.Listener, error)
- func ListenUDP(port int) (net.PacketConn, error)
- func PrepareYggConfig(app *AppConfig) (*ycfg.NodeConfig, error)
- func SaveJSON(path string, v any) error
- func SetConnectivityHandler(h ConnectivityHandler)
- func SetMaxPeers(n int)
- func SetVerbose(v bool)
- type AppConfig
- type ConnectivityHandler
- type Netstack
- func (ns *Netstack) Addr() net.IP
- func (ns *Netstack) AddrString() string
- func (ns *Netstack) Close() error
- func (ns *Netstack) DialTCP(peerIPv6 string, port int, timeout time.Duration) (net.Conn, error)
- func (ns *Netstack) DialUDP(peerIPv6 string, port int, timeout time.Duration) (net.PacketConn, tcpip.FullAddress, error)
- func (ns *Netstack) ListenTCP(port int) (net.Listener, error)
- func (ns *Netstack) ListenUDP(port int) (net.PacketConn, error)
- type Node
- func (n *Node) Close() error
- func (n *Node) Connected() bool
- func (n *Node) DialTCP(peerIPv6 string, port int) (net.Conn, error)
- func (n *Node) ListenTCP(port int) (net.Listener, error)
- func (n *Node) StartNetstack() (*Netstack, error)
- func (n *Node) WaitConnected(ctx context.Context, interval time.Duration) error
Constants ¶
This section is empty.
Variables ¶
var ErrNotConnected = errors.New("ygg: not connected")
ErrNotConnected is returned when an operation requires an active Ygg link (at least one Up peer), but the node currently has none.
Functions ¶
func CollectPeers ¶
func DialUDP ¶
func DialUDP(peerIPv6 string, port int) (net.PacketConn, error)
DialUDP dials a peer over the current default node's user-space netstack and returns a connected PacketConn (Write/Read without specifying addr each time).
func FilterAlivePeers ¶
FilterAlivePeers checks peer availability and returns only those considered "alive". For http/https - perform HTTP GET with InsecureTLS; for other schemes - TCP dial to host:port.
func ListenUDP ¶
func ListenUDP(port int) (net.PacketConn, error)
ListenUDP listens on the current default node's user-space netstack and returns a PacketConn bound to our Ygg IPv6 on the given port. Packets can be ReadFrom/WriteTo.
func PrepareYggConfig ¶
func PrepareYggConfig(app *AppConfig) (*ycfg.NodeConfig, error)
PrepareYggConfig generates or loads keys into ycfg.NodeConfig.
func SetConnectivityHandler ¶
func SetConnectivityHandler(h ConnectivityHandler)
SetConnectivityHandler installs a callback for connectivity state changes. The callback is invoked on a background goroutine.
func SetMaxPeers ¶
func SetMaxPeers(n int)
SetMaxPeers sets an upper bound on the number of peers to add at startup. If n <= 0, there is no limit.
func SetVerbose ¶
func SetVerbose(v bool)
SetVerbose enables or disables verbose logging from this package.
Types ¶
type AppConfig ¶
type AppConfig struct {
// Seed is the inline private key seed (empty => generate).
Seed string `json:"seed,omitempty"`
// Peers lists static peers (tcp://host:port, tls://..., quic://...).
Peers []string `json:"peers"`
// DialTimeoutSec controls connect timeouts.
DialTimeoutSec int `json:"dial_timeout_sec,omitempty"`
// contains filtered or unexported fields
}
func LoadOrInitAppConfig ¶
func (*AppConfig) MarshalJSON ¶
func (*AppConfig) UnmarshalJSON ¶
type ConnectivityHandler ¶
type ConnectivityHandler func(connected bool)
ConnectivityHandler is called whenever the node transitions between connected and disconnected states.
type Netstack ¶
type Netstack struct {
Stack *stack.Stack
NICID tcpip.NICID
// contains filtered or unexported fields
}
Netstack wraps an in-process gVisor TCP/IP stack bridged to the Yggdrasil core via ipv6rwc.
func (*Netstack) AddrString ¶
AddrString returns our Ygg IPv6 as string.
func (*Netstack) DialUDP ¶
func (ns *Netstack) DialUDP(peerIPv6 string, port int, timeout time.Duration) (net.PacketConn, tcpip.FullAddress, error)
DialUDP dials a remote Ygg IPv6 + port using UDP.
type Node ¶
type Node struct {
Core *ycore.Core
Config *ycfg.NodeConfig
Net *Netstack
// contains filtered or unexported fields
}
func New ¶
New initializes (or loads) configuration from cfgPath, discovers peers, starts an embedded Yggdrasil core, connects to alive peers, and returns the Node. If cfgPath is empty, a default location is chosen (next to the binary or ~/.config/say/config.json). The caller owns the returned Node and may stop it by calling Close().
func StartAndConnect ¶
StartAndConnect starts the core and connects to peers until the first one is up.
func (*Node) StartNetstack ¶
StartNetstack wires the Yggdrasil core to the gVisor netstack via an ipv6rwc/channel endpoint.
func (*Node) WaitConnected ¶
WaitConnected blocks until the node has at least one Up peer or the context is cancelled. The check runs at the given interval; if interval <= 0, 500ms is used. Returns nil when connected, ctx.Err() on cancellation/timeout.