mtypes

package
v0.3.5 Latest Latest
Warning

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

Go to latest
Published: Dec 27, 2021 License: MIT Imports: 15 Imported by: 0

Documentation

Overview

Package daemon provides a Go implementation of the sd_notify protocol. It can be used to inform systemd of service start-up completion, watchdog events, and other status changes.

https://www.freedesktop.org/software/systemd/man/sd_notify.html#Description

Index

Constants

View Source
const (
	// SdNotifyReady tells the service manager that service startup is finished
	// or the service finished loading its configuration.
	SdNotifyReady = "READY=1"

	// SdNotifyStopping tells the service manager that the service is beginning
	// its shutdown.
	SdNotifyStopping = "STOPPING=1"

	// SdNotifyReloading tells the service manager that this service is
	// reloading its configuration. Note that you must call SdNotifyReady when
	// it completed reloading.
	SdNotifyReloading = "RELOADING=1"

	// SdNotifyWatchdog tells the service manager to update the watchdog
	// timestamp for the service.
	SdNotifyWatchdog = "WATCHDOG=1"
)
View Source
const Infinity = float64(99999)

Variables

This section is empty.

Functions

func AbsInt added in v0.3.4

func AbsInt(a int) int

func ByteSlice2Byte32

func ByteSlice2Byte32(bytes []byte) (ret [32]byte)

func GUzip

func GUzip(bytesIn []byte) (ret []byte, err error)

func GetByte

func GetByte(structIn interface{}) (bb []byte, err error)

func Gzip

func Gzip(bytesIn []byte) (ret []byte)

func Hash2Str

func Hash2Str(h string) string

func RandomBytes

func RandomBytes(length int, defaults []byte) (ret []byte)

func RandomStr

func RandomStr(length int, defaults string) (ret string)

func ReadYaml added in v0.3.3

func ReadYaml(filePath string, out interface{}) (err error)

func S2TD

func S2TD(secs float64) time.Duration

func SdNotify added in v0.3.2

func SdNotify(unsetEnvironment bool, state string) (bool, error)

SdNotify sends a message to the init daemon. It is common to ignore the error. If `unsetEnvironment` is true, the environment variable `NOTIFY_SOCKET` will be unconditionally unset.

It returns one of the following: (false, nil) - notification not supported (i.e. NOTIFY_SOCKET is unset) (false, err) - notification supported, but failure happened (e.g. error connecting to NOTIFY_SOCKET or while sending data) (true, nil) - notification supported, data has been sent

func String2Float64 added in v0.3.3

func String2Float64(s string) (float64, error)

Types

type API_Peerinfo

type API_Peerinfo struct {
	NodeID  Vertex
	PSKey   string
	Connurl *API_connurl
}

type API_Peers

type API_Peers map[string]API_Peerinfo // map[PubKey]API_Peerinfo

type API_SuperParams added in v0.3.1

type API_SuperParams struct {
	SendPingInterval    float64
	HttpPostInterval    float64
	PeerAliveTimeout    float64
	DampingFilterRadius uint64
	AdditionalCost      float64
}

type API_connurl

type API_connurl struct {
	ExternalV4 map[string]float64
	ExternalV6 map[string]float64
	LocalV4    map[string]float64
	LocalV6    map[string]float64
}

func (*API_connurl) GetList

func (Connurl *API_connurl) GetList(UseLocal bool) (ret map[string]float64)

func (*API_connurl) IsEmpty

func (Connurl *API_connurl) IsEmpty() bool

type API_report_peerinfo

type API_report_peerinfo struct {
	Pongs    []PongMsg
	LocalV4s map[string]float64
	LocalV6s map[string]float64
}

func ParseAPI_report_peerinfo

func ParseAPI_report_peerinfo(bin []byte) (StructPlace API_report_peerinfo, err error)

type API_report_peerinfo_jwt_claims

type API_report_peerinfo_jwt_claims struct {
	PostCount uint64
	BodyHash  string
	jwt.StandardClaims
}

type BoardcastPeerMsg

