mirror of
https://gitlab.com/pulsechaincom/prysm-pulse.git
synced 2024-12-31 23:41:22 +00:00
0559d01261
* Preliminary support for relay nodes * lint * Add comment, remove TODO * work on relay address factory * dial relay node, if available * forgot new files * fix service registry breakage * added logging * Added a peer count with prometheus * always start mDNS * fix lint
40 lines
675 B
Go
40 lines
675 B
Go
package p2p
|
|
|
|
import (
|
|
"context"
|
|
"time"
|
|
|
|
"github.com/libp2p/go-libp2p-host"
|
|
"github.com/prometheus/client_golang/prometheus"
|
|
)
|
|
|
|
var (
|
|
peerCountMetric = prometheus.NewGauge(prometheus.GaugeOpts{
|
|
Name: "p2p_peer_count",
|
|
Help: "The number of currently connected peers",
|
|
})
|
|
)
|
|
|
|
func init() {
|
|
prometheus.MustRegister(peerCountMetric)
|
|
}
|
|
|
|
func startPeerWatcher(ctx context.Context, h host.Host) {
|
|
|
|
go (func() {
|
|
for {
|
|
select {
|
|
case <-ctx.Done():
|
|
return
|
|
default:
|
|
// Update peer count (minus ourselves)
|
|
peerCountMetric.Set(float64(len(h.Peerstore().Peers()) - 1))
|
|
|
|
// Wait 1 second to update again
|
|
time.Sleep(1 * time.Second)
|
|
}
|
|
}
|
|
})()
|
|
|
|
}
|