Select Git revision
parameters.go
plugin.go 5.53 KiB
package client
import (
"encoding/hex"
"net"
"time"
"github.com/iotaledger/goshimmer/plugins/autopeering/local"
"github.com/iotaledger/autopeering-sim/discover"
"github.com/iotaledger/autopeering-sim/selection"
"github.com/iotaledger/goshimmer/packages/network"
"github.com/iotaledger/goshimmer/packages/timeutil"
"github.com/iotaledger/goshimmer/plugins/analysis/types/addnode"
"github.com/iotaledger/goshimmer/plugins/analysis/types/connectnodes"
"github.com/iotaledger/goshimmer/plugins/analysis/types/disconnectnodes"
"github.com/iotaledger/goshimmer/plugins/analysis/types/ping"
"github.com/iotaledger/goshimmer/plugins/analysis/types/removenode"
"github.com/iotaledger/goshimmer/plugins/autopeering"
"github.com/iotaledger/hive.go/daemon"
"github.com/iotaledger/hive.go/events"
"github.com/iotaledger/hive.go/logger"
"github.com/iotaledger/hive.go/node"
"github.com/iotaledger/hive.go/parameter"
)
var log = logger.NewLogger("Analysis-Client")
func Run(plugin *node.Plugin) {
daemon.BackgroundWorker("Analysis Client", func() {
shuttingDown := false
for !shuttingDown {
select {
case <-daemon.ShutdownSignal:
return
default:
if conn, err := net.Dial("tcp", parameter.NodeConfig.GetString(CFG_SERVER_ADDRESS)); err != nil {
log.Debugf("Could not connect to reporting server: %s", err.Error())
timeutil.Sleep(1 * time.Second)
} else {
managedConn := network.NewManagedConnection(conn)
eventDispatchers := getEventDispatchers(managedConn)
reportCurrentStatus(eventDispatchers)
setupHooks(plugin, managedConn, eventDispatchers)
shuttingDown = keepConnectionAlive(managedConn)
}
}
}
})
}
func getEventDispatchers(conn *network.ManagedConnection) *EventDispatchers {
return &EventDispatchers{
AddNode: func(nodeId []byte) {
_, _ = conn.Write((&addnode.Packet{NodeId: nodeId}).Marshal())
},
RemoveNode: func(nodeId []byte) {
_, _ = conn.Write((&removenode.Packet{NodeId: nodeId}).Marshal())
},
ConnectNodes: func(sourceId []byte, targetId []byte) {
_, _ = conn.Write((&connectnodes.Packet{SourceId: sourceId, TargetId: targetId}).Marshal())
},
DisconnectNodes: func(sourceId []byte, targetId []byte) {
_, _ = conn.Write((&disconnectnodes.Packet{SourceId: sourceId, TargetId: targetId}).Marshal())
},