type BoardcastPeerMsg struct {
	Request_ID uint32
	NodeID     Vertex
	PubKey     [32]byte
	ConnURL    string
}

func ParseBoardcastPeerMsg

func ParseBoardcastPeerMsg(bin []byte) (StructPlace BoardcastPeerMsg, err error)

func (*BoardcastPeerMsg) ToString

func (c *BoardcastPeerMsg) ToString() string

type DistTable

type DistTable map[Vertex]map[Vertex]float64

type DynamicRouteInfo

type DynamicRouteInfo struct {
	SendPingInterval     float64   `yaml:"SendPingInterval"`
	PeerAliveTimeout     float64   `yaml:"PeerAliveTimeout"`
	TimeoutCheckInterval float64   `yaml:"TimeoutCheckInterval"`
	ConnNextTry          float64   `yaml:"ConnNextTry"`
	DupCheckTimeout      float64   `yaml:"DupCheckTimeout"`
	AdditionalCost       float64   `yaml:"AdditionalCost"`
	DampingFilterRadius  uint64    `yaml:"DampingFilterRadius"`
	SaveNewPeers         bool      `yaml:"SaveNewPeers"`
	SuperNode            SuperInfo `yaml:"SuperNode"`
	P2P                  P2PInfo   `yaml:"P2P"`
	NTPConfig            NTPInfo   `yaml:"NTPConfig"`
}

type EdgeConfig

type EdgeConfig struct {
	Interface             InterfaceConf    `yaml:"Interface"`
	NodeID                Vertex           `yaml:"NodeID"`
	NodeName              string           `yaml:"NodeName"`
	PostScript            string           `yaml:"PostScript"`
	DefaultTTL            uint8            `yaml:"DefaultTTL"`
	L2FIBTimeout          float64          `yaml:"L2FIBTimeout"`
	PrivKey               string           `yaml:"PrivKey"`
	ListenPort            int              `yaml:"ListenPort"`
	AfPrefer              int              `yaml:"AfPrefer"`
	LogLevel              LoggerInfo       `yaml:"LogLevel"`
	DynamicRoute          DynamicRouteInfo `yaml:"DynamicRoute"`
	NextHopTable          NextHopTable     `yaml:"NextHopTable"`
	ResetEndPointInterval float64          `yaml:"ResetEndPointInterval"`
	Peers                 []PeerInfo       `yaml:"Peers"`
}

type GraphRecalculateSetting

type GraphRecalculateSetting struct {
	StaticMode                bool      `yaml:"StaticMode"`
	ManualLatency             DistTable `yaml:"ManualLatency"`
	JitterTolerance           float64   `yaml:"JitterTolerance"`
	JitterToleranceMultiplier float64   `yaml:"JitterToleranceMultiplier"`
	TimeoutCheckInterval      float64   `yaml:"TimeoutCheckInterval"`
	RecalculateCoolDown       float64   `yaml:"RecalculateCoolDown"`
}

type InterfaceConf

type InterfaceConf struct {
	IType         string `yaml:"IType"`
	Name          string `yaml:"Name"`
	VPPIFaceID    uint32 `yaml:"VPPIFaceID"`
	VPPBridgeID   uint32 `yaml:"VPPBridgeID"`
	MacAddrPrefix string `yaml:"MacAddrPrefix"`
	IPv4CIDR      string `yaml:"IPv4CIDR"`
	IPv6CIDR      string `yaml:"IPv6CIDR"`
	IPv6LLPrefix  string `yaml:"IPv6LLPrefix"`
	MTU           uint16 `yaml:"MTU"`
	RecvAddr      string `yaml:"RecvAddr"`
	SendAddr      string `yaml:"SendAddr"`
	L2HeaderMode  string `yaml:"L2HeaderMode"`
}

type JWTSecret

type JWTSecret [32]byte

type LoggerInfo

type LoggerInfo struct {
	LogLevel    string `yaml:"LogLevel"`
	LogTransit  bool   `yaml:"LogTransit"`
	LogNormal   bool   `yaml:"LogNormal"`
	LogControl  bool   `yaml:"LogControl"`
	LogInternal bool   `yaml:"LogInternal"`
	LogNTP      bool   `yaml:"LogNTP"`
}

