Skip to content
Snippets Groups Projects
Select Git revision
  • 626a96ddd7fc127238db43ab1e112304543f6ecd
  • without_tipselection default
  • develop protected
  • fix/grafana-local-dashboard
  • wasp
  • fix/dashboard-explorer-freeze
  • master
  • feat/timerqueue
  • test/sync_debug_and_650
  • feat/sync_revamp_inv
  • wip/sync
  • tool/db-recovery
  • portcheck/fix
  • fix/synchronization
  • feat/new-dashboard-analysis
  • feat/refactored-analysis-dashboard
  • feat/new-analysis-dashboard
  • test/demo-prometheus-fpc
  • prometheus_metrics
  • wip/analysis-server
  • merge/fpc-test-value-transfer
  • v0.2.2
  • v0.2.1
  • v0.2.0
  • v0.1.3
  • v0.1.2
  • v0.1.1
  • v0.1.0
28 results

plugin.go

Blame
  • plugin.go 5.76 KiB
    package spa
    
    import (
    	"net/http"
    	"runtime"
    	"sync"
    	"time"
    
    	"github.com/gorilla/websocket"
    	"github.com/iotaledger/hive.go/autopeering/peer/service"
    	"github.com/labstack/echo"
    	"github.com/labstack/echo/middleware"
    
    	"github.com/iotaledger/goshimmer/packages/shutdown"
    	"github.com/iotaledger/goshimmer/plugins/autopeering"
    	"github.com/iotaledger/goshimmer/plugins/autopeering/local"
    	"github.com/iotaledger/goshimmer/plugins/cli"
    	"github.com/iotaledger/goshimmer/plugins/config"
    	"github.com/iotaledger/goshimmer/plugins/gossip"
    	"github.com/iotaledger/goshimmer/plugins/metrics"
    
    	"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/workerpool"
    )
    
    var (
    	PLUGIN = node.NewPlugin("SPA", node.Enabled, configure, run)
    	log    *logger.Logger
    
    	nodeStartAt = time.Now()
    
    	clientsMu    sync.Mutex
    	clients             = make(map[uint64]chan interface{}, 0)
    	nextClientID uint64 = 0
    
    	wsSendWorkerCount     = 1
    	wsSendWorkerQueueSize = 250
    	wsSendWorkerPool      *workerpool.WorkerPool
    )
    
    func configure(plugin *node.Plugin) {
    	log = logger.NewLogger(plugin.Name)
    
    	wsSendWorkerPool = workerpool.New(func(task workerpool.Task) {
    		sendToAllWSClient(&msg{MsgTypeTPSMetric, task.Param(0).(uint64)})
    		sendToAllWSClient(&msg{MsgTypeNodeStatus, currentNodeStatus()})
    		sendToAllWSClient(&msg{MsgTypeNeighborMetric, neighborMetrics()})
    		task.Return(nil)
    	}, workerpool.WorkerCount(wsSendWorkerCount), workerpool.QueueSize(wsSendWorkerQueueSize))
    
    	configureLiveFeed()
    }
    
    func run(plugin *node.Plugin) {
    
    	notifyStatus := events.NewClosure(func(tps uint64) {
    		wsSendWorkerPool.TrySubmit(tps)
    	})
    
    	daemon.BackgroundWorker("SPA[WSSend]", func(shutdownSignal <-chan struct{}) {
    		metrics.Events.ReceivedTPSUpdated.Attach(notifyStatus)
    		wsSendWorkerPool.Start()
    		<-shutdownSignal
    		log.Info("Stopping SPA[WSSend] ...")
    		metrics.Events.ReceivedTPSUpdated.Detach(notifyStatus)
    		wsSendWorkerPool.Stop()
    		log.Info("Stopping SPA[WSSend] ... done")