hub

package
v0.2.1 Latest Latest
Warning

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

Go to latest
Published: Aug 10, 2020 License: AGPL-3.0 Imports: 18 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// AllHubs is the database scope for saving Hubs
	AllHubs = "cache:spn/hubs/"

	// LocalHubs is the database scope for local hubs
	LocalHubs = AllHubs + "local/"

	// PublicHubs is the database scope for public hubs
	PublicHubs = AllHubs + "public/"

	// RawMsgsScope is for storing raw msgs. The path spec for this scope is cache:spn/rawMsgs/<scope>/<msgType>/<ID>
	RawMsgsScope = "cache:spn/rawMsgs/"
)
View Source
var (
	// ErrMissingInfo signifies that the hub is missing the HubAnnouncement.
	ErrMissingInfo = errors.New("hub is missing Announcement")

	// ErrMissingTransports signifies that the hub announcement did not specify any transports.
	ErrMissingTransports = errors.New("hub announcement is missing transports")

	// ErrMissingIPs signifies that the hub announcement did not specify any IPs.
	ErrMissingIPs = errors.New("hub announcement is missing IPs")

	// ErrTemporaryValidationError is returned when a validation error might be temporary.
	ErrTemporaryValidationError = errors.New("temporary validation error")
)

Functions

func ConnectionsEqual

func ConnectionsEqual(a, b []*HubConnection) bool

ConnectionsEqual returns whether the given []*HubConnection are equal.

func CreateHubSignet

func CreateHubSignet(toolID string, securityLevel int) (private, public *jess.Signet, err error)

CreateHubSignet creates a signet with the correct ID for usage as a Hub Identity.

func ImportAnnouncement

func ImportAnnouncement(data []byte, scope Scope) error

ImportAnnouncement imports an announcement if it passes all the checks.

func ImportStatus

func ImportStatus(data []byte, scope Scope) error

ImportStatus imports a status update if it passes all the checks.

func RemoveHub

func RemoveHub(scope Scope, id string) error

RemoveHub deletes a Hub from the database.

func SaveRawHubMsg

func SaveRawHubMsg(id string, scope Scope, msgType string, data []byte) error

SaveRawHubMsg saves a raw (and signed) message received by another Hub.

func SetHubIPValidationFn

func SetHubIPValidationFn(fn func(hub *Hub, ip net.IP) error)

SetHubIPValidationFn sets the function that is used to validate the IP of a Hub.

func SetNavigatorAccess

func SetNavigatorAccess(fn func(id string) *Hub)

SetNavigatorAccess sets a shortcut function to access hubs from the navigator instead of having go through the database. This also reduces the number of object in RAM and better caches parsed attributes.

func SignHubMsg

func SignHubMsg(msg []byte, env *jess.Envelope, enableTofu bool) ([]byte, error)

SignHubMsg signs the given serialized hub msg with the given configuration.

func SortConnections

func SortConnections(c []*HubConnection)

SortConnections sorts a slice of HubConnections.

Types

type Hub

type Hub struct {
	sync.Mutex
	record.Base

	ID        string
	PublicKey *jess.Signet

	Scope  Scope
	Info   *HubAnnouncement
	Status *HubStatus

	FirstSeen time.Time
}

Hub represents a network node in the SPN.

func EnsureHub

func EnsureHub(r record.Record) (*Hub, error)

EnsureHub makes sure a database record is a Hub.

func GetHub

func GetHub(scope Scope, id string) (*Hub, error)

GetHub get a Hub from the database - or the navigator, if configured.

func OpenHubMsg

func OpenHubMsg(data []byte, scope Scope, tofu bool) (msg []byte, sendingHub *Hub, err error)

OpenHubMsg opens a signed hub msg and verifies the signature using the local database. If TOFU is enabled, the signature is always accepted, if valid.

func (*Hub) AddConnection

func (h *Hub) AddConnection(newConn *HubConnection) error

AddConnection adds a new Hub Connection to the Hub Status.

func (*Hub) GetSignet

func (h *Hub) GetSignet(id string, recipient bool) (*jess.Signet, error)

GetSignet returns the public key identified by the given ID from the Hub Status.

func (*Hub) RemoveConnection

func (h *Hub) RemoveConnection(hubID string) error

RemoveConnection removes a Hub Connection from the Hub Status.

func (*Hub) Save

func (hub *Hub) Save() error

Save saves to Hub to the correct scope in the database.

func (*Hub) SelectSignet

func (h *Hub) SelectSignet() *jess.Signet