type NTPInfo added in v0.3.2

type NTPInfo struct {
	UseNTP           bool     `yaml:"UseNTP"`
	MaxServerUse     int      `yaml:"MaxServerUse"`
	SyncTimeInterval float64  `yaml:"SyncTimeInterval"`
	NTPTimeout       float64  `yaml:"NTPTimeout"`
	Servers          []string `yaml:"Servers"`
}

type NextHopTable

type NextHopTable map[Vertex]map[Vertex]Vertex

type P2PInfo added in v0.3.2

type P2PInfo struct {
	UseP2P                  bool                    `yaml:"UseP2P"`
	SendPeerInterval        float64                 `yaml:"SendPeerInterval"`
	GraphRecalculateSetting GraphRecalculateSetting `yaml:"GraphRecalculateSetting"`
}

type Passwords

type Passwords struct {
	ShowState   string `yaml:"ShowState"`
	AddPeer     string `yaml:"AddPeer"`
	DelPeer     string `yaml:"DelPeer"`
	UpdatePeer  string `yaml:"UpdatePeer"`
	UpdateSuper string `yaml:"UpdateSuper"`
}

type PeerInfo

type PeerInfo struct {
	NodeID              Vertex `yaml:"NodeID"`
	PubKey              string `yaml:"PubKey"`
	PSKey               string `yaml:"PSKey"`
	EndPoint            string `yaml:"EndPoint"`
	PersistentKeepalive uint32 `yaml:"PersistentKeepalive"`
	Static              bool   `yaml:"Static"`
}

type PingMsg

type PingMsg struct {
	RequestID    uint32
	Src_nodeID   Vertex
	Time         time.Time
	RequestReply int
}

func ParsePingMsg

func ParsePingMsg(bin []byte) (StructPlace PingMsg, err error)

func (*PingMsg) ToString

func (c *PingMsg) ToString() string

type PongMsg

type PongMsg struct {
	RequestID      uint32
	Src_nodeID     Vertex
	Dst_nodeID     Vertex
	Timediff       float64
	TimeToAlive    float64
	AdditionalCost float64
}

func ParsePongMsg

func ParsePongMsg(bin []byte) (StructPlace PongMsg, err error)

func (*PongMsg) ToString

func (c *PongMsg) ToString() string

type QueryPeerMsg

type QueryPeerMsg struct {
	Request_ID uint32
}

func ParseQueryPeerMsg

func ParseQueryPeerMsg(bin []byte) (StructPlace QueryPeerMsg, err error)

func (*QueryPeerMsg) ToString

func (c *QueryPeerMsg) ToString() string

type RegisterMsg

type RegisterMsg struct {
	Node_id             Vertex
	Version             string
	PeerStateHash       string
	NhStateHash         string
	SuperParamStateHash string
	JWTSecret           JWTSecret
	HttpPostCount       uint64
}

func ParseRegisterMsg

func ParseRegisterMsg(bin []byte) (StructPlace RegisterMsg, err error)

func (*RegisterMsg) ToString

func (c *RegisterMsg) ToString() string

type SUPER_Events

type SUPER_Events struct {
	Event_server_pong     chan PongMsg
	Event_server_register chan RegisterMsg
}

type ServerCommand

type ServerCommand int
const (
	NoAction ServerCommand = iota
	Shutdown
	ThrowError
	Panic
	UpdatePeer
	UpdateNhTable
	UpdateSuperParams
)

func (*ServerCommand) ToString

func (a *ServerCommand) ToString() string

type ServerUpdateMsg added in v0.3.1

type ServerUpdateMsg struct {
	Node_id Vertex
	Action  ServerCommand
	Code    int
	Params  string
}

func ParseServerUpdateMsg added in v0.3.1

func ParseServerUpdateMsg(bin []byte) (StructPlace ServerUpdateMsg, err error)

func (*ServerUpdateMsg) ToString added in v0.3.1

