status-go/geth/peers/signal.go
Dmitry Shulyak f3e2631c1d
Add signals for notifying react about discovery activity (#859)
* Add signal for notifying react on discovery activity

* Whitelist expected signals in e2e tests
2018-04-25 10:13:59 +03:00

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,
})
}