Skip to content
Snippets Groups Projects
Select Git revision
  • 2c95e07db7ec5d739fff0495c88a9dbb4bab38cf
  • 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
  • user avatar
    capossele authored
    2c95e07d
    History
    plugin.go 1.71 KiB
    package autopeering
    
    import (
    	"net"
    
    	"github.com/iotaledger/autopeering-sim/discover"
    	"github.com/iotaledger/autopeering-sim/selection"
    	"github.com/iotaledger/goshimmer/packages/daemon"
    	"github.com/iotaledger/goshimmer/packages/node"
    	"github.com/iotaledger/goshimmer/plugins/gossip"
    	"github.com/iotaledger/hive.go/events"
    )
    
    func configure(plugin *node.Plugin) {
    	daemon.Events.Shutdown.Attach(events.NewClosure(func() {
    		close <- struct{}{}
    	}))
    
    	configureLogging(plugin)
    }
    
    func run(plugin *node.Plugin) {
    	go start()
    }
    
    func configureLogging(plugin *node.Plugin) {
    	gossip.Events.RemoveNeighbor.Attach(events.NewClosure(func(peer *gossip.Neighbor) {
    		Selection.DropPeer(peer.Peer)
    	}))
    
    	selection.Events.Dropped.Attach(events.NewClosure(func(ev *selection.DroppedEvent) {
    		plugin.LogDebug("neighbor removed: " + ev.DroppedID.String())
    		gossip.RemoveNeighbor(ev.DroppedID.String())
    	}))
    
    	selection.Events.IncomingPeering.Attach(events.NewClosure(func(ev *selection.PeeringEvent) {
    		plugin.LogDebug("accepted neighbor added: " + ev.Peer.Address() + " / " + ev.Peer.String())
    		address, port, _ := net.SplitHostPort(ev.Services["gossip"].Address)
    		gossip.AddNeighbor(gossip.NewNeighbor(ev.Peer, address, port))
    	}))
    
    	selection.Events.OutgoingPeering.Attach(events.NewClosure(func(ev *selection.PeeringEvent) {
    		plugin.LogDebug("chosen neighbor added: " + ev.Peer.Address() + " / " + ev.Peer.String())
    		address, port, _ := net.SplitHostPort(ev.Services["gossip"].Address)
    		gossip.AddNeighbor(gossip.NewNeighbor(ev.Peer, address, port))
    	}))
    
    	discover.Events.PeerDiscovered.Attach(events.NewClosure(func(ev *discover.DiscoveredEvent) {
    		plugin.LogInfo("new peer discovered: " + ev.Peer.Address() + " / " + ev.Peer.ID().String())
    	}))
    }