config

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Mar 10, 2024 License: BSD-3-Clause Imports: 17 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// DefaultTunMTU is used for tun devices.
	DefaultTunMTU = 9000

	// DefaultFrameSize is the default expected frame size based on the default tun mtu.
	DefaultFrameSize = DefaultTunMTU - IPv6HeaderMTUSize - TCPHeaderMTUSize - LinkFrameSize - FrameSizeEncrypted
)
View Source
const (
	BaseMTU           = 1480 // 1500 with 20 bytes a little extra space for special cases.
	IPv4HeaderMTUSize = 20   // Without options, as not common.
	IPv6HeaderMTUSize = 40   // Without options, as not common.
	TCPHeaderMTUSize  = 20   // Base size with no options.
	UDPHeaderMTUSize  = 8    // Has no options.

	FrameSizeEncrypted = 80 // With 12 byte switch block. TODO: Source better.
	LinkFrameSize      = 32 // TODO: Source better.
)

MTU Calculation Configuration.

View Source
const DefaultPortNumber = 47369 // M(1+3), Y(2+5), C(3), O(1+5), R(1+8); 0xB909

DefaultPortNumber is the default port number used by Mycoria.

Variables

View Source
var DefaultAPIAddress = netip.MustParseAddr("fd00::b909")

DefaultAPIAddress is the default local API address used by Mycoria.

View Source
var DefaultDotTLD = ".myco"

DefaultDotTLD is the default TLD that Mycoria uses, but with a dot prefix.

View Source
var DefaultTLD = "myco"

DefaultTLD is the default TLD that Mycoria uses.

View Source
var DefaultTLDBetweenDots = ".myco."

DefaultTLDBetweenDots is the default TLD that Mycoria uses, but between dots.

Functions

func CalculateExpectedFrameSize

func CalculateExpectedFrameSize(addr net.Addr) int

CalculateExpectedFrameSize calculates the overlay MTU based on the given address.

func CleanDomain added in v0.1.0

func CleanDomain(domain string) (cleaned string, valid bool)

CleanDomain cleans the given domain and also returns if it is valid.

Types

type Config

type Config struct {
	Store

	APIListen netip.AddrPort

	Friends       []Friend
	FriendsByName map[string]Friend
	FriendsByIP   map[netip.Addr]Friend

	Services []Service
	Resolve  map[string]netip.Addr
	// contains filtered or unexported fields
}

Config holds initialized configuration.

func LoadConfig

func LoadConfig(filename string) (*Config, error)

LoadConfig loads the config from the given file.

func MakeTestConfig

func MakeTestConfig(s Store) *Config

MakeTestConfig parses and returns the given config store with loosened checks. If anything fails, it panics.

func (*Config) CheckInboundTrafficPolicy

func (c *Config) CheckInboundTrafficPolicy(protocol uint8, dstPort uint16, src netip.Addr) (allowed bool)

CheckInboundTrafficPolicy checks if the given inbound traffic is allowed.

func (*Config) DevMode added in v0.1.0

func (c *Config) DevMode() bool

DevMode returns if the development mode is enabled.

func (*Config) GetRouterInfo

func (c *Config) GetRouterInfo() *m.RouterInfo

GetRouterInfo retruns a new router info derived from config.

func (*Config) OverlayFrameSize

func (c *Config) OverlayFrameSize() int

OverlayFrameSize returns the expected maximum frame size for overlay network links.

func (*Config) SaveTo

func (c *Config) SaveTo(filename string) error

SaveTo write the config to the given file.

func (*Config) SetDevMode added in v0.1.0

func (c *Config) SetDevMode(mode bool)

SetDevMode sets the development mode.

func (*Config) SetOverlayFrameSize

func (c *Config) SetOverlayFrameSize(mtu int)

SetOverlayFrameSize sets the expected maximum frame size for overlay network links.

func (*Config) SetTunMTU

func (c *Config) SetTunMTU(mtu int)

SetTunMTU sets the MTU to be used for tun devices.

func (*Config) Started added in v0.1.0

func (c *Config) Started() time.Time

Started returns the time when the router was started. Measured by when the config was created.

func (*Config) TunMTU

func (c *Config) TunMTU() int

TunMTU returns the MTU to be used for tun devices.

func (*Config) Uptime added in v0.1.0

func (c *Config) Uptime() time.Duration

Uptime returns the time since the router was started. Measured by when the config was created.

type Friend

type Friend struct {
	Name string
	IP   netip.Addr
}

Friend is a trusted router in the network.

type FriendConfig

