Documentation ¶
Overview ¶
Package common contains the structs and logic that form the basis of quantum's operation.
All other quantum modules rely on a subset of the functionality provided here.
Index ¶
- Constants
- func ArrayEquals(a, b []byte) bool
- func IPtoInt(IP net.IP) uint32
- func IncrementIP(ip net.IP)
- func StringInSlice(a string, slice []string) bool
- type Config
- type Logger
- type LoggerType
- type Mapping
- func GenerateFloatingMapping(cfg *Config, i int, mappings map[uint32]*Mapping) (*Mapping, error)
- func GenerateLocalMapping(cfg *Config, mappings map[uint32]*Mapping) (*Mapping, error)
- func NewFloatingMapping(cfg *Config, i int) *Mapping
- func NewMapping(cfg *Config) *Mapping
- func ParseMapping(str string, cfg *Config) (*Mapping, error)
- type NetworkConfig
- type Payload
- type Signaler
Examples ¶
Constants ¶
const ( // RealDeviceNameEnv is the environment variable that the real network device name is stored in for reloads. RealDeviceNameEnv = "_QUANTUM_REAL_DEVICE_NAME_" // IPStart - The ip start position within a quantum packet. IPStart = 0 // IPEnd - The ip end position within a quantum packet. IPEnd = 4 // IPLength - The length of the private ip header. IPLength = 4 // PacketStart - The real packet start position within a quantum packet. PacketStart = 4 // MaxPacketLength - The maximum packet size to send via the UDP device. // StandardMTU(1500) - IPHeader(20) - UDPHeader(8). MaxPacketLength = 1472 // HeaderSize - The size of the data perpended tp the real packet. HeaderSize = IPLength // OverflowSize - An extra buffer for overflow of the MTU for plugins and other things to use incase its necessary. OverflowSize = 35 // MTU - The max size packet to receive from the TUN device. MTU = MaxPacketLength - HeaderSize - OverflowSize )
Variables ¶
This section is empty.
Functions ¶
func ArrayEquals ¶
ArrayEquals returns true if both byte slices contain the same data.
NOTE: this is a very slow func and should be limited in use.
Example ¶
a := []byte{0, 1} b := []byte{0, 1} c := []byte{1, 1} fmt.Println(ArrayEquals(a, b), ArrayEquals(nil, nil), ArrayEquals(a, c), ArrayEquals(a, nil))
Output: true true false false
func IPtoInt ¶
IPtoInt takes an ipv4 net.IP and returns a uint32 that represents it.
Example ¶
ipAddr := net.ParseIP("1.0.0.0") ipInt := IPtoInt(ipAddr) fmt.Println(ipInt)
Output: 1
func IncrementIP ¶
IncrementIP will increment the given ipv4 net.IP by 1 in place.
Example ¶
ipAddr := net.ParseIP("0.0.0.1") IncrementIP(ipAddr) fmt.Println(ipAddr)
Output: 0.0.0.2
func StringInSlice ¶
StringInSlice returns true if the string 'a' is contained in the string array 'slice'.
Example ¶
slice := []string{"encryption", "compression"} fmt.Println(StringInSlice("encryption", slice), StringInSlice("compression", slice), StringInSlice("nonexistent", slice))
Output: true true false
Types ¶
type Config ¶
type Config struct { ConfFile string `` /* 330-byte string literal not displayed */ DeviceName string `` /* 331-byte string literal not displayed */ NumWorkers int `` /* 319-byte string literal not displayed */ PrivateIP net.IP `` /* 322-byte string literal not displayed */ ListenIP net.IP `` /* 321-byte string literal not displayed */ ListenPort int `` /* 323-byte string literal not displayed */ FloatingIPs []net.IP `` /* 332-byte string literal not displayed */ PublicIPv4 net.IP `` /* 323-byte string literal not displayed */ DisableIPv4 bool `` /* 331-byte string literal not displayed */ PublicIPv6 net.IP `` /* 323-byte string literal not displayed */ DisableIPv6 bool `` /* 331-byte string literal not displayed */ DataDir string `` /* 326-byte string literal not displayed */ PidFile string `` /* 325-byte string literal not displayed */ Forward bool `` /* 327-byte string literal not displayed */ Gateway net.IP `` /* 319-byte string literal not displayed */ Plugins []string `` /* 319-byte string literal not displayed */ Datastore string `` /* 321-byte string literal not displayed */ DatastorePrefix string `` /* 318-byte string literal not displayed */ DatastoreSyncInterval time.Duration `` /* 337-byte string literal not displayed */ DatastoreRefreshInterval time.Duration `` /* 344-byte string literal not displayed */ DatastoreFloatingIPTTL time.Duration `` /* 327-byte string literal not displayed */ DatastoreEndpoints []string `` /* 321-byte string literal not displayed */ DatastoreUsername string `` /* 320-byte string literal not displayed */ DatastorePassword string `` /* 320-byte string literal not displayed */ DatastoreTLSSkipVerify bool `` /* 333-byte string literal not displayed */ DatastoreTLSCA string `` /* 335-byte string literal not displayed */ DatastoreTLSCert string `` /* 339-byte string literal not displayed */ DatastoreTLSKey string `` /* 332-byte string literal not displayed */ DTLSSkipVerify bool `` /* 334-byte string literal not displayed */ DTLSCA string `` /* 336-byte string literal not displayed */ DTLSCert string `` /* 340-byte string literal not displayed */ DTLSKey string `` /* 333-byte string literal not displayed */ StatsRoute string `` /* 325-byte string literal not displayed */ StatsAddress string `` /* 325-byte string literal not displayed */ StatsPort int `` /* 327-byte string literal not displayed */ Network string `` /* 326-byte string literal not displayed */ NetworkStaticRange string `` /* 337-byte string literal not displayed */ NetworkFloatingRange string `` /* 339-byte string literal not displayed */ NetworkBackend string `` /* 319-byte string literal not displayed */ NetworkLeaseTime time.Duration `` /* 327-byte string literal not displayed */ PublicKey []byte `internal:"true"` // The public key to use with the encryption plugin. PrivateKey []byte `internal:"true"` // The private key to use with the encryption plugin. PublicSalt []byte `internal:"true"` // The public salt to use with the encryption plugin. PrivateSalt []byte `internal:"true"` // The private salt to use with the encryption plugin. Salt []byte `internal:"true"` // The salt to use with the encryption plugin. RealDeviceName string `internal:"true"` // Used when a rolling restart is triggered to find the correct tun interface ReuseFDS bool `internal:"true"` // Used when a rolling restart is triggered which forces quantum to reuse the passed in socket/tun fds MachineID string `internal:"true"` // The generated machine id for this node AuthEnabled bool `internal:"true"` // Whether or not datastore authentication is enabled (toggled by setting username/password) TLSEnabled bool `internal:"true"` // Whether or not tls with the datastore is enabled (toggled by setting the tls parameters at run time) IsIPv4Enabled bool `internal:"true"` // Whether or not quantum has determined that this node is ipv4 capable IsIPv6Enabled bool `internal:"true"` // Whether or not quantum has determined that this node is ipv6 capable ListenAddr syscall.Sockaddr `internal:"true"` // The commputed Sockaddr object to bind the underlying udp sockets to NetworkConfig *NetworkConfig `internal:"true"` // The network config detemined by existence of the object in etcd Log *Logger `internal:"true"` // The internal Logger to use // contains filtered or unexported fields }
Config struct that handles marshalling in user supplied configuration data from cli arguments, environment variables, and configuration file entries.
The user supplied configuration is processed via a structured hierarchy:
- Cli arguments override both environment variables and configuration file entries.
- Environment variables will override file entries but can be overridden by cli arguments.
- Configuration file entries will be overridden by both environment variables and cli arguments.
- Defaults are used in the case that the user does not define a configuration argument.
The only exceptions to the above are the two special cli argments '-h'|'--help' or '-v'|'--version' which will output usage information or version information respectively and then exit the application.
type Logger ¶
type Logger struct { Plain *log.Logger Error *log.Logger Info *log.Logger Warn *log.Logger Debug *log.Logger }
Logger struct which allows for a single global point for logging configuration.
func NewLogger ¶
func NewLogger(loggerType LoggerType) *Logger
NewLogger creates a new logger struct based on the supplied LoggerType.
type LoggerType ¶
type LoggerType int
LoggerType will determine the logging level of the logger object created.
const ( // NoopLogger will noop all logging calls this is only used for testing. NoopLogger LoggerType = iota // ErrorLogger will only output error logs. ErrorLogger // WarnLogger will output warn/error logs. WarnLogger // InfoLogger will output info/warn/error logs. InfoLogger // DebugLogger will output debug/info/warn/error logs. DebugLogger )
type Mapping ¶
type Mapping struct { // The unique machine id within the quantum network. MachineID string `json:"machineID"` // The private ip address within the quantum network. PrivateIP net.IP `json:"privateIP"` // The port where quantum is listening for remote packets. Port int `json:"port"` // Whether or not this mapping represents a floating ip address. Floating bool `json:"floating"` // The gateway ip this node will forward traffic to. Gateway net.IP `json:"gatewayIP"` // The public ipv4 address of the node represented by this mapping, which may or may not exist. IPv4 net.IP `json:"ipv4,omitempty"` // The public ipv6 address of the node represented by this mapping, which may or may not exist. IPv6 net.IP `json:"ipv6,omitempty"` // The plugins that the node represented by this mapping supports. SupportedPlugins []string `json:"plugins,omitempty"` // The public key to use with the encryption plugin. PublicKey []byte `json:"publicKey,omitempty"` // The salt to use with the encryption plugin. PublicSalt []byte `json:"salt,omitempty"` // The resulting endpoint to send data to the node represented by this mapping. Sockaddr syscall.Sockaddr `json:"-"` // The resulting endpoint to send data to the node represented by this mapping. Address string `json:"-"` // The AES object to use for encrypting packets to/from the node represented by this mapping. AES *crypto.AES `json:"-"` }
Mapping represents the relationship between a public/private address along with encryption metadata for a particular node in the quantum network.
func GenerateFloatingMapping ¶
GenerateFloatingMapping will take in the user defined configuration plus the currently defined mappins, in order to determine the floating mapping.
func GenerateLocalMapping ¶
GenerateLocalMapping will take in the user defined configuration plus the currently defined mappings, in order to determine the local mapping.
func NewFloatingMapping ¶
NewFloatingMapping generates a new basic Mapping with no cryptographic metadata.
func NewMapping ¶
NewMapping generates a new basic Mapping with no cryptographic metadata.
func ParseMapping ¶
ParseMapping creates a new mapping based on the output of a Mapping.Bytes call.
type NetworkConfig ¶
type NetworkConfig struct { // The backend to use for communication. Backend string `json:"backend"` // The network range that represents the quantum network. Network string `json:"network"` // The reserved static ip address range which should be skipped for floating and DHCP assignments. StaticRange string `json:"staticRange"` // The reserved floating ip address range which should be skipped for static and DHCP assignments. FloatingRange string `json:"floatingRange"` // The length of time to hold the assigned DHCP lease. LeaseTime time.Duration `json:"leaseTime"` // The base ip address of the quantum network. BaseIP net.IP `json:"-"` // The IPNet representation of the quantum network. IPNet *net.IPNet `json:"-"` // The IPNet representation of the reserved static ip address range. StaticNet *net.IPNet `json:"-"` // The IPNet representation of the reserved floating ip address range. FloatingNet *net.IPNet `json:"-"` }
NetworkConfig object to represent the current network setup.
func ParseNetworkConfig ¶
func ParseNetworkConfig(data []byte) (*NetworkConfig, error)
ParseNetworkConfig from the data stored in the datastore.
func (*NetworkConfig) Bytes ¶
func (networkCfg *NetworkConfig) Bytes() []byte
Bytes returns a byte slice representation of a NetworkConfig object, if there is an error while marshalling data a nil slice is returned.
func (*NetworkConfig) String ¶
func (networkCfg *NetworkConfig) String() string
Bytes returns a string representation of a NetworkConfig object, if there is an error while marshalling data an empty string is returned.
type Payload ¶
type Payload struct { // The raw byte array representing the payload, which includes all necessary metadata. Raw []byte // The packet data within the raw payload. Packet []byte // The private ip address of the remote peer within the raw payload. IPAddress []byte // The total length of the payload. Length int }
Payload represents a packet traversing the quantum network.
func NewSockPayload ¶
NewSockPayload is used to generate a payload based on a received Socket packet.
func NewTunPayload ¶
NewTunPayload is used to generate a payload based on a received TUN packet.
type Signaler ¶
type Signaler struct {
// contains filtered or unexported fields
}
Signaler struct used to manage os and user signals to the quantum process.
func NewSignaler ¶
NewSignaler generates a new Signaler object, which will watch for new os and user signals passed to the quantum process.