nodedb

package
v0.0.0-...-0eeec4f Latest Latest
Warning

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

Go to latest
Published: Sep 19, 2015 License: MIT Imports: 19 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// log this client count for offline nodes
	NODE_OFFLINE = -1
	// log this if the client statistics data cannot be parsed
	NODE_DATAERROR = -2
)
View Source
const (
	// time.Time format string for what we like the JSON Marshaled
	// variant to look like
	NodesJSONTimeStamp = `"2006-01-02T15:04:05"`
)

Variables

View Source
var DefaultValidityGluon = time.Hour * 24 * 30
View Source
var DefaultValidityVis = time.Minute * 20
View Source
var ErrInvalid = errors.New("invalid data")
View Source
var ErrUnknownVersion = errors.New("Unknown data format version")

Functions

This section is empty.

Types

type Cache

type Cache struct {
	sync.Mutex
	// contains filtered or unexported fields
}

type Count

type Count struct {
	Timestamp time.Time
	Count     int
}

func (*Count) Bytes

func (n *Count) Bytes() ([]byte, error)

func (*Count) DeserializeFrom

func (n *Count) DeserializeFrom(d []byte) error

func (*Count) GetCount

func (n *Count) GetCount() int

func (*Count) GetTimestamp

func (n *Count) GetTimestamp() time.Time

func (*Count) Key

func (n *Count) Key() []byte

func (*Count) SetCount

func (n *Count) SetCount(count int)

func (*Count) SetKey

func (n *Count) SetKey(k []byte)

func (*Count) SetTimestamp

func (n *Count) SetTimestamp(timestamp time.Time)

type CountMeshClients

type CountMeshClients struct{ Count }

func (*CountMeshClients) StoreID

func (c *CountMeshClients) StoreID() []byte

type CountMeshNodes

type CountMeshNodes struct{ Count }

func (*CountMeshNodes) StoreID

func (c *CountMeshNodes) StoreID() []byte

type CountNodeClients

type CountNodeClients struct {
	Count
	Node string
}

func NewCountNodeClients

func NewCountNodeClients(node string, timestamp time.Time, count int) *CountNodeClients

func (*CountNodeClients) StoreID

func (c *CountNodeClients) StoreID() []byte

type Counter

type Counter interface {
	store.Item
	GetTimestamp() time.Time
	SetTimestamp(time.Time)
	GetCount() int
	SetCount(int)
}

type Gateway

type Gateway struct{ store.Flag }

func (*Gateway) StoreID

func (g *Gateway) StoreID() []byte

type GraphJSON

type GraphJSON struct {
	Version int             `json:"version,omitempty"`
	BatAdv  GraphJSONBatAdv `json:"batadv"`
}

Type corresponding to a full graph.json document

type GraphJSONBatAdv

type GraphJSONBatAdv struct {
	Directed bool            `json:"directed"`
	Graph    []struct{}      `json:"graph"`
	Nodes    []GraphJSONNode `json:"nodes"`
	Links    []GraphJSONLink `json:"links"`
}

batadv subelement in graph.json document

type GraphJSONLink struct {
	Source   int     `json:"source"`
	Vpn      bool    `json:"vpn"`
	Bidirect bool    `json:"bidirect"`
	Target   int     `json:"target"`
	Tq       float64 `json:"tq"`
}

Information about a link. Especially stupid design is the numerical indexing based on the list index of the corresponding node information.

type GraphJSONNode

type GraphJSONNode struct {
	NodeID string              `json:"node_id,omitempty"`
	ID     alfred.HardwareAddr `json:"id"`
	Number int                 `json:"number"`
}

Information about the existence of a mesh node

func NewGraphJSONNode

func NewGraphJSONNode(id alfred.HardwareAddr, nodeid string, number int) GraphJSONNode

func NewGraphJSONNodeIDonly

func NewGraphJSONNodeIDonly(id alfred.HardwareAddr, number int) GraphJSONNode

type LogSample

type LogSample struct {
	// the start of the sample is the point in time from where we are going
	// backwards, i.e. into the past
	Start time.Time
	// part of the sample that the logged instance is considered offline
	Offline float64
	// part of the sample that the logged instance gave us invalid data
	Errorneous float64
	// a weighted (by the duration of it being valid) average of the log count
	WeightedAverage float64
	// minimum count within sample time
	Min float64
	// maximum count within sample time
	Max float64
}

a sample of log data

type NodeDB

type NodeDB struct {
	Main                   *store.DB
	Logs                   *store.DB
	NotifyPurgeVis         *topic.Topic
	NotifyUpdateNodeInfo   *topic.Topic
	NotifyUpdateStatistics *topic.Topic
	NotifyUpdateVis        *topic.Topic
	NotifyQuitUpdater      *topic.Topic
	NotifyQuitPurger       *topic.Topic
	NotifyQuitLogger       *topic.Topic
	// contains filtered or unexported fields
}

func New

func New(gluonvalid, visvalid time.Duration, storefile string, logfile string) (*NodeDB, error)

create a new database instance

func (*NodeDB) ExportNodeInfo

func (db *NodeDB) ExportNodeInfo(w io.Writer)

func (*NodeDB) ExportStatistics

func (db *NodeDB) ExportStatistics(w io.Writer)

func (*NodeDB) ExportVisData

func (db *NodeDB) ExportVisData(w io.Writer)

func (*NodeDB) ForEachLogEntry

func (db *NodeDB) ForEachLogEntry(logitem Counter, handler func() (bool, error)) error

fetch raw log data

handler function might return "true" to abort reading further

func (*NodeDB) GenerateGraphJSON

func (db *NodeDB) GenerateGraphJSON(w io.Writer)

Write a full graph.json document based on the contents of the database.

func (*NodeDB) GenerateLogJSON

func (db *NodeDB) GenerateLogJSON(w io.Writer, logitem Counter) error

Wrapper to generate JSON output for raw log data

func (*NodeDB) GenerateLogList

func (db *NodeDB) GenerateLogList(w io.Writer) error

generate a JSON list of nodes for which there is log data available

func (*NodeDB) GenerateLogitemSamplesJSON

func (db *NodeDB) GenerateLogitemSamplesJSON(w io.Writer, logitem Counter, start time.Time, over time.Duration, samples int) error

generate a JSON list of samples

func (*NodeDB) GenerateNodesJSON

func (db *NodeDB) GenerateNodesJSON(w io.Writer, offlineDuration time.Duration)

Write a full nodes.json style document based on the current database contents.

func (*NodeDB) GenerateNodesOldJSON

func (db *NodeDB) GenerateNodesOldJSON(w io.Writer, offlineDuration time.Duration)

Write a full nodes.json style document based on the current database contents.

func (*NodeDB) GetLogSamples

func (db *NodeDB) GetLogSamples(logitem Counter, start time.Time, over time.Duration, samples int, handler func(sample LogSample)) error

sample log data into a certain amount of samples, starting at a fixed point in time and going backwards from there, covering a given overall duration to take samples of

For the reader of the following code: take your time, and read the documentation within the code carefully.

func (*NodeDB) ImportNodes

func (db *NodeDB) ImportNodes(r io.Reader, persistent bool) error

read nodes.json compatible data into database

func (*NodeDB) ImportNodesFile

func (db *NodeDB) ImportNodesFile(filename string, persistent bool) error

read nodes.json file into database

func (*NodeDB) LogCounts

func (db *NodeDB) LogCounts(offlineAfter time.Duration)

Will wait for update notifications and upon receiving them, run a count of the data items to be logged. Only one count will be run at any time. When notifications arrive during a count is running, another count will be run as soon the current one is done.

func (*NodeDB) NewNodeID

func (db *NodeDB) NewNodeID(tx *bolt.Tx, nodeid string, alias []byte) error

func (*NodeDB) ResolveNodeID

func (db *NodeDB) ResolveNodeID(tx *bolt.Tx, mac alfred.HardwareAddr) (string, bool)

func (*NodeDB) StartLogger

func (db *NodeDB) StartLogger(offlineAfter time.Duration)

func (*NodeDB) StartPurger

func (db *NodeDB) StartPurger(gluonpurgeint, vispurgeint time.Duration)

func (*NodeDB) StartUpdater

func (db *NodeDB) StartUpdater(client *alfred.Client, updatewait, retrywait time.Duration)

func (*NodeDB) StopLogger

func (db *NodeDB) StopLogger()

func (*NodeDB) StopPurger

func (db *NodeDB) StopPurger()

func (*NodeDB) StopUpdater

func (db *NodeDB) StopUpdater()

func (*NodeDB) UpdateNodeInfo

func (db *NodeDB) UpdateNodeInfo(i *NodeInfo, persistent bool) error

func (*NodeDB) UpdateStatistics

func (db *NodeDB) UpdateStatistics(s *Statistics) error

func (*NodeDB) UpdateVisData

func (db *NodeDB) UpdateVisData(v *VisData) error

type NodeID

type NodeID struct{ store.Byte }

func (*NodeID) StoreID

func (n *NodeID) StoreID() []byte

type NodeInfo

type NodeInfo struct {
	store.ContainedKey
	gluon.NodeInfo
}

func (*NodeInfo) Bytes

func (n *NodeInfo) Bytes() ([]byte, error)

func (*NodeInfo) DeserializeFrom

func (n *NodeInfo) DeserializeFrom(b []byte) error

func (*NodeInfo) Key

func (n *NodeInfo) Key() []byte

func (*NodeInfo) StoreID

func (n *NodeInfo) StoreID() []byte

type NodesJSON

type NodesJSON struct {
	Timestamp NodesJSONTime             `json:"timestamp"`
	Nodes     map[string]*NodesJSONData `json:"nodes"`
	Version   int                       `json:"version,omitempty"`
}

Base type for the nodes.json document

type NodesJSONData

type NodesJSONData struct {
	// wrap gluon.NodeInfoData
	NodeInfo   gluon.NodeInfoData  `json:"nodeinfo,omitempty"`
	Flags      NodesJSONFlags      `json:"flags,omitempty"`
	FirstSeen  NodesJSONTime       `json:"firstseen,omitempty"`
	LastSeen   NodesJSONTime       `json:"lastseen,omitempty"`
	Statistics NodesJSONStatistics `json:"statistics,omitempty"`
}

Type for the data of a single Mesh node

type NodesJSONFlags

type NodesJSONFlags struct {
	Online  bool `json:"online"`
	Gateway bool `json:"gateway,omitempty"`
}

type NodesJSONStatistics

type NodesJSONStatistics struct {
	Clients     int                  `json:"clients"`
	Gateway     *alfred.HardwareAddr `json:"gateway,omitempty"`
	Uptime      float64              `json:"uptime"`
	LoadAvg     float64              `json:"loadavg"`
	MemoryUsage float64              `json:"memory_usage"`
	RootFSUsage float64              `json:"rootfs_usage"`
}

type NodesJSONTime

type NodesJSONTime time.Time

Wrapped time.Time type to provide JSON Marshaling as we like it to be

func (NodesJSONTime) MarshalJSON

func (t NodesJSONTime) MarshalJSON() ([]byte, error)

provide interface for JSON serialization

func (*NodesJSONTime) UnmarshalJSON

func (t *NodesJSONTime) UnmarshalJSON(tval []byte) error

provide interface for JSON serialization

type NodesOldJSON

type NodesOldJSON struct {
	Meta  NodesOldJSONMeta    `json:"meta"`
	Nodes []*NodesOldJSONData `json:"nodes"`
	Links []*NodesOldJSONLink `json:"links"`
}

Base type for the nodes.json document

type NodesOldJSONData

type NodesOldJSONData struct {
	Id                string               `json:"id"`
	Name              *string              `json:"name"`
	LastSeen          int64                `json:"lastseen"`
	Uptime            float64              `json:"uptime"`
	Geo               []float64            `json:"geo,omitempty"`
	ClientCount       int                  `json:"clientcount"`
	BatmanVersion     *string              `json:"batman_version"`
	BatmanGWMode      *string              `json:"batman_gwmode"`
	Group             *string              `json:"group"`
	Flags             NodesOldJSONFlags    `json:"flags"`
	AutoUpdaterState  bool                 `json:"autoupdater_state"`
	AutoUpdaterBranch string               `json:"autoupdater_branch"`
	Hardware          string               `json:"hardware,omitempty"`
	Firmware          *string              `json:"firmware"`
	GluonBase         string               `json:"gluon_base,omitempty"`
	Gateway           *alfred.HardwareAddr `json:"gateway,omitempty"`
	Addresses         []net.IP             `json:"addresses,omitempty"`
}

Type for the data of a single Mesh node

type NodesOldJSONFlags

type NodesOldJSONFlags struct {
	Online  bool `json:"online"`
	Gateway bool `json:"gateway"`
}
type NodesOldJSONLink struct {
	Id      string  `json:"id"`
	Source  int     `json:"source"`
	Quality string  `json:"quality"`
	Target  int     `json:"target"`
	Type    *string `json:"type"`
}

type NodesOldJSONMeta

type NodesOldJSONMeta struct {
	Timestamp    NodesJSONTime `json:"timestamp"`
	GluonRelease string        `json:"gluon_release,omitempty"`
}

type Statistics

type Statistics struct {
	store.ContainedKey
	gluon.Statistics
}

func (*Statistics) Bytes

func (s *Statistics) Bytes() ([]byte, error)

func (*Statistics) DeserializeFrom

func (s *Statistics) DeserializeFrom(b []byte) error

func (*Statistics) Key

func (s *Statistics) Key() []byte

func (*Statistics) StoreID

func (n *Statistics) StoreID() []byte

type VisData

type VisData struct {
	store.ContainedKey
	batadvvis.VisV1
}

func (*VisData) Bytes

func (v *VisData) Bytes() ([]byte, error)

func (*VisData) DeserializeFrom

func (v *VisData) DeserializeFrom(b []byte) error

func (*VisData) Key

func (v *VisData) Key() []byte

func (*VisData) StoreID

func (n *VisData) StoreID() []byte

Jump to

Keyboard shortcuts

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