type FriendConfig struct {
	Name string `json:"name,omitempty" yaml:"name,omitempty"`
	IP   string `json:"ip,omitempty"   yaml:"ip,omitempty"`
}

FriendConfig is a trusted router in the network.

type Router

type Router struct {
	// Address it the identity of the router.
	Address m.AddressStorage `json:"address,omitempty" yaml:"address,omitempty"`

	// Universe holds the "universe" the router is in.
	Universe       string `json:"universe,omitempty"       yaml:"universe,omitempty"`
	UniverseSecret string `json:"universeSecret,omitempty" yaml:"universeSecret,omitempty"`

	// Isolate constrains outgoing traffic to friends.
	Isolate bool `json:"isolate,omitempty" yaml:"isolate,omitempty"`

	// Listen holds the peering URLs to listen on.
	// URLs must have an IP address as host.
	Listen []string `json:"listen,omitempty" yaml:"listen,omitempty"`

	// IANA holds a list of domains or IPs assigne by IANA through which the router can be reached.
	IANA []string `json:"iana,omitempty" yaml:"iana,omitempty"`

	// Connect holds the peering URLs the router
	// tries to always hold a connection to.
	Connect []string `json:"connect,omitempty" yaml:"connect,omitempty"`

	// AutoConnect specifies whether the router should automatically peer with
	// other routers (based on live usage data) to improve network flow.
	AutoConnect bool `json:"autoConnect,omitempty" yaml:"autoConnect,omitempty"`

	// Bootstrap holds peering URLs that the router uses to bootstrap to the network.
	Bootstrap []string `json:"bootstrap,omitempty" yaml:"bootstrap,omitempty"`

	// Stub runs the router in stub mode. It will not relay router announcements
	// and will appear as a dead end to other routers.
	Stub bool `json:"stub,omitempty" yaml:"stub,omitempty"`

	// Lite runs the router in lite mode. It will attempt to reduce any
	// non-essential activity and traffic.
	// Behavior will slightly change over time and also depends on other routers
	// playing along - do not use for workarounds.
	Lite bool `json:"lite,omitempty" yaml:"lite,omitempty"`
}

Router defines all configuration regarding the overlay network itself.

type Service

type Service struct {
	Name        string
	Description string
	Domain      string
	URL         string

	Public  bool
	Friends bool
	For     []netip.Addr

	Advertise bool
}

Service defines an endpoint other routers can send traffic to.

type ServiceConfig

type ServiceConfig struct {
	Name        string `json:"name,omitempty"        yaml:"name,omitempty"`
	Description string `json:"description,omitempty" yaml:"description,omitempty"`
	Domain      string `json:"domain,omitempty"      yaml:"domain,omitempty"`
	URL         string `json:"url,omitempty"         yaml:"url,omitempty"`

	// Access Control
	Public  bool     `json:"public,omitempty"  yaml:"public,omitempty"`
	Friends bool     `json:"friends,omitempty" yaml:"friends,omitempty"`
	For     []string `json:"for,omitempty"     yaml:"for,omitempty"`

	Advertise bool `json:"advertise,omitempty" yaml:"advertise,omitempty"`
}

ServiceConfig defines an endpoint other routers can send traffic to.

type Store

type Store struct {
	Router Router `json:"router,omitempty" yaml:"router,omitempty"`
	System System `json:"system,omitempty" yaml:"system,omitempty"`

	ServiceConfigs []ServiceConfig   `json:"services,omitempty" yaml:"services,omitempty"`
	FriendConfigs  []FriendConfig    `json:"friends,omitempty"  yaml:"friends,omitempty"`
	ResolveConfig  map[string]string `json:"resolve,omitempty"  yaml:"resolve,omitempty"`
}

Store holds all configuration in a storable format.

func (Store) Clone added in v0.1.0

func (s Store) Clone() (Store, error)

Clone returns a full copy the store.

func (Store) Parse

func (s Store) Parse() (*Config, error)

Parse parses a config definition and return an initialized config.

type System

type System struct {
	TunName    string `json:"tunName,omitempty"    yaml:"tunName,omitempty"`
	DisableTun bool   `json:"disableTun,omitempty" yaml:"disableTun,omitempty"`
	APIListen  string `json:"apiListen,omitempty"  yaml:"apiListen,omitempty"`
	StatePath  string `json:"statePath,omitempty"  yaml:"statePath,omitempty"`

	DisableChromiumWorkaround bool `json:"disableChromiumWorkaround,omitempty" yaml:"disableChromiumWorkaround,omitempty"`
}

System defines all configuration regarding the system.

Jump to

Keyboard shortcuts

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