Skip to content
Snippets Groups Projects
Commit d01c5f3c authored by capossele's avatar capossele
Browse files

:loud_sound: adds report for knownPeers and AcceptedNeighbors

parent 561483d3
No related branches found
No related tags found
No related merge requests found
...@@ -80,7 +80,9 @@ func reportCurrentStatus(eventDispatchers *EventDispatchers) { ...@@ -80,7 +80,9 @@ func reportCurrentStatus(eventDispatchers *EventDispatchers) {
eventDispatchers.AddNode(local.GetInstance().ID().Bytes()) eventDispatchers.AddNode(local.GetInstance().ID().Bytes())
} }
reportKnownPeers(eventDispatchers)
reportChosenNeighbors(eventDispatchers) reportChosenNeighbors(eventDispatchers)
reportAcceptedNeighbors(eventDispatchers)
} }
func setupHooks(plugin *node.Plugin, conn *network.ManagedConnection, eventDispatchers *EventDispatchers) { func setupHooks(plugin *node.Plugin, conn *network.ManagedConnection, eventDispatchers *EventDispatchers) {
...@@ -123,6 +125,7 @@ func setupHooks(plugin *node.Plugin, conn *network.ManagedConnection, eventDispa ...@@ -123,6 +125,7 @@ func setupHooks(plugin *node.Plugin, conn *network.ManagedConnection, eventDispa
var onClose *events.Closure var onClose *events.Closure
onClose = events.NewClosure(func() { onClose = events.NewClosure(func() {
discover.Events.PeerDiscovered.Detach(onDiscoverPeer) discover.Events.PeerDiscovered.Detach(onDiscoverPeer)
discover.Events.PeerDeleted.Detach(onDeletePeer)
selection.Events.IncomingPeering.Detach(onAddAcceptedNeighbor) selection.Events.IncomingPeering.Detach(onAddAcceptedNeighbor)
selection.Events.OutgoingPeering.Detach(onAddChosenNeighbor) selection.Events.OutgoingPeering.Detach(onAddChosenNeighbor)
selection.Events.Dropped.Detach(onRemoveNeighbor) selection.Events.Dropped.Detach(onRemoveNeighbor)
...@@ -132,15 +135,32 @@ func setupHooks(plugin *node.Plugin, conn *network.ManagedConnection, eventDispa ...@@ -132,15 +135,32 @@ func setupHooks(plugin *node.Plugin, conn *network.ManagedConnection, eventDispa
conn.Events.Close.Attach(onClose) conn.Events.Close.Attach(onClose)
} }
func reportKnownPeers(dispatchers *EventDispatchers) {
if autopeering.Discovery != nil {
for _, peer := range autopeering.Discovery.GetVerifiedPeers() {
dispatchers.AddNode(peer.ID().Bytes())
}
}
}
func reportChosenNeighbors(dispatchers *EventDispatchers) { func reportChosenNeighbors(dispatchers *EventDispatchers) {
if autopeering.Selection != nil { if autopeering.Selection != nil {
for _, chosenNeighbor := range autopeering.Selection.GetOutgoingNeighbors() { for _, chosenNeighbor := range autopeering.Selection.GetOutgoingNeighbors() {
dispatchers.AddNode(chosenNeighbor.ID().Bytes()) //dispatchers.AddNode(chosenNeighbor.ID().Bytes())
dispatchers.ConnectNodes(local.GetInstance().ID().Bytes(), chosenNeighbor.ID().Bytes()) dispatchers.ConnectNodes(local.GetInstance().ID().Bytes(), chosenNeighbor.ID().Bytes())
} }
} }
} }
func reportAcceptedNeighbors(dispatchers *EventDispatchers) {
if autopeering.Selection != nil {
for _, acceptedNeighbor := range autopeering.Selection.GetIncomingNeighbors() {
//dispatchers.AddNode(acceptedNeighbor.ID().Bytes())
dispatchers.ConnectNodes(local.GetInstance().ID().Bytes(), acceptedNeighbor.ID().Bytes())
}
}
}
func keepConnectionAlive(conn *network.ManagedConnection, shutdownSignal <-chan struct{}) bool { func keepConnectionAlive(conn *network.ManagedConnection, shutdownSignal <-chan struct{}) bool {
go conn.Read(make([]byte, 1)) go conn.Read(make([]byte, 1))
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment