Documentation ¶
Index ¶
- Constants
- Variables
- func CreateHubSignet(toolID string, securityLevel int) (private, public *jess.Signet, err error)
- func FlagsEqual(a, b []string) bool
- func LanesEqual(a, b []*Lane) bool
- func MakeHubDBKey(mapName, hubID string) string
- func MakeHubMsgDBKey(mapName string, msgType MsgType, hubID string) string
- func QueryRawGossipMsgs(mapName string, msgType MsgType) (it *iterator.Iterator, err error)
- func RemoveHubAndMsgs(mapName string, hubID string) (err error)
- func SaveHubMsg(id string, mapName string, msgType MsgType, data []byte) error
- func SetNavigatorAccess(fn func(mapName, hubID string) *Hub)
- func SignHubMsg(msg []byte, env *jess.Envelope, enableTofu bool) ([]byte, error)
- func SortLanes(l []*Lane)
- func SortTransports(ts []*Transport)
- type Announcement
- func (a *Announcement) Copy() *Announcement
- func (a *Announcement) EntryPolicy() endpoints.Endpoints
- func (a *Announcement) Equal(b *Announcement) bool
- func (a *Announcement) ExitPolicy() endpoints.Endpoints
- func (a *Announcement) Export(env *jess.Envelope) ([]byte, error)
- func (a *Announcement) HasFlag(flagName string) bool
- func (a *Announcement) ParsedTransports() []*Transport
- type Hub
- func ApplyAnnouncement(existingHub *Hub, data []byte, mapName string, scope Scope, selfcheck bool) (hub *Hub, known, changed bool, err error)
- func ApplyStatus(existingHub *Hub, data []byte, mapName string, scope Scope, selfcheck bool) (hub *Hub, known, changed bool, err error)
- func EnsureHub(r record.Record) (*Hub, error)
- func GetHub(mapName string, hubID string) (*Hub, error)
- func GetHubByKey(key string) (*Hub, error)
- func OpenHubMsg(hub *Hub, data []byte, mapName string, tofu bool) (msg []byte, sendingHub *Hub, known bool, err error)
- func (h *Hub) AddLane(newLane *Lane) error
- func (h *Hub) GetInfo() *Announcement
- func (h *Hub) GetLaneTo(hubID string) *Lane
- func (h *Hub) GetMeasurements() *Measurements
- func (h *Hub) GetMeasurementsWithLockedHub() *Measurements
- func (h *Hub) GetSignet(id string, recipient bool) (*jess.Signet, error)
- func (h *Hub) GetStatus() *Status
- func (h *Hub) HasFlag(flagName string) bool
- func (h *Hub) Name() string
- func (h *Hub) Obsolete() bool
- func (h *Hub) RemoveLane(hubID string) error
- func (h *Hub) Save() error
- func (h *Hub) SelectSignet() *jess.Signet
- func (h *Hub) String() string
- func (h *Hub) StringWithoutLocking() string
- func (h *Hub) Verified() bool
- type HubIntel
- type HubMsg
- type InfoOverride
- type Intel
- type Key
- type Lane
- type Measurements
- func (m *Measurements) Copy() *Measurements
- func (m *Measurements) Expired(ttl time.Duration) bool
- func (m *Measurements) GetCalculatedCost() (cost float32)
- func (m *Measurements) GetCapacity() (capacity int, measuredAt time.Time)
- func (m *Measurements) GetGeoProximity() (geoProximity float32)
- func (m *Measurements) GetLatency() (latency time.Duration, measuredAt time.Time)
- func (m *Measurements) IsPersisted() bool
- func (m *Measurements) SetCalculatedCost(cost float32)
- func (m *Measurements) SetCapacity(capacity int)
- func (m *Measurements) SetGeoProximity(geoProximity float32)
- func (m *Measurements) SetLatency(latency time.Duration)
- func (m *Measurements) Valid() bool
- type MsgType
- type ParsedIntel
- type RegionConfig
- type Scope
- type SingleTrustStore
- type Status
- type Transport
- type VirtualNetworkConfig
Constants ¶
const ( MsgTypeAnnouncement = "announcement" MsgTypeStatus = "status" )
Message Types.
const ( // FlagNetError signifies that the Hub reports a network connectivity failure or impairment. FlagNetError = "net-error" // FlagOffline signifies that the Hub has gone offline by itself. FlagOffline = "offline" // FlagAllowUnencrypted signifies that the Hub is available to handle unencrypted connections. FlagAllowUnencrypted = "allow-unencrypted" )
Status Flags.
const MaxCalculatedCost = 1000000
MaxCalculatedCost specifies the max calculated cost to be used for an unknown high cost.
const VersionOffline = "offline"
VersionOffline is a special version used to signify that the Hub has gone offline. This is depracated, please use FlagOffline instead.
Variables ¶
var ( // ErrMissingInfo signifies that the hub is missing the HubAnnouncement. ErrMissingInfo = errors.New("hub has no announcement") // ErrMissingTransports signifies that the hub announcement did not specify any transports. ErrMissingTransports = errors.New("hub announcement has no transports") // ErrMissingIPs signifies that the hub announcement did not specify any IPs, // or none of the IPs is supported by the client. ErrMissingIPs = errors.New("hub announcement has no (supported) IPs") // ErrTemporaryValidationError is returned when a validation error might be temporary. ErrTemporaryValidationError = errors.New("temporary validation error") // ErrOldData is returned when received data is outdated. ErrOldData = errors.New("") )
var BaselineCharset = regexp.MustCompile(
`^[` +
` !#()*+,\-\./0-9:=?@A-Z[\]^_a-z{|}~` +
`ŠŒŽšœžŸ¡¿ÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖØÙÚÛÜÝÞßàáâãäåæçèéêëìíîïðñòóôõöøùúûüýþÿ` +
`]*$`,
)
BaselineCharset defines the permitted characters.
Functions ¶
func CreateHubSignet ¶
CreateHubSignet creates a signet with the correct ID for usage as a Hub Identity.
func FlagsEqual ¶
FlagsEqual returns whether the given status flags are equal.
func LanesEqual ¶
LanesEqual returns whether the given []*Lane are equal.
func MakeHubDBKey ¶
MakeHubDBKey makes a hub db key.
func MakeHubMsgDBKey ¶
MakeHubMsgDBKey makes a hub msg db key.
func QueryRawGossipMsgs ¶
QueryRawGossipMsgs queries the database for raw gossip messages.
func RemoveHubAndMsgs ¶
RemoveHubAndMsgs deletes a Hub and it's saved messages from the database.
func SaveHubMsg ¶
SaveHubMsg saves a raw (and signed) message received by another Hub.
func SetNavigatorAccess ¶
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 ¶
SignHubMsg signs the given serialized hub msg with the given configuration.
func SortTransports ¶
func SortTransports(ts []*Transport)
SortTransports sorts the transports to emphasize certain protocols, but otherwise leaves the order intact.
Types ¶
type Announcement ¶
type Announcement struct { // Primary Key // hash of public key // must be checked if it matches the public key ID string `cbor:"i"` // via jess.LabeledHash // PublicKey *jess.Signet // PublicKey // if not part of signature // Signature *jess.Letter Timestamp int64 `cbor:"t"` // Unix timestamp in seconds // Node Information Name string `cbor:"n"` // name of the node Group string `cbor:"g,omitempty" json:",omitempty"` // person or organisation, who is in control of the node (should be same for all nodes of this person or organisation) ContactAddress string `cbor:"ca,omitempty" json:",omitempty"` // contact possibility (recommended, but optional) ContactService string `cbor:"cs,omitempty" json:",omitempty"` // type of service of the contact address, if not email // currently unused, but collected for later use Hosters []string `cbor:"ho,omitempty" json:",omitempty"` // hoster supply chain (reseller, hosting provider, datacenter operator, ...) Datacenter string `cbor:"dc,omitempty" json:",omitempty"` // datacenter will be bullshit checked // Network Location and Access // If node is behind NAT (or similar), IP addresses must be configured IPv4 net.IP `cbor:"ip4,omitempty" json:",omitempty"` // must be global and accessible IPv6 net.IP `cbor:"ip6,omitempty" json:",omitempty"` // must be global and accessible Transports []string `cbor:"tp,omitempty" json:",omitempty"` // Policies - default permit Entry []string `cbor:"pi,omitempty" json:",omitempty"` // {"+ ", "- *"} Exit []string `cbor:"po,omitempty" json:",omitempty"` // Flags holds flags that signify special states. Flags []string `cbor:"f,omitempty" json:",omitempty"` // contains filtered or unexported fields }
Announcement is the main message type to publish Hub Information. This only changes if updated manually.
func (*Announcement) Copy ¶
func (a *Announcement) Copy() *Announcement
Copy returns a deep copy of the Announcement.
func (*Announcement) EntryPolicy ¶
func (a *Announcement) EntryPolicy() endpoints.Endpoints
EntryPolicy returns the Hub's entry policy.
func (*Announcement) Equal ¶
func (a *Announcement) Equal(b *Announcement) bool
Equal returns whether the given Announcements are equal.
func (*Announcement) ExitPolicy ¶
func (a *Announcement) ExitPolicy() endpoints.Endpoints
ExitPolicy returns the Hub's exit policy.
func (*Announcement) Export ¶
func (a *Announcement) Export(env *jess.Envelope) ([]byte, error)
Export exports the announcement with the given signature configuration.
func (*Announcement) HasFlag ¶
func (a *Announcement) HasFlag(flagName string) bool
HasFlag returns whether the Announcement has the given flag set.
func (*Announcement) ParsedTransports ¶
func (a *Announcement) ParsedTransports() []*Transport
ParsedTransports returns the Hub's parsed transports.
type Hub ¶
type Hub struct { sync.Mutex record.Base ID string PublicKey *jess.Signet Map string Info *Announcement Status *Status Measurements *Measurements FirstSeen time.Time VerifiedIPs bool InvalidInfo bool InvalidStatus bool // contains filtered or unexported fields }
Hub represents a network node in the SPN.
func ApplyAnnouncement ¶
func ApplyAnnouncement(existingHub *Hub, data []byte, mapName string, scope Scope, selfcheck bool) (hub *Hub, known, changed bool, err error)
ApplyAnnouncement applies the announcement to the Hub if it passes all the checks. If no Hub is provided, it is loaded from the database or created.
func ApplyStatus ¶
func ApplyStatus(existingHub *Hub, data []byte, mapName string, scope Scope, selfcheck bool) (hub *Hub, known, changed bool, err error)
ApplyStatus applies a status update if it passes all the checks.
func GetHubByKey ¶
GetHubByKey returns a hub by its raw DB key.
func OpenHubMsg ¶
func OpenHubMsg(hub *Hub, data []byte, mapName string, tofu bool) (msg []byte, sendingHub *Hub, known bool, err error)
OpenHubMsg opens a signed hub msg and verifies the signature using the provided hub or the local database. If TOFU is enabled, the signature is always accepted, if valid.
func (*Hub) GetMeasurements ¶
func (h *Hub) GetMeasurements() *Measurements
GetMeasurements returns the hub measurements. This method should always be used instead of direct access.
func (*Hub) GetMeasurementsWithLockedHub ¶
func (h *Hub) GetMeasurementsWithLockedHub() *Measurements
GetMeasurementsWithLockedHub returns the hub measurements. The caller must hold the lock to Hub. This method should always be used instead of direct access.
func (*Hub) GetSignet ¶
GetSignet returns the public key identified by the given ID from the Hub Status.
func (*Hub) Name ¶
Name returns a human-readable version of a Hub's name. This name will likely consist of two parts: the given name and the ending of the ID to make it unique.
func (*Hub) RemoveLane ¶
RemoveLane removes a Lane from the Hub Status.
func (*Hub) SelectSignet ¶
SelectSignet selects the public key to use for initiating connections to that Hub.
func (*Hub) StringWithoutLocking ¶
StringWithoutLocking returns a human-readable representation of the Hub without locking it.
type HubIntel ¶
type HubIntel struct { // Trusted specifies if the Hub is specially designated for more sensitive tasks, such as handling unencrypted traffic. Trusted bool // Discontinued specifies if the Hub has been discontinued and should be marked as offline and removed. Discontinued bool // VerifiedOwner holds the name of the verified owner / operator of the Hub. VerifiedOwner string // Override is used to override certain Hub information. Override *InfoOverride }
HubIntel holds Hub-related data.
type HubMsg ¶
type HubMsg struct { record.Base sync.Mutex ID string Map string Type MsgType Data []byte Received int64 }
HubMsg stores raw Hub messages.
type InfoOverride ¶
type InfoOverride struct { // ContinentCode overrides the continent code of the geoip data. ContinentCode string // CountryCode overrides the country code of the geoip data. CountryCode string // Coordinates overrides the geo coordinates code of the geoip data. Coordinates *geoip.Coordinates // ASN overrides the Autonomous System Number of the geoip data. ASN uint // ASOrg overrides the Autonomous System Organization of the geoip data. ASOrg string }
InfoOverride holds data to overide hub info information.
type Intel ¶
type Intel struct { // BootstrapHubs is list of transports that also contain an IP and the Hub's ID. BootstrapHubs []string // Hubs holds intel regarding specific Hubs. Hubs map[string]*HubIntel // AdviseOnlyTrustedHubs advises to only use trusted Hubs regardless of intended purpose. AdviseOnlyTrustedHubs bool // AdviseOnlyTrustedHomeHubs advises to only use trusted Hubs for Home Hubs. AdviseOnlyTrustedHomeHubs bool // AdviseOnlyTrustedDestinationHubs advises to only use trusted Hubs for Destination Hubs. AdviseOnlyTrustedDestinationHubs bool // HubAdvisory always affects all Hubs. HubAdvisory []string // HomeHubAdvisory is only taken into account when selecting a Home Hub. HomeHubAdvisory []string // DestinationHubAdvisory is only taken into account when selecting a Destination Hub. DestinationHubAdvisory []string // Regions defines regions to assist network optimization. Regions []*RegionConfig // VirtualNetworks holds network configurations for virtual cloud networks. VirtualNetworks []*VirtualNetworkConfig // contains filtered or unexported fields }
Intel holds a collection of various security related data collections on Hubs.
func ParseIntel ¶
ParseIntel parses Hub intelligence data.
func (*Intel) ParseAdvisories ¶
ParseAdvisories parses all advisory endpoint lists.
func (*Intel) Parsed ¶
func (i *Intel) Parsed() *ParsedIntel
Parsed returns the collection of parsed intel data.
type Lane ¶
type Lane struct { // ID is the Hub ID of the peer. ID string // Capacity designates the available bandwidth between these Hubs. // It is specified in bit/s. Capacity int // Lateny designates the latency between these Hubs. // It is specified in nanoseconds. Latency time.Duration }
Lane represents a connection to another Hub.
type Measurements ¶
type Measurements struct { sync.Mutex // Latency designates the latency between these Hubs. // It is specified in nanoseconds. Latency time.Duration // LatencyMeasuredAt holds when the latency was measured. LatencyMeasuredAt time.Time // Capacity designates the available bandwidth between these Hubs. // It is specified in bit/s. Capacity int // CapacityMeasuredAt holds when the capacity measurement expires. CapacityMeasuredAt time.Time // CalculatedCost stores the calculated cost for direct access. // It is not set automatically, but needs to be set when needed. CalculatedCost float32 // GeoProximity stores an approximation of the geolocation proximity. // The value is between 0 (other side of the world) and 100 (same location). GeoProximity float32 // contains filtered or unexported fields }
Measurements holds various measurements relating to a Hub. Fields may not be accessed directly.
func NewMeasurements ¶
func NewMeasurements() *Measurements
NewMeasurements returns a new measurements struct.
func (*Measurements) Copy ¶
func (m *Measurements) Copy() *Measurements
Copy returns a copy of the measurements.
func (*Measurements) Expired ¶
func (m *Measurements) Expired(ttl time.Duration) bool
Expired returns whether any of the measurements has expired - calculated with the given TTL.
func (*Measurements) GetCalculatedCost ¶
func (m *Measurements) GetCalculatedCost() (cost float32)
GetCalculatedCost returns the calculated cost. The calculated cost is not set automatically, but needs to be set when needed.
func (*Measurements) GetCapacity ¶
func (m *Measurements) GetCapacity() (capacity int, measuredAt time.Time)
GetCapacity returns the capacity and when it expires. The capacity is measued in bit/s.
func (*Measurements) GetGeoProximity ¶
func (m *Measurements) GetGeoProximity() (geoProximity float32)
GetGeoProximity returns the geolocation proximity.
func (*Measurements) GetLatency ¶
func (m *Measurements) GetLatency() (latency time.Duration, measuredAt time.Time)
GetLatency returns the latency and when it expires.
func (*Measurements) IsPersisted ¶
func (m *Measurements) IsPersisted() bool
IsPersisted return whether changes to the measurements have been persisted.
func (*Measurements) SetCalculatedCost ¶
func (m *Measurements) SetCalculatedCost(cost float32)
SetCalculatedCost sets the calculated cost to the given value. The calculated cost is not set automatically, but needs to be set when needed.
func (*Measurements) SetCapacity ¶
func (m *Measurements) SetCapacity(capacity int)
SetCapacity sets the capacity to the given value. The capacity is measued in bit/s.
func (*Measurements) SetGeoProximity ¶
func (m *Measurements) SetGeoProximity(geoProximity float32)
SetGeoProximity sets the geolocation proximity to the given value.
func (*Measurements) SetLatency ¶
func (m *Measurements) SetLatency(latency time.Duration)
SetLatency sets the latency to the given value.
func (*Measurements) Valid ¶
func (m *Measurements) Valid() bool
Valid returns whether there is a valid value .
type ParsedIntel ¶
type ParsedIntel struct { // HubAdvisory always affects all Hubs. HubAdvisory endpoints.Endpoints // HomeHubAdvisory is only taken into account when selecting a Home Hub. HomeHubAdvisory endpoints.Endpoints // DestinationHubAdvisory is only taken into account when selecting a Destination Hub. DestinationHubAdvisory endpoints.Endpoints }
ParsedIntel holds a collection of parsed intel data.
type RegionConfig ¶
type RegionConfig struct { // ID is the internal identifier of the region. ID string // Name is a human readable name of the region. Name string // MemberPolicy specifies a list for including members. MemberPolicy []string // RegionalMinLanes specifies how many lanes other regions should build // to this region. RegionalMinLanes int // RegionalMinLanesPerHub specifies how many lanes other regions should // build to this region, per Hub in this region. // This value will usually be below one. RegionalMinLanesPerHub float64 // RegionalMaxLanesOnHub specifies how many lanes from or to another region may be // built on one Hub per region. RegionalMaxLanesOnHub int // SatelliteMinLanes specifies how many lanes satellites (Hubs without // region) should build to this region. SatelliteMinLanes int // SatelliteMinLanesPerHub specifies how many lanes satellites (Hubs without // region) should build to this region, per Hub in this region. // This value will usually be below one. SatelliteMinLanesPerHub float64 // InternalMinLanesOnHub specifies how many lanes every Hub should create // within the region at minimum. InternalMinLanesOnHub int // InternalMaxHops specifies the max hop constraint for internally optimizing // the region. InternalMaxHops int }
RegionConfig holds the configuration of a region.
type SingleTrustStore ¶
SingleTrustStore is a simple truststore that always returns the same Signet.
type Status ¶
type Status struct { Timestamp int64 `cbor:"t"` // Version holds the current software version of the Hub. Version string `cbor:"v"` // Routing Information Keys map[string]*Key `cbor:"k,omitempty" json:",omitempty"` // public keys (with type) Lanes []*Lane `cbor:"c,omitempty" json:",omitempty"` // Connections to other Hubs. // Status Information // Load describes max(CPU, Memory) in percent, averaged over at least 15 // minutes. Load is published in fixed steps only. Load int `cbor:"l,omitempty" json:",omitempty"` // Flags holds flags that signify special states. Flags []string `cbor:"f,omitempty" json:",omitempty"` }
Status is the message type used to update changing Hub Information. Changes are made automatically.
type Transport ¶
Transport represents a "endpoint" that others can connect to. This allows for use of different protocols, ports and infrastructure integration.
func ParseBootstrapHub ¶
func ParseBootstrapHub(bootstrapTransport string) (t *Transport, hubID string, hubIP net.IP, err error)
ParseBootstrapHub parses a bootstrap hub.
func ParseTransport ¶
ParseTransport parses a transport definition.
func ParseTransports ¶
ParseTransports returns a list of parsed transports and errors from parsing the given definitions.
type VirtualNetworkConfig ¶
type VirtualNetworkConfig struct { // Name is a human readable name of the virtual network. Name string // Force forces the use of the mapped IP addresses after the Hub's IPs have been verified. Force bool // Mapping maps Hub IDs to internal IP addresses. Mapping map[string]net.IP }
VirtualNetworkConfig holds configuration of a virtual network that binds multiple Hubs together.