status-go/peers
Andrea Maria Piana 58fcf809ea
Bug/fix pending peers segfault (#2004)
* Replace mclock with time in peer pools

we used mclock as golang before 1.9 did not support monotonic clocks,
https://github.com/gavv/monotime, it does now https://golang.org/pkg/time/
so we can fallback on the system implementation, which will return
nanoseconds with a resolution that is system dependent.

* Handle case where peer have same discovered time

In some system the resolution of the clock is not high enough so
multiple peers are added on the same nanosecond.

This result in the peer just added being immediately removed.

This code adds a check making sure we don't assume that a peer is added.

Another approach would be to make sure to include the peer in the list,
so prevent the peer just being added to be evicted, but it's slightly
more complicated and the resolution is generally accurate enough for our
purpose so that peers will be fresh enough if they have the same
discovered time.

It also adds a regression test, I had to use an interface to stub the
clock.

Fixes: https://github.com/status-im/nim-status-client/issues/522

* bump version to 0.55.3
2020-07-24 11:14:05 -04:00
..
verifier Use goimports instead of gofmt 2020-01-06 10:17:23 +01:00
README.md [#856] move geth subpackages to root level (#1007) 2018-06-08 13:29:50 +02:00
cache.go Use goimports instead of gofmt 2020-01-06 10:17:23 +01:00
cache_test.go Use goimports instead of gofmt 2020-01-06 10:17:23 +01:00
cotopicpool.go Use goimports instead of gofmt 2020-01-06 10:17:23 +01:00
cotopicpool_test.go Use goimports instead of gofmt 2020-01-06 10:17:23 +01:00
peerpool.go Bug/fix pending peers segfault (#2004) 2020-07-24 11:14:05 -04:00
peerpool_test.go Use goimports instead of gofmt 2020-01-06 10:17:23 +01:00
signal.go Use goimports instead of gofmt 2020-01-06 10:17:23 +01:00
topic_peer_queue.go Bug/fix pending peers segfault (#2004) 2020-07-24 11:14:05 -04:00
topic_peer_queue_test.go Bug/fix pending peers segfault (#2004) 2020-07-24 11:14:05 -04:00
topic_register.go Use goimports instead of gofmt 2020-01-06 10:17:23 +01:00
topicpool.go Bug/fix pending peers segfault (#2004) 2020-07-24 11:14:05 -04:00
topicpool_test.go Bug/fix pending peers segfault (#2004) 2020-07-24 11:14:05 -04:00

README.md

Peer pool signals

Peer pool sends 3 types of signals.

Discovery started signal will be sent once discovery server is started. And every time node will have to re-start discovery server because peer number dropped too low.

{
  "type": "discovery.started",
  "event": null
}

Discovery stopped signal will be sent once discovery found max limit of peers for every registered topic.

{
  "type": "discovery.stopped",
  "event": null
}

Discovery summary signal will be sent every time new peer is added or removed from a cluster. It will contain a map with capability as a key and total numbers of peers with that capability as a value.

{
  "type": "discovery.summary",
  "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:

{
  "type": "discovery.summary",
  "event": []
}