diff --git a/pluginmgr/research/plugins.go b/pluginmgr/research/plugins.go index 04b591c975f7734ace327b2a4c4d66545e34643d..fa338c8a123e8b52fc75add18528be4db93c5a85 100644 --- a/pluginmgr/research/plugins.go +++ b/pluginmgr/research/plugins.go @@ -8,5 +8,5 @@ import ( var PLUGINS = node.Plugins( remotelog.PLUGIN, - analysis.PLUGIN, + analysis.Plugin, ) diff --git a/plugins/analysis/client/parameters.go b/plugins/analysis/client/parameters.go index d8db0874b6960bbedc4f08dc2b788c6aef225b77..597ae09a42d3d939be0d0208630a3014f599191c 100644 --- a/plugins/analysis/client/parameters.go +++ b/plugins/analysis/client/parameters.go @@ -5,8 +5,10 @@ import ( ) const ( + // CfgServerAddress defines the config flag of the analysis server address. CfgServerAddress = "analysis.client.serverAddress" - ReportInterval = 5 + // ReportInterval defines the interval of the reporting. + ReportInterval = 5 ) func init() { diff --git a/plugins/analysis/client/plugin.go b/plugins/analysis/client/plugin.go index e73a0e98d85e85a9a64f7d77aa7346be3f00f513..8d1b8b0fe9ce765431b6d52e8b6cd71547639095 100644 --- a/plugins/analysis/client/plugin.go +++ b/plugins/analysis/client/plugin.go @@ -7,21 +7,21 @@ import ( "sync" "time" + "github.com/iotaledger/goshimmer/packages/shutdown" "github.com/iotaledger/goshimmer/plugins/analysis/types/heartbeat" + "github.com/iotaledger/goshimmer/plugins/autopeering" + "github.com/iotaledger/goshimmer/plugins/autopeering/local" + "github.com/iotaledger/goshimmer/plugins/config" "github.com/iotaledger/hive.go/daemon" "github.com/iotaledger/hive.go/logger" "github.com/iotaledger/hive.go/network" "github.com/iotaledger/hive.go/node" - - "github.com/iotaledger/goshimmer/packages/shutdown" - "github.com/iotaledger/goshimmer/plugins/autopeering" - "github.com/iotaledger/goshimmer/plugins/autopeering/local" - "github.com/iotaledger/goshimmer/plugins/config" ) var log *logger.Logger var connLock sync.Mutex +// Run runs the plugin. func Run(plugin *node.Plugin) { log = logger.NewLogger("Analysis-Client") daemon.BackgroundWorker("Analysis Client", func(shutdownSignal <-chan struct{}) { diff --git a/plugins/analysis/client/types.go b/plugins/analysis/client/types.go index 9e29eb5390d11ce6504ae2115e9f754a40cd2a50..29660bed73246a99dd1d108f924de8a14f4aa80e 100644 --- a/plugins/analysis/client/types.go +++ b/plugins/analysis/client/types.go @@ -2,6 +2,8 @@ package client import "github.com/iotaledger/goshimmer/plugins/analysis/types/heartbeat" +// EventDispatchers holds the Heartbeat function. type EventDispatchers struct { + // Heartbeat defines the Heartbeat function. Heartbeat func(*heartbeat.Packet) } diff --git a/plugins/analysis/plugin.go b/plugins/analysis/plugin.go index dd65e237fe26b591e10d99d71509f2d15d9fed52..f7b58bdec3be1b9d61790763e80fec5e7b200e6d 100644 --- a/plugins/analysis/plugin.go +++ b/plugins/analysis/plugin.go @@ -10,11 +10,15 @@ import ( "github.com/iotaledger/goshimmer/plugins/config" ) -var PLUGIN = node.NewPlugin("Analysis", node.Enabled, configure, run) +var pluginName = "Analysis" + +// Plugin defines the analysis plugin. +var Plugin = node.NewPlugin(pluginName, node.Enabled, configure, run) + var log *logger.Logger func configure(plugin *node.Plugin) { - log = logger.NewLogger("Analysis") + log = logger.NewLogger(pluginName) if config.Node.GetInt(server.CfgServerPort) != 0 { webinterface.Configure(plugin) server.Configure(plugin) diff --git a/plugins/analysis/server/constants.go b/plugins/analysis/server/constants.go index 844fc02729cacb3d36c86681bacadaedac4773f0..2ba27cac816e0bf7595943ceaea1e2f6558de325 100644 --- a/plugins/analysis/server/constants.go +++ b/plugins/analysis/server/constants.go @@ -7,7 +7,8 @@ import ( ) const ( + // IdleTimeout defines the idle timeout. IdleTimeout = 10 * time.Second - + // StateHeartbeat defines the state of the heartbeat. StateHeartbeat = heartbeat.MarshaledPacketHeader ) diff --git a/plugins/analysis/server/events.go b/plugins/analysis/server/events.go index 9e88d60a9920f91eeb6f46819207a3cb815ab48d..d76f350a711ec654328fee326d260084b2ac88f0 100644 --- a/plugins/analysis/server/events.go +++ b/plugins/analysis/server/events.go @@ -5,13 +5,20 @@ import ( "github.com/iotaledger/hive.go/events" ) +// Events holds the events of the analysis server package. var Events = struct { - AddNode *events.Event - RemoveNode *events.Event - ConnectNodes *events.Event + // AddNode triggers when adding a new node. + AddNode *events.Event + // RemoveNode triggers when removing a node. + RemoveNode *events.Event + // ConnectNodes triggers when connecting two nodes. + ConnectNodes *events.Event + // DisconnectNodes triggers when disconnecting two nodes. DisconnectNodes *events.Event - Error *events.Event - Heartbeat *events.Event + // Error triggers when an error occurs. + Error *events.Event + // Heartbeat triggers when an heartbeat has been received. + Heartbeat *events.Event }{ events.NewEvent(stringCaller), events.NewEvent(stringCaller), diff --git a/plugins/analysis/server/parameters.go b/plugins/analysis/server/parameters.go index 645f32cc915295d2f8b0fef890795857649b4c91..670cff84e7567bf8b3f3eb3fe4aea4972f5a30bb 100644 --- a/plugins/analysis/server/parameters.go +++ b/plugins/analysis/server/parameters.go @@ -5,6 +5,7 @@ import ( ) const ( + // CfgServerPort defines the config flag of the analysis server TCP port. CfgServerPort = "analysis.server.port" ) diff --git a/plugins/analysis/server/plugin.go b/plugins/analysis/server/plugin.go index 158ad6f17dd7d49c46ed5105e8c8282d461a3906..0bbb77f8cba6f74f22d3a64afd49f7b17852d9bc 100644 --- a/plugins/analysis/server/plugin.go +++ b/plugins/analysis/server/plugin.go @@ -3,25 +3,27 @@ package server import ( "errors" + "github.com/iotaledger/goshimmer/packages/shutdown" + "github.com/iotaledger/goshimmer/plugins/analysis/types/heartbeat" + "github.com/iotaledger/goshimmer/plugins/config" "github.com/iotaledger/hive.go/daemon" "github.com/iotaledger/hive.go/events" "github.com/iotaledger/hive.go/logger" "github.com/iotaledger/hive.go/network" "github.com/iotaledger/hive.go/network/tcp" "github.com/iotaledger/hive.go/node" - - "github.com/iotaledger/goshimmer/packages/shutdown" - "github.com/iotaledger/goshimmer/plugins/analysis/types/heartbeat" - "github.com/iotaledger/goshimmer/plugins/config" ) var ( - ErrInvalidPackageHeader = errors.New("invalid package header") + // ErrInvalidPackageHeader defines an invalid package header error. + ErrInvalidPackageHeader = errors.New("invalid package header") + // ErrExpectedInitialAddNodePackage defines an expected initial add node package error. ErrExpectedInitialAddNodePackage = errors.New("expected initial add node package") server *tcp.TCPServer log *logger.Logger ) +// Configure configures the plugin. func Configure(plugin *node.Plugin) { log = logger.NewLogger("Analysis-Server") server = tcp.NewServer() @@ -38,6 +40,7 @@ func Configure(plugin *node.Plugin) { })) } +// Run runs the plugin. func Run(plugin *node.Plugin) { daemon.BackgroundWorker("Analysis Server", func(shutdownSignal <-chan struct{}) { log.Infof("Starting Server (port %d) ... done", config.Node.GetInt(CfgServerPort)) @@ -47,15 +50,17 @@ func Run(plugin *node.Plugin) { }, shutdown.PriorityAnalysis) } +// Shutdown shutdowns the plugin. func Shutdown() { log.Info("Stopping Server ...") server.Shutdown() log.Info("Stopping Server ... done") } +// HandleConnection handles the given connection. func HandleConnection(conn *network.ManagedConnection) { err := conn.SetTimeout(IdleTimeout) - if err!=nil { + if err != nil { log.Errorf(err.Error()) } diff --git a/plugins/analysis/server/types.go b/plugins/analysis/server/types.go index 2dd1e29a5bde698bb18b5036d27584637e84ac1a..4113216c76c7c4510a03e6ed621484ef9831cbbd 100644 --- a/plugins/analysis/server/types.go +++ b/plugins/analysis/server/types.go @@ -1,3 +1,4 @@ package server +// ConnectionState defines the type of a connection state as a byte type ConnectionState = byte diff --git a/plugins/analysis/types/heartbeat/constants.go b/plugins/analysis/types/heartbeat/constants.go index a8b46886f7e64f2380e65a33b645a7c935e99c91..ea0aa58a2aef2d2bc2c5a8dadaac77f94a9a51a4 100644 --- a/plugins/analysis/types/heartbeat/constants.go +++ b/plugins/analysis/types/heartbeat/constants.go @@ -3,32 +3,44 @@ package heartbeat import "crypto/sha256" const ( - // MarshaledPacketHeader unique identifier of packet + // MarshaledPacketHeader unique identifier of packet. MarshaledPacketHeader = 0x01 - // MaxOutboundNeighborCount is the maximum number of allowed neighbors in one direction + // MaxOutboundNeighborCount is the maximum number of allowed neighbors in one direction. MaxOutboundNeighborCount = 4 - // MaxInboundNeighborCount is the maximum number of allowed neighbors in one direction - MaxInboundNeighborCount = 4 + // MaxInboundNeighborCount is the maximum number of allowed neighbors in one direction. + MaxInboundNeighborCount = 4 - // MaxMarshaledTotalSize Maximum packet length in bytes + // MaxMarshaledTotalSize Maximum packet length in bytes. MaxMarshaledTotalSize = MarshaledPacketHeaderSize + MarshaledOwnIDSize + MarshaledOutboundIDsLengthSize + MaxOutboundNeighborCount*MarshaledOutboundIDSize + MarshaledInboundIDsLengthSize + MaxInboundNeighborCount*MarshaledInboundIDSize + // MarshaledPacketHeaderStart is the beginning of the MarshaledPacketHeader. MarshaledPacketHeaderStart = 0 - MarshaledPacketHeaderSize = 1 - MarshaledPacketHeaderEnd = MarshaledPacketHeaderStart + MarshaledPacketHeaderSize + // MarshaledPacketHeaderSize is the size of the MarshaledPacketHeader. + MarshaledPacketHeaderSize = 1 + // MarshaledPacketHeaderEnd is the end of the MarshaledPacketHeader. + MarshaledPacketHeaderEnd = MarshaledPacketHeaderStart + MarshaledPacketHeaderSize + // MarshaledOwnIDStart is the beginning of the MarshaledOwnID. MarshaledOwnIDStart = MarshaledPacketHeaderEnd - MarshaledOwnIDSize = sha256.Size - MarshaledOwnIDEnd = MarshaledOwnIDStart + MarshaledOwnIDSize + // MarshaledOwnIDSize is the size of the MarshaledOwnID. + MarshaledOwnIDSize = sha256.Size + // MarshaledOwnIDEnd is the end of the MarshaledOwnID. + MarshaledOwnIDEnd = MarshaledOwnIDStart + MarshaledOwnIDSize + // MarshaledOutboundIDsLengthStart is the beginning of the MarshaledOutboundIDsLength. MarshaledOutboundIDsLengthStart = MarshaledOwnIDEnd - MarshaledOutboundIDsLengthSize = 1 - MarshaledOutboundIDSize = sha256.Size - MarshaledOutboundIDsLengthEnd = MarshaledOutboundIDsLengthStart + MarshaledOutboundIDsLengthSize - + // MarshaledOutboundIDsLengthSize is the size of the MarshaledOutboundIDsLength. + MarshaledOutboundIDsLengthSize = 1 + // MarshaledOutboundIDSize is the size of the MarshaledOutboundID. + MarshaledOutboundIDSize = sha256.Size + // MarshaledOutboundIDsLengthEnd is the end of the MarshaledOutboundIDsLength. + MarshaledOutboundIDsLengthEnd = MarshaledOutboundIDsLengthStart + MarshaledOutboundIDsLengthSize + + // MarshaledInboundIDsLengthSize is the size of the MarshaledInboundIDsLength. MarshaledInboundIDsLengthSize = 1 - MarshaledInboundIDSize = sha256.Size + // MarshaledInboundIDSize is the size of the MarshaledInboundID. + MarshaledInboundIDSize = sha256.Size ) diff --git a/plugins/analysis/types/heartbeat/packet.go b/plugins/analysis/types/heartbeat/packet.go index 0135db97ca801bb1447853fc0c16d816d64247bb..eb9db877715d4c27228f8798f90f7cea4228d64d 100644 --- a/plugins/analysis/types/heartbeat/packet.go +++ b/plugins/analysis/types/heartbeat/packet.go @@ -3,7 +3,9 @@ package heartbeat import "errors" var ( + // ErrMalformedHeartbeatPacket defines the malformed heartbeat packet error. ErrMalformedHeartbeatPacket = errors.New("malformed heartbeat packet") + // ErrTooManyNeighborsToReport defines the too many neighbors to report in packet error. ErrTooManyNeighborsToReport = errors.New("too many neighbors to report in packet") ) @@ -14,6 +16,7 @@ type Packet struct { InboundIDs [][]byte } +// Unmarshal unmarshals a slice of byte and returns a *Packet and an error (nil if successful). func Unmarshal(data []byte) (*Packet, error) { // So far we are only sure about the static part MarshaledTotalSize := MarshaledPacketHeaderSize + MarshaledOwnIDSize @@ -73,6 +76,7 @@ func Unmarshal(data []byte) (*Packet, error) { } +// Marshal marshals a given *Packet and returns the marshaled slice of byte and an error (nil if successful). func (packet *Packet) Marshal() ([]byte, error) { // Calculate total needed bytes based on packet MarshaledTotalSize := MarshaledPacketHeaderSize + MarshaledOwnIDSize + @@ -93,9 +97,8 @@ func (packet *Packet) Marshal() ([]byte, error) { lengthOutboundIDs := len(packet.OutboundIDs) if lengthOutboundIDs > MaxOutboundNeighborCount { return nil, ErrTooManyNeighborsToReport - } else { - marshaledPackage[MarshaledOutboundIDsLengthStart] = byte(lengthOutboundIDs) } + marshaledPackage[MarshaledOutboundIDsLengthStart] = byte(lengthOutboundIDs) // Copy contents of packet.OutboundIDs for i, outboundID := range packet.OutboundIDs { @@ -109,9 +112,8 @@ func (packet *Packet) Marshal() ([]byte, error) { lengthInboundIDs := len(packet.InboundIDs) if lengthInboundIDs > MaxInboundNeighborCount { return nil, ErrTooManyNeighborsToReport - } else { - marshaledPackage[MarshaledInboundIdsLengthStart] = byte(lengthInboundIDs) } + marshaledPackage[MarshaledInboundIdsLengthStart] = byte(lengthInboundIDs) // End of length is the start of inbound nodeId-s MarshaledInboundIdsLengthEnd := MarshaledInboundIdsLengthStart + MarshaledInboundIDsLengthSize diff --git a/plugins/analysis/types/ping/constants.go b/plugins/analysis/types/ping/constants.go index 05b18da561669157b088357e58f74e8f853de304..71b18ed22711968422a4c2d3a842f882df2a8886 100644 --- a/plugins/analysis/types/ping/constants.go +++ b/plugins/analysis/types/ping/constants.go @@ -1,11 +1,16 @@ package ping const ( + // MarshaledPacketHeader defines the MarshaledPacketHeader. MarshaledPacketHeader = 0x00 + // MarshaledPacketHeaderStart defines the start of the MarshaledPacketHeader. MarshaledPacketHeaderStart = 0 - MarshaledPacketHeaderSize = 1 - MarshaledPacketHeaderEnd = MarshaledPacketHeaderStart + MarshaledPacketHeaderSize + // MarshaledPacketHeaderSize defines the size of the MarshaledPacketHeader. + MarshaledPacketHeaderSize = 1 + // MarshaledPacketHeaderEnd defines the end of the MarshaledPacketHeader. + MarshaledPacketHeaderEnd = MarshaledPacketHeaderStart + MarshaledPacketHeaderSize + // MarshaledTotalSize defines the total size of the MarshaledPacketHeader. MarshaledTotalSize = MarshaledPacketHeaderEnd ) diff --git a/plugins/analysis/types/ping/packet.go b/plugins/analysis/types/ping/packet.go index cfa624c4e2e7b3f8a1e71e4bc926a60698b527ae..28df9c321af890e1afa35bbcb0625c2d4656732c 100644 --- a/plugins/analysis/types/ping/packet.go +++ b/plugins/analysis/types/ping/packet.go @@ -3,11 +3,14 @@ package ping import "errors" var ( + // ErrMalformedPingPacket defines the malformed ping packet error. ErrMalformedPingPacket = errors.New("malformed ping packet") ) +// Packet defines the Packet type as an empty struct. type Packet struct{} +// Unmarshal unmarshals a given slice of byte and returns a *Packet and an error. func Unmarshal(data []byte) (*Packet, error) { if len(data) < MarshaledTotalSize || data[MarshaledPacketHeaderStart] != MarshaledPacketHeader { return nil, ErrMalformedPingPacket @@ -18,6 +21,7 @@ func Unmarshal(data []byte) (*Packet, error) { return unmarshaledPacket, nil } +// Marshal marshals a given *Packet and returns the marshaled slice of byte. func (packet *Packet) Marshal() []byte { marshaledPackage := make([]byte, MarshaledTotalSize) diff --git a/plugins/analysis/webinterface/httpserver/parameters.go b/plugins/analysis/webinterface/httpserver/parameters.go index c7f29c9fa1a8bb0876005491a519c5c566c09ff0..1df15cc297820faae707150ef74185bc71342cba 100644 --- a/plugins/analysis/webinterface/httpserver/parameters.go +++ b/plugins/analysis/webinterface/httpserver/parameters.go @@ -5,8 +5,10 @@ import ( ) const ( + // CfgBindAddress defines the config flag of the analysis http server binding address. CfgBindAddress = "analysis.httpServer.bindAddress" - CfgDev = "analysis.httpServer.dev" + // CfgDev defines the config flag of the analysis http server dev mode. + CfgDev = "analysis.httpServer.dev" ) func init() { diff --git a/plugins/analysis/webinterface/httpserver/plugin.go b/plugins/analysis/webinterface/httpserver/plugin.go index 7da249c8ad2aa99fc17f7a59a22b1cdd05a8355f..dbfd4dc89b01dbc18494913e28808b30f952be72 100644 --- a/plugins/analysis/webinterface/httpserver/plugin.go +++ b/plugins/analysis/webinterface/httpserver/plugin.go @@ -25,6 +25,7 @@ const name = "Analysis HTTP Server" var assetsBox = packr.New("Assets", "./static") +// Configure configures the plugin. func Configure() { log = logger.NewLogger(name) @@ -45,6 +46,7 @@ func Configure() { engine.GET("/datastream", echo.WrapHandler(websocket.Handler(dataStream))) } +// Run runs the plugin. func Run() { log.Infof("Starting %s ...", name) if err := daemon.BackgroundWorker(name, start, shutdown.PriorityAnalysis); err != nil { diff --git a/plugins/analysis/webinterface/httpserver/websocket_channel.go b/plugins/analysis/webinterface/httpserver/websocket_channel.go index 38a04a7dcad82fe1d635115206cc29aca7ec4adf..91698112554ad53a7bcd9c20f7e5fd24ad000db6 100644 --- a/plugins/analysis/webinterface/httpserver/websocket_channel.go +++ b/plugins/analysis/webinterface/httpserver/websocket_channel.go @@ -6,11 +6,13 @@ import ( "golang.org/x/net/websocket" ) +// WebSocketChannel holds the websocket connection and its channel. type WebSocketChannel struct { ws *websocket.Conn send chan string } +// NewWebSocketChannel returns a new *WebSocketChannel for the given websocket connection. func NewWebSocketChannel(ws *websocket.Conn) *WebSocketChannel { wsChan := &WebSocketChannel{ ws: ws, @@ -22,10 +24,12 @@ func NewWebSocketChannel(ws *websocket.Conn) *WebSocketChannel { return wsChan } +// Write writes into the given WebSocketChannel. func (c *WebSocketChannel) Write(update string) { c.send <- update } +// KeepAlive keeps the websocket connection alive. func (c *WebSocketChannel) KeepAlive() { buf := make([]byte, 1) for { @@ -37,6 +41,7 @@ func (c *WebSocketChannel) KeepAlive() { } } +// Close closes the WebSocketChannel. func (c *WebSocketChannel) Close() { close(c.send) _ = c.ws.Close() diff --git a/plugins/analysis/webinterface/plugin.go b/plugins/analysis/webinterface/plugin.go index 447f1c42b4aeb0e78ca5592b48f448c8cbbd1bb7..15e5778a1696b596e950598dba4659fe90de20af 100644 --- a/plugins/analysis/webinterface/plugin.go +++ b/plugins/analysis/webinterface/plugin.go @@ -6,11 +6,13 @@ import ( "github.com/iotaledger/hive.go/node" ) +// Configure configures the plugin. func Configure(plugin *node.Plugin) { httpserver.Configure() recordedevents.Configure(plugin) } +// Run runs the plugin. func Run(plugin *node.Plugin) { httpserver.Run() recordedevents.Run() diff --git a/plugins/analysis/webinterface/recordedevents/recorded_events.go b/plugins/analysis/webinterface/recordedevents/recorded_events.go index 9e30c88d3af371124348cf0931145fe7ddb81613..c6957beacf8d9b16db3823a04219d3fbd1ebfb9f 100644 --- a/plugins/analysis/webinterface/recordedevents/recorded_events.go +++ b/plugins/analysis/webinterface/recordedevents/recorded_events.go @@ -23,6 +23,7 @@ var links = make(map[string]map[string]time.Time) var lock sync.Mutex +// Configure configures the plugin. func Configure(plugin *node.Plugin) { server.Events.Heartbeat.Attach(events.NewClosure(func(packet heartbeat.Packet) { var out strings.Builder @@ -42,15 +43,15 @@ func Configure(plugin *node.Plugin) { lock.Lock() defer lock.Unlock() - nodeIdString := hex.EncodeToString(packet.OwnID) + nodeIDString := hex.EncodeToString(packet.OwnID) timestamp := time.Now() // When node is new, add to graph - if _, isAlready := nodes[nodeIdString]; !isAlready { - server.Events.AddNode.Trigger(nodeIdString) + if _, isAlready := nodes[nodeIDString]; !isAlready { + server.Events.AddNode.Trigger(nodeIDString) } // Save it + update timestamp - nodes[nodeIdString] = timestamp + nodes[nodeIDString] = timestamp // Outgoing neighbor links update for _, outgoingNeighbor := range packet.OutboundIDs { @@ -65,17 +66,17 @@ func Configure(plugin *node.Plugin) { nodes[outgoingNeighborString] = timestamp // Do we have any links already with src=nodeIdString? - if _, isAlready := links[nodeIdString]; !isAlready { + if _, isAlready := links[nodeIDString]; !isAlready { // Nope, so we have to allocate an empty map to be nested in links for nodeIdString - links[nodeIdString] = make(map[string]time.Time) + links[nodeIDString] = make(map[string]time.Time) } // Update graph when connection hasn't been seen before - if _, isAlready := links[nodeIdString][outgoingNeighborString]; !isAlready { - server.Events.ConnectNodes.Trigger(nodeIdString, outgoingNeighborString) + if _, isAlready := links[nodeIDString][outgoingNeighborString]; !isAlready { + server.Events.ConnectNodes.Trigger(nodeIDString, outgoingNeighborString) } // Update links - links[nodeIdString][outgoingNeighborString] = timestamp + links[nodeIDString][outgoingNeighborString] = timestamp } // Incoming neighbor links update @@ -97,15 +98,16 @@ func Configure(plugin *node.Plugin) { } // Update graph when connection hasn't been seen before - if _, isAlready := links[incomingNeighborString][nodeIdString]; !isAlready { - server.Events.ConnectNodes.Trigger(incomingNeighborString, nodeIdString) + if _, isAlready := links[incomingNeighborString][nodeIDString]; !isAlready { + server.Events.ConnectNodes.Trigger(incomingNeighborString, nodeIDString) } // Update links map - links[incomingNeighborString][nodeIdString] = timestamp + links[incomingNeighborString][nodeIDString] = timestamp } })) } +// Run runs the plugin. func Run() { daemon.BackgroundWorker("Analysis Server Record Manager", func(shutdownSignal <-chan struct{}) { ticker := time.NewTicker(CleanUpPeriod) @@ -171,6 +173,7 @@ func getEventsToReplay() (map[string]time.Time, map[string]map[string]time.Time) return copiedNodes, copiedLinks } +// Replay runs the handlers on the events to replay. func Replay(handlers *types.EventHandlers) { copiedNodes, copiedLinks := getEventsToReplay() diff --git a/plugins/analysis/webinterface/types/types.go b/plugins/analysis/webinterface/types/types.go index 76aca004ea0c8fca6c0a11573cbfa629b7e33419..f9266dc789f0535df55b25afcd9c4f84c6c5c5a3 100644 --- a/plugins/analysis/webinterface/types/types.go +++ b/plugins/analysis/webinterface/types/types.go @@ -1,10 +1,16 @@ package types +// EventHandlers holds the handler for each event. type EventHandlers = struct { - AddNode func(nodeId string) - RemoveNode func(nodeId string) - ConnectNodes func(sourceId string, targetId string) + // Addnode defines the handler called when adding a new node. + AddNode func(nodeId string) + // RemoveNode defines the handler called when adding removing a node. + RemoveNode func(nodeId string) + // ConnectNodes defines the handler called when connecting two nodes. + ConnectNodes func(sourceId string, targetId string) + // DisconnectNodes defines the handler called when connecting two nodes. DisconnectNodes func(sourceId string, targetId string) } +// EventHandlersConsumer defines the consumer function of an *EventHandlers. type EventHandlersConsumer = func(handler *EventHandlers)