SelectSignet selects the public key to use for initiating connections to that Hub.

func (*Hub) String

func (h *Hub) String() string

String returns a human-readable representation of a Hub.

type HubAnnouncement

type HubAnnouncement struct {

	// Primary Key
	// hash of public key
	// must be checked if it matches the public key
	ID string // via jess.LabeledHash

	// PublicKey *jess.Signet
	// PublicKey // if not part of signature
	// Signature *jess.Letter
	Timestamp int64 // Unix timestamp in seconds

	// Node Information
	Name           string // name of the node
	Group          string // person or organisation, who is in control of the node (should be same for all nodes of this person or organisation)
	ContactAddress string // contact possibility  (recommended, but optional)
	ContactService string // type of service of the contact address, if not email

	// currently unused, but collected for later use
	Hosters    []string // hoster supply chain (reseller, hosting provider, datacenter operator, ...)
	Datacenter string   // datacenter will be bullshit checked

	// Network Location and Access
	// If node is behind NAT (or similar), IP addresses must be configured
	IPv4       net.IP // must be global and accessible
	IPv6       net.IP // must be global and accessible
	Transports []string

	// Policies - default permit
	Entry []string
	// {"+ ", "- *"}
	Exit []string
}

HubAnnouncement is the main message type to publish Hub Information. This only changes if updated manually.

func (*HubAnnouncement) Equal

func (a *HubAnnouncement) Equal(b *HubAnnouncement) bool

Equal returns whether the given Announcements are equal.

func (*HubAnnouncement) Export

func (ha *HubAnnouncement) Export(env *jess.Envelope) ([]byte, error)

Export exports the announcement with the given signature configuration.

type HubConnection

type HubConnection struct {
	ID       string // ID of peer
	Capacity int    // max available bandwidth in Mbit/s (measure actively!)
	Latency  int    // ping in msecs
}

HubConnection represents a link to another Hub.

func (*HubConnection) Equal

func (c *HubConnection) Equal(other *HubConnection) bool

Equal returns whether the HubConnection is equal to the given one.

func (*HubConnection) String

func (c *HubConnection) String() string

type HubKey

type HubKey struct {
	Scheme  string
	Key     []byte
	Expires int64
}

HubKey represents a semi-ephemeral public key used for 0-RTT connection establishment.

type HubMsg

type HubMsg struct {
	record.Base
	sync.Mutex

	ID    string
	Scope Scope
	Type  string
	Data  []byte

	Received int64
}

HubMsg stores raw Hub messages.

func EnsureHubMsg

func EnsureHubMsg(r record.Record) (*HubMsg, error)

EnsureHubMsg makes sure a database record is a HubMsg.

type HubStatus

type HubStatus struct {
	Timestamp int64

	// Routing Information
	Keys        map[string]*HubKey // public keys (with type)
	Connections []*HubConnection

	// Load describes max(CPU, Memory) in percent, averages over the last hour
	// only update if change is significant in terms of impact on routing
	// do not update more often than once an hour
	Load int
}

HubStatus is the message type used to update changing Hub Information. Changes are made automatically.

func (*HubStatus) Export

func (hs *HubStatus) Export(env *jess.Envelope) ([]byte, error)

Export exports the status with the given signature configuration.

type Scope

type Scope uint8

Scope is the network scope a Hub can be in.

const (
	// ScopeInvalid defines an invalid scope
	ScopeInvalid Scope = 0

	// ScopeLocal identifies local Hubs
	ScopeLocal Scope = 1

	// ScopePublic identifies public Hubs
	ScopePublic Scope = 2

	// ScopeTest identifies Hubs for testing
	ScopeTest Scope = 0xFF
)

func (Scope) String

func (s Scope) String() string

String returns the string representation of the scope.

type SingleTrustStore

type SingleTrustStore struct {
	Signet *jess.Signet
}

SingleTrustStore is a simple truststore that always returns the same Signet.

func (*SingleTrustStore) GetSignet

func (ts *SingleTrustStore) GetSignet(_ string, _ bool) (*jess.Signet, error)

GetSignet implements the truststore interface.

type Transport

type Transport struct {
	Protocol string
	Domain   string
	Port     uint16
	Path     string
	Option   string
}

Transport represents a "endpoint" that others can connect to. This allows for use of different protocols, ports and infrastructure integration.

func ParseTransport

func ParseTransport(definition string) (*Transport, error)

ParseTransport parses a transport definition.

func (*Transport) String

func (t *Transport) String() string

String returns the definition form of the transport.

Jump to

Keyboard shortcuts

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