core

package
v0.4.7-0...-66ca820 Latest Latest
Warning

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

Go to latest
Published: Jan 18, 2023 License: LGPL-3.0 Imports: 32 Imported by: 5

Documentation

Overview

Package address contains the types used by mesh to represent IPv6 addresses or prefixes, as well as functions for working with these types. Of particular importance are the functions used to derive addresses or subnets from a NodeID, or to get the NodeID and bitmask of the bits visible from an address, which is needed for DHT searches.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AddHandler

type AddHandler interface {
	AddHandler(name, desc string, args []string, handlerfunc AddHandlerFunc) error
}

type AddHandlerFunc

type AddHandlerFunc func(json.RawMessage) (interface{}, error)

type Address

type Address [16]byte

Address represents an IPv6 address in the mesh address range.

type AllowedPublicKey

type AllowedPublicKey ed25519.PublicKey

type Core

type Core struct {
	// This is the main data structure that holds everything else for a node
	// We're going to keep our own copy of the provided config - that way we can
	// guarantee that it will be covered by the mutex
	phony.Inbox
	*iwe.PacketConn

	PeersChangedSignal signals.Signal
	// contains filtered or unexported fields
}

The Core object represents the Mesh node. You should create a Core object for each Mesh node you plan to run.

func New

func New(secret ed25519.PrivateKey, logger Logger, opts ...SetupOption) (*Core, error)

func (*Core) AddPeer

func (c *Core) AddPeer(uri string, sourceInterface string) error

func (*Core) AddrForKey

func (c *Core) AddrForKey(publicKey ed25519.PublicKey) *Address

AddrForKey takes an ed25519.PublicKey as an argument and returns an *Address. This function returns nil if the key length is not ed25519.PublicKeySize. This address begins with the contents of GetPrefix(), with the last bit set to 0 to indicate an address. The following 8 bits are set to the number of leading 1 bits in the bitwise inverse of the public key. The bitwise inverse of the key, excluding the leading 1 bits and the first leading 0 bit, is truncated to the appropriate length and makes up the remainder of the address.

func (*Core) Address

func (c *Core) Address() net.IP

Address gets the IPv6 address of the Mesh node. This is always a /128 address. The IPv6 address is only relevant when the node is operating as an IP router and often is meaningless when embedded into an application, unless that application also implements either VPN functionality or deals with IP packets specifically.

func (*Core) CallPeer

func (c *Core) CallPeer(u *url.URL, sintf string) error

CallPeer calls a peer once. This should be specified in the peer URI format, e.g.:

tcp://a.b.c.d:e
socks://a.b.c.d:e/f.g.h.i:j

This does not add the peer to the peer list, so if the connection drops, the peer will not be called again automatically.

func (*Core) GetAddressKey

func (c *Core) GetAddressKey(a Address) ed25519.PublicKey

GetKet returns the partial ed25519.PublicKey for the Address. This is used for key lookup.

func (*Core) GetDHT

func (c *Core) GetDHT() []DHTEntryInfo

func (*Core) GetNodeInfo

func (c *Core) GetNodeInfo(key string) (result map[string]any, err error)

func (*Core) GetPaths

func (c *Core) GetPaths() []PathEntryInfo

func (*Core) GetPeers

func (c *Core) GetPeers() []PeerInfo

func (*Core) GetPrefix

func (c *Core) GetPrefix() [1]byte

GetPrefix returns the address prefix used by mesh. The current implementation requires this to be a multiple of 8 bits + 7 bits. The 8th bit of the last byte is used to signal nodes (0) or /64 prefixes (1). Nodes that configure this differently will be unable to communicate with each other using IP packets, though routing and the DHT machinery *should* still work.

func (*Core) GetSelf

func (c *Core) GetSelf() SelfInfo

func (*Core) GetSessions

func (c *Core) GetSessions() []SessionInfo

func (*Core) GetSubnetKey

func (c *Core) GetSubnetKey(s Subnet) ed25519.PublicKey

GetKet returns the partial ed25519.PublicKey for the Subnet. This is used for key lookup.

func (*Core) IsValidAddress

func (c *Core) IsValidAddress(a Address) bool

IsValid returns true if an address falls within the range used by nodes in the network.

func (*Core) IsValidSubnet

func (c *Core) IsValidSubnet(s Subnet) bool

IsValid returns true if a prefix falls within the range usable by the network.

func (*Core) Listen

func (c *Core) Listen(u *url.URL, sintf string) (*Listener, error)

Listen starts a new listener (either TCP or TLS). The input should be a url.URL parsed from a string of the form e.g. "tcp://a.b.c.d:e". In the case of a link-local address, the interface should be provided as the second argument.

func (*Core) MTU

func (c *Core) MTU() uint64

func (*Core) PublicKey

func (c *Core) PublicKey() ed25519.PublicKey

func (*Core) ReadFrom

func (c *Core) ReadFrom(p []byte) (n int, from net.Addr, err error)

func (*Core) RemoteGetDHT

