Skip to content
Snippets Groups Projects
Select Git revision
  • dfd97b643e508ce7eb5fff176e9252635cb02c5a
  • 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 3.42 KiB
    package autopeering
    
    import (
    	"github.com/iotaledger/goshimmer/packages/daemon"
    	"github.com/iotaledger/goshimmer/packages/events"
    	"github.com/iotaledger/goshimmer/packages/node"
    	"github.com/iotaledger/goshimmer/plugins/autopeering/instances"
    	"github.com/iotaledger/goshimmer/plugins/autopeering/instances/acceptedneighbors"
    	"github.com/iotaledger/goshimmer/plugins/autopeering/instances/chosenneighbors"
    	"github.com/iotaledger/goshimmer/plugins/autopeering/instances/knownpeers"
    	"github.com/iotaledger/goshimmer/plugins/autopeering/peerstorage"
    	"github.com/iotaledger/goshimmer/plugins/autopeering/protocol"
    	"github.com/iotaledger/goshimmer/plugins/autopeering/saltmanager"
    	"github.com/iotaledger/goshimmer/plugins/autopeering/server"
    	"github.com/iotaledger/goshimmer/plugins/autopeering/types/peer"
    	"github.com/iotaledger/goshimmer/plugins/gossip"
    )
    
    var PLUGIN = node.NewPlugin("Auto Peering", node.Enabled, configure, run)
    
    func configure(plugin *node.Plugin) {
    	saltmanager.Configure(plugin)
    	instances.Configure(plugin)
    	server.Configure(plugin)
    	protocol.Configure(plugin)
    	peerstorage.Configure(plugin)
    
    	daemon.Events.Shutdown.Attach(events.NewClosure(func() {
    		server.Shutdown(plugin)
    	}))
    
    	configureLogging(plugin)
    }
    
    func run(plugin *node.Plugin) {
    	instances.Run(plugin)
    	server.Run(plugin)
    	protocol.Run(plugin)
    }
    
    func configureLogging(plugin *node.Plugin) {
    	gossip.Events.RemoveNeighbor.Attach(events.NewClosure(func(peer *gossip.Neighbor) {
    		chosenneighbors.INSTANCE.Remove(peer.GetIdentity().StringIdentifier)
    		acceptedneighbors.INSTANCE.Remove(peer.GetIdentity().StringIdentifier)
    	}))
    
    	acceptedneighbors.INSTANCE.Events.Add.Attach(events.NewClosure(func(p *peer.Peer) {
    		plugin.LogDebug("accepted neighbor added: " + p.GetAddress().String() + " / " + p.GetIdentity().StringIdentifier)
    
    		gossip.AddNeighbor(gossip.NewNeighbor(p.GetIdentity(), p.GetAddress(), p.GetGossipPort()))
    	}))
    	acceptedneighbors.INSTANCE.Events.Remove.Attach(events.NewClosure(func(p *peer.Peer) {
    		plugin.LogDebug("accepted neighbor removed: " + p.GetAddress().String() + " / " + p.GetIdentity().StringIdentifier)
    
    		gossip.RemoveNeighbor(p.GetIdentity().StringIdentifier)
    	}))
    
    	chosenneighbors.INSTANCE.Events.Add.Attach(events.NewClosure(func(p *peer.Peer) {
    		plugin.LogDebug("chosen neighbor added: " + p.GetAddress().String() + " / " + p.GetIdentity().StringIdentifier)
    
    		gossip.AddNeighbor(gossip.NewNeighbor(p.GetIdentity(), p.GetAddress(), p.GetGossipPort()))
    	}))
    	chosenneighbors.INSTANCE.Events.Remove.Attach(events.NewClosure(func(p *peer.Peer) {
    		plugin.LogDebug("chosen neighbor removed: " + p.GetAddress().String() + " / " + p.GetIdentity().StringIdentifier)
    
    		gossip.RemoveNeighbor(p.GetIdentity().StringIdentifier)
    	}))
    
    	knownpeers.INSTANCE.Events.Add.Attach(events.NewClosure(func(p *peer.Peer) {
    		plugin.LogInfo("new peer discovered: " + p.GetAddress().String() + " / " + p.GetIdentity().StringIdentifier)
    
    		if _, exists := gossip.GetNeighbor(p.GetIdentity().StringIdentifier); exists {
    			gossip.AddNeighbor(gossip.NewNeighbor(p.GetIdentity(), p.GetAddress(), p.GetGossipPort()))
    		}
    	}))
    	knownpeers.INSTANCE.Events.Update.Attach(events.NewClosure(func(p *peer.Peer) {
    		plugin.LogDebug("peer updated: " + p.GetAddress().String() + " / " + p.GetIdentity().StringIdentifier)
    
    		if _, exists := gossip.GetNeighbor(p.GetIdentity().StringIdentifier); exists {
    			gossip.AddNeighbor(gossip.NewNeighbor(p.GetIdentity(), p.GetAddress(), p.GetGossipPort()))
    		}
    	}))
    }