mirror of
https://github.com/status-im/status-go.git
synced 2025-01-29 16:06:47 +00:00
f3e2631c1d
* Add signal for notifying react on discovery activity * Whitelist expected signals in e2e tests
46 lines
1.1 KiB
Go
46 lines
1.1 KiB
Go
package peers
|
|
|
|
import (
|
|
"github.com/ethereum/go-ethereum/p2p"
|
|
"github.com/status-im/status-go/geth/signal"
|
|
)
|
|
|
|
const (
|
|
// DiscoveryStarted is sent when node discv5 was started.
|
|
DiscoveryStarted = "discovery.started"
|
|
// DiscoveryStopped is sent when discv5 server was stopped.
|
|
DiscoveryStopped = "discovery.stopped"
|
|
|
|
// DiscoverySummary is sent when peer is added or removed.
|
|
// it will be a map with capability=peer count k/v's.
|
|
DiscoverySummary = "discovery.summary"
|
|
)
|
|
|
|
// SendDiscoveryStarted sends discovery.started signal.
|
|
func SendDiscoveryStarted() {
|
|
signal.Send(signal.Envelope{
|
|
Type: DiscoveryStarted,
|
|
})
|
|
}
|
|
|
|
// SendDiscoveryStopped sends discovery.stopped signal.
|
|
func SendDiscoveryStopped() {
|
|
signal.Send(signal.Envelope{
|
|
Type: DiscoveryStopped,
|
|
})
|
|
}
|
|
|
|
// SendDiscoverySummary sends discovery.summary signal.
|
|
func SendDiscoverySummary(peers []*p2p.PeerInfo) {
|
|
summary := map[string]int{}
|
|
for i := range peers {
|
|
for _, cap := range peers[i].Caps {
|
|
summary[cap]++
|
|
}
|
|
}
|
|
signal.Send(signal.Envelope{
|
|
Type: DiscoverySummary,
|
|
Event: summary,
|
|
})
|
|
}
|