Dump peer infos as discovery summary
This commit is contained in:
parent
9268f55d7d
commit
9e65b5a6ae
|
@ -32,10 +32,26 @@ of peers with that capability as a value.
|
|||
```json
|
||||
{
|
||||
"type": "discovery.summary",
|
||||
"event": {
|
||||
"shh/6": 1
|
||||
"event": [
|
||||
{
|
||||
"id": "339c84c816b5f17a622c8d7ab9498f9998e942a274f70794af934bf5d3d02e14db8ddca2170e4edccede29ea6d409b154c141c34c01006e76c95e17672a27454",
|
||||
"name": "peer-0/v1.0/darwin/go1.10.1",
|
||||
"caps": [
|
||||
"shh/6"
|
||||
],
|
||||
"network": {
|
||||
"localAddress": "127.0.0.1:61049",
|
||||
"remoteAddress": "127.0.0.1:33732",
|
||||
"inbound": false,
|
||||
"trusted": false,
|
||||
"static": true
|
||||
},
|
||||
"protocols": {
|
||||
"shh": "unknown"
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
```
|
||||
|
||||
Or if we don't have any peers:
|
||||
|
@ -43,6 +59,6 @@ Or if we don't have any peers:
|
|||
```json
|
||||
{
|
||||
"type": "discovery.summary",
|
||||
"event": {}
|
||||
"event": []
|
||||
}
|
||||
```
|
||||
|
|
|
@ -106,7 +106,7 @@ func (s *PeerPoolSimulationSuite) getPoolEvent(events <-chan string) string {
|
|||
|
||||
func (s *PeerPoolSimulationSuite) TestSingleTopicDiscoveryWithFailover() {
|
||||
poolEvents := make(chan string, 1)
|
||||
summaries := make(chan map[string]int, 1)
|
||||
summaries := make(chan []*p2p.PeerInfo, 1)
|
||||
signal.SetDefaultNodeNotificationHandler(func(jsonEvent string) {
|
||||
var envelope struct {
|
||||
Type string
|
||||
|
@ -120,7 +120,7 @@ func (s *PeerPoolSimulationSuite) TestSingleTopicDiscoveryWithFailover() {
|
|||
poolEvents <- envelope.Type
|
||||
case signal.EventDiscoverySummary:
|
||||
poolEvents <- envelope.Type
|
||||
var summary map[string]int
|
||||
var summary []*p2p.PeerInfo
|
||||
s.NoError(json.Unmarshal(envelope.Event, &summary))
|
||||
summaries <- summary
|
||||
}
|
||||
|
@ -152,8 +152,6 @@ func (s *PeerPoolSimulationSuite) TestSingleTopicDiscoveryWithFailover() {
|
|||
s.Require().Equal(signal.EventDiscoverySummary, s.getPoolEvent(poolEvents))
|
||||
summary := <-summaries
|
||||
s.Len(summary, 1)
|
||||
s.Contains(summary, "shh/6")
|
||||
s.Equal(summary["shh/6"], 1)
|
||||
|
||||
register.Stop()
|
||||
s.peers[0].Stop()
|
||||
|
@ -175,8 +173,6 @@ func (s *PeerPoolSimulationSuite) TestSingleTopicDiscoveryWithFailover() {
|
|||
s.Require().Equal(signal.EventDiscoverySummary, s.getPoolEvent(poolEvents))
|
||||
summary = <-summaries
|
||||
s.Len(summary, 1)
|
||||
s.Contains(summary, "shh/6")
|
||||
s.Equal(summary["shh/6"], 1)
|
||||
}
|
||||
|
||||
// TestPeerPoolMaxPeersOverflow verifies that following scenario will not occur:
|
||||
|
|
|
@ -7,11 +7,5 @@ import (
|
|||
|
||||
// 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.SendDiscoverySummary(summary)
|
||||
signal.SendDiscoverySummary(peers)
|
||||
}
|
||||
|
|
|
@ -22,6 +22,6 @@ func SendDiscoveryStopped() {
|
|||
}
|
||||
|
||||
// SendDiscoverySummary sends discovery.summary signal.
|
||||
func SendDiscoverySummary(summary map[string]int) {
|
||||
func SendDiscoverySummary(summary interface{}) {
|
||||
send(EventDiscoverySummary, summary)
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue