delago.dedis.ch/dela/internal/traffic Index | Files

package traffic

import "go.dedis.ch/dela/internal/traffic"

Index

Constants

const EnvVariable = "MINO_TRAFFIC"

EnvVariable is the name of the environment variable to enable the traffic.

Variables

var (

	// LogItems allows one to granularly say when items should be logged or not.
	// This is useful for example in an integration test where a specific part
	// raises a problem but the full graph would be too noisy. For that, one
	// can set LogItems = false and change it to true when needed.
	LogItems = true
	// LogEvent works the same as LogItems but for events. Note that in both
	// cases the varenv should be set.
	LogEvent = true
)
var GlobalWatcher = Watcher{
	// contains filtered or unexported fields
}

GlobalWatcher can be used to watch for sent and received messages.

Functions

func GenerateEventGraphviz

func GenerateEventGraphviz(out io.Writer, traffics ...*Traffic)

GenerateEventGraphviz creates a graphviz representation of the events

func GenerateItemsGraphviz

func GenerateItemsGraphviz(out io.Writer, withSend, withRcv bool, traffics ...*Traffic)

GenerateItemsGraphviz creates a graphviz representation of the items. One can generate a graphical representation with `dot -Tpdf graph.dot -o graph.pdf`

func SaveEvents

func SaveEvents(path string) error

SaveEvents saves all the events as a graph

func SaveItems

func SaveItems(path string, withSend, withRcv bool) error

SaveItems saves all the items as a graph

Types

type Event

type Event struct {
	Address mino.Address
	Pkt     router.Packet
}

Event defines the elements of a receive or sent event

type Traffic

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

Traffic is used to keep track of packets Traffic in a server

func NewTraffic

func NewTraffic(src mino.Address, out io.Writer) *Traffic

NewTraffic creates a new empty traffic recorder.

func (*Traffic) Display

func (t *Traffic) Display(out io.Writer)

Display prints the current traffic to the writer.

func (*Traffic) LogRecv

func (t *Traffic) LogRecv(ctx context.Context, gateway mino.Address, pkt router.Packet)

LogRecv records a packet received by the node. The sender is the gateway and the receiver the node.

func (*Traffic) LogRelay

func (t *Traffic) LogRelay(to mino.Address)

LogRelay records a new relay.

func (*Traffic) LogRelayClosed

func (t *Traffic) LogRelayClosed(to mino.Address)

LogRelayClosed records the end of a relay.

func (*Traffic) LogSend

func (t *Traffic) LogSend(ctx context.Context, gateway mino.Address, pkt router.Packet)

LogSend records a packet sent by the node. It records the node address as the sender and the gateway as the receiver, while also recording the packet itself.

func (*Traffic) Save

func (t *Traffic) Save(path string, withSend, withRcv bool) error

Save saves the items graph to the given address.

type Watcher

type Watcher struct {
	// contains filtered or unexported fields
}

Watcher defines an element to watch for sent and received messages.

func (*Watcher) WatchIns

func (w *Watcher) WatchIns(ctx context.Context) <-chan Event

WatchIns returns a channel populated with received messages.

func (*Watcher) WatchOuts

func (w *Watcher) WatchOuts(ctx context.Context) <-chan Event

WatchOuts returns a channel populated with sent messages.

Source Files

mod.go

Version
v0.1.0 (latest)
Published
Apr 10, 2024
Platform
linux/amd64
Imports
16 packages
Last checked
1 month ago

Tools for package owners.