func (c *ServerUpdateMsg) ToString() string

type StateHash added in v0.3.1

type StateHash struct {
	Peer       atomic.Value //[32]byte
	SuperParam atomic.Value //[32]byte
	NhTable    atomic.Value //[32]byte
}

type SuperConfig

type SuperConfig struct {
	NodeName                string                  `yaml:"NodeName"`
	PostScript              string                  `yaml:"PostScript"`
	PrivKeyV4               string                  `yaml:"PrivKeyV4"`
	PrivKeyV6               string                  `yaml:"PrivKeyV6"`
	ListenPort              int                     `yaml:"ListenPort"`
	ListenPort_EdgeAPI      string                  `yaml:"ListenPort_EdgeAPI"`
	ListenPort_ManageAPI    string                  `yaml:"ListenPort_ManageAPI"`
	API_Prefix              string                  `yaml:"API_Prefix"`
	RePushConfigInterval    float64                 `yaml:"RePushConfigInterval"`
	HttpPostInterval        float64                 `yaml:"HttpPostInterval"`
	PeerAliveTimeout        float64                 `yaml:"PeerAliveTimeout"`
	SendPingInterval        float64                 `yaml:"SendPingInterval"`
	DampingFilterRadius     uint64                  `yaml:"DampingFilterRadius"`
	LogLevel                LoggerInfo              `yaml:"LogLevel"`
	Passwords               Passwords               `yaml:"Passwords"`
	GraphRecalculateSetting GraphRecalculateSetting `yaml:"GraphRecalculateSetting"`
	NextHopTable            NextHopTable            `yaml:"NextHopTable"`
	EdgeTemplate            string                  `yaml:"EdgeTemplate"`
	UsePSKForInterEdge      bool                    `yaml:"UsePSKForInterEdge"`
	ResetEndPointInterval   float64                 `yaml:"ResetEndPointInterval"`
	Peers                   []SuperPeerInfo         `yaml:"Peers"`
}

type SuperInfo

type SuperInfo struct {
	UseSuperNode         bool     `yaml:"UseSuperNode"`
	PSKey                string   `yaml:"PSKey"`
	EndpointV4           string   `yaml:"EndpointV4"`
	PubKeyV4             string   `yaml:"PubKeyV4"`
	EndpointV6           string   `yaml:"EndpointV6"`
	PubKeyV6             string   `yaml:"PubKeyV6"`
	EndpointEdgeAPIUrl   string   `yaml:"EndpointEdgeAPIUrl"`
	SkipLocalIP          bool     `yaml:"SkipLocalIP"`
	AdditionalLocalIP    []string `yaml:"AdditionalLocalIP"`
	SuperNodeInfoTimeout float64  `yaml:"SuperNodeInfoTimeout"`
}

type SuperPeerInfo

type SuperPeerInfo struct {
	NodeID         Vertex  `yaml:"NodeID"`
	Name           string  `yaml:"Name"`
	PubKey         string  `yaml:"PubKey"`
	PSKey          string  `yaml:"PSKey"`
	AdditionalCost float64 `yaml:"AdditionalCost"`
	SkipLocalIP    bool    `yaml:"SkipLocalIP"`
	EndPoint       string  `yaml:"EndPoint"`
	ExternalIP     string  `yaml:"ExternalIP"`
}

type Vertex

type Vertex uint16

Nonnegative integer ID of vertex

const (
	NodeID_Broadcast Vertex = math.MaxUint16 - iota // Normal boardcast, boardcast with route table
	NodeID_Spread    Vertex = math.MaxUint16 - iota // p2p mode: boardcast to every know peer and prevent dup. super mode: send to supernode
	NodeID_SuperNode Vertex = math.MaxUint16 - iota
	NodeID_Invalid   Vertex = math.MaxUint16 - iota
	NodeID_Special   Vertex = NodeID_Invalid
)

func String2NodeID added in v0.3.3

func String2NodeID(s string) (Vertex, error)

func (*Vertex) ToString

func (v *Vertex) ToString() string

Jump to

Keyboard shortcuts

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