mirror of
https://github.com/luxfi/node.git
synced 2026-10-30 15:24:05 +00:00
The module already called itself github.com/luxfi/node while containing no node in Go: cmd/luxd was twenty-one lines that printed the size of a few types, and the Go column of the matrix measured a VM plugin. A repo that fetches the thing it claims to be has not replaced it, so the Go sources move in — 1515 files, the daemon and everything under it — and the build reaches outside this module for nothing. Rust and C++ sit beside it unchanged and are still measured against it by the differential. That is the point of one repo: the reference implementation and the two ports are the same checkout, so parity is a thing you can run rather than a thing you assert. Verified: builds, and the closure carries no lux-private — checked at build time rather than believed. The daemon starts twelve chains on a local network (P X C Q Z A B G K M F, plus D through its plugin) and reports healthy.
73 lines
1.3 KiB
Go
73 lines
1.3 KiB
Go
// Copyright (C) 2019-2025, Lux Industries Inc. All rights reserved.
|
|
// See the file LICENSE for licensing terms.
|
|
|
|
package nat
|
|
|
|
import (
|
|
"errors"
|
|
"net"
|
|
"net/netip"
|
|
"time"
|
|
)
|
|
|
|
var (
|
|
_ Router = (*noRouter)(nil)
|
|
|
|
errNoRouterCantMapPorts = errors.New("can't map ports without a known router")
|
|
errFetchingIP = errors.New("getting outbound IP failed")
|
|
)
|
|
|
|
const googleDNSServer = "8.8.8.8:80"
|
|
|
|
type noRouter struct {
|
|
ip netip.Addr
|
|
ipErr error
|
|
}
|
|
|
|
func (noRouter) SupportsNAT() bool {
|
|
return false
|
|
}
|
|
|
|
func (noRouter) MapPort(uint16, uint16, string, time.Duration) error {
|
|
return errNoRouterCantMapPorts
|
|
}
|
|
|
|
func (noRouter) UnmapPort(uint16, uint16) error {
|
|
return nil
|
|
}
|
|
|
|
func (r noRouter) ExternalIP() (netip.Addr, error) {
|
|
return r.ip, r.ipErr
|
|
}
|
|
|
|
func getOutboundIP() (netip.Addr, error) {
|
|
conn, err := net.Dial("udp", googleDNSServer)
|
|
if err != nil {
|
|
return netip.Addr{}, err
|
|
}
|
|
|
|
localAddr := conn.LocalAddr()
|
|
if err := conn.Close(); err != nil {
|
|
return netip.Addr{}, err
|
|
}
|
|
|
|
udpAddr, ok := localAddr.(*net.UDPAddr)
|
|
if !ok {
|
|
return netip.Addr{}, errFetchingIP
|
|
}
|
|
addr := udpAddr.AddrPort().Addr()
|
|
if addr.Is4In6() {
|
|
addr = addr.Unmap()
|
|
}
|
|
return addr, nil
|
|
}
|
|
|
|
// NewNoRouter returns a router that assumes the network is public
|
|
func NewNoRouter() Router {
|
|
ip, err := getOutboundIP()
|
|
return &noRouter{
|
|
ip: ip,
|
|
ipErr: err,
|
|
}
|
|
}
|