func (c *Core) RemoteGetDHT(key string) (map[string]any, error)

func (*Core) RemoteGetPeers

func (c *Core) RemoteGetPeers(key string) (map[string]any, error)

func (*Core) RemoteGetSelf

func (c *Core) RemoteGetSelf(key string) (map[string]any, error)

func (*Core) RemovePeer

func (c *Core) RemovePeer(uri string, sourceInterface string) error

func (*Core) RemovePeers

func (c *Core) RemovePeers() error

func (*Core) RetryPeersNow

func (c *Core) RetryPeersNow()

func (*Core) SetAdmin

func (c *Core) SetAdmin(a AddHandler) error

SetAdmin must be called after Init and before Start. It sets the admin handler for NodeInfo and the Debug admin functions.

func (*Core) SetLogger

func (c *Core) SetLogger(log Logger)

SetLogger sets the output logger of the Mesh node after startup. This may be useful if you want to redirect the output later. Note that this expects a Logger from the github.com/gologme/log package and not from Go's built-in log package.

func (*Core) Stop

func (c *Core) Stop()

Stop shuts down the Mesh node.

func (*Core) Subnet

func (c *Core) Subnet() net.IPNet

Subnet gets the routed IPv6 subnet of the Mesh node. This is always a /64 subnet. The IPv6 subnet is only relevant when the node is operating as an IP router and often is meaningless when embedded into an application, unless that application also implements either VPN functionality or deals with IP packets specifically.

func (*Core) SubnetForKey

func (c *Core) SubnetForKey(publicKey ed25519.PublicKey) *Subnet

SubnetForKey takes an ed25519.PublicKey as an argument and returns a *Subnet. This function returns nil if the key length is not ed25519.PublicKeySize. The subnet begins with the address prefix, with the last bit set to 1 to indicate a prefix. The following 8 bits are set to the number of leading 1 bits in the bitwise inverse of the key. The bitwise inverse of the key, excluding the leading 1 bits and the first leading 0 bit, is truncated to the appropriate length and makes up the remainder of the subnet.

func (*Core) WriteTo

func (c *Core) WriteTo(p []byte, addr net.Addr) (n int, err error)

type DHTEntryInfo

type DHTEntryInfo struct {
	Key  ed25519.PublicKey
	Port uint64
	Rest uint64
}

type DebugGetDHTRequest

type DebugGetDHTRequest struct {
	Key string `json:"key"`
}

type DebugGetDHTResponse

type DebugGetDHTResponse map[string]interface{}

type DebugGetPeersRequest

type DebugGetPeersRequest struct {
	Key string `json:"key"`
}

type DebugGetPeersResponse

type DebugGetPeersResponse map[string]interface{}

type DebugGetSelfRequest

type DebugGetSelfRequest struct {
	Key string `json:"key"`
}

type DebugGetSelfResponse

type DebugGetSelfResponse map[string]interface{}

type GetNodeInfoRequest

type GetNodeInfoRequest struct {
	Key string `json:"key"`
}

type GetNodeInfoResponse

type GetNodeInfoResponse map[string]json.RawMessage

type ListenAddress

type ListenAddress string

type Listener

type Listener struct {
	net.Listener
	// contains filtered or unexported fields
}

func (*Listener) Close

func (l *Listener) Close() error

type Logger

type Logger interface {
	Printf(string, ...interface{})
	Println(...interface{})
	Infof(string, ...interface{})
	Infoln(...interface{})
	Warnf(string, ...interface{})
	Warnln(...interface{})
	Errorf(string, ...interface{})
	Errorln(...interface{})
	Debugf(string, ...interface{})
	Debugln(...interface{})
}

type NetworkDomain

type NetworkDomain struct {
	Prefix string
}

type NodeInfo

type NodeInfo map[string]interface{}

type NodeInfoPrivacy

type NodeInfoPrivacy bool

type PathEntryInfo

type PathEntryInfo struct {
	Key  ed25519.PublicKey
	Path []uint64
}

type Peer

type Peer struct {
	URI             string
	SourceInterface string
}

type PeerInfo

type PeerInfo struct {
	Key      ed25519.PublicKey
	Root     ed25519.PublicKey
	Coords   []uint64
	Port     uint64
	Priority uint8
	Remote   string
	RXBytes  uint64
	TXBytes  uint64
	Uptime   time.Duration
	RemoteIp string
}

type SelfInfo

type SelfInfo struct {
	Key        ed25519.PublicKey
	Root       ed25519.PublicKey
	PrivateKey ed25519.PrivateKey
	Coords     []uint64
}

type SessionInfo

type SessionInfo struct {
	Key     ed25519.PublicKey
	RXBytes uint64
	TXBytes uint64
	Uptime  time.Duration
}

type SetupOption

type SetupOption interface {
	// contains filtered or unexported methods
}

type Subnet

type Subnet [8]byte

Subnet represents an IPv6 /64 subnet in the mesh subnet range.

Jump to

Keyboard shortcuts

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