mirror of
https://gitlab.com/pulsechaincom/erigon-pulse.git
synced 2024-12-22 03:30:37 +00:00
Diag session routing (#8317)
Co-authored-by: Mark Holt <mark@distributed.vision>
This commit is contained in:
parent
669503d38f
commit
2cbd446e88
4
.gitignore
vendored
4
.gitignore
vendored
@ -90,3 +90,7 @@ caplin-recordings
|
||||
jwt.hex
|
||||
|
||||
.tool-versions
|
||||
|
||||
*__debug_bin*
|
||||
yarn.lock
|
||||
node_modules
|
||||
|
58
diagnostics/peers.go
Normal file
58
diagnostics/peers.go
Normal file
@ -0,0 +1,58 @@
|
||||
package diagnostics
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"net/http"
|
||||
|
||||
"github.com/ledgerwatch/erigon/p2p"
|
||||
"github.com/ledgerwatch/erigon/turbo/node"
|
||||
"github.com/urfave/cli/v2"
|
||||
)
|
||||
|
||||
func SetupPeersAccess(ctx *cli.Context, metricsMux *http.ServeMux, node *node.ErigonNode) {
|
||||
metricsMux.HandleFunc("/peers", func(w http.ResponseWriter, r *http.Request) {
|
||||
w.Header().Set("Access-Control-Allow-Origin", "*")
|
||||
w.Header().Set("Content-Type", "application/json")
|
||||
writePeers(w, ctx, node)
|
||||
})
|
||||
}
|
||||
|
||||
func writePeers(w http.ResponseWriter, ctx *cli.Context, node *node.ErigonNode) {
|
||||
reply, err := node.Backend().Peers(context.Background())
|
||||
|
||||
if err != nil {
|
||||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
|
||||
peers := make([]*p2p.PeerInfo, 0, len(reply.Peers))
|
||||
|
||||
for _, rpcPeer := range reply.Peers {
|
||||
peer := p2p.PeerInfo{
|
||||
ENR: rpcPeer.Enr,
|
||||
Enode: rpcPeer.Enode,
|
||||
ID: rpcPeer.Id,
|
||||
Name: rpcPeer.Name,
|
||||
Caps: rpcPeer.Caps,
|
||||
Network: struct {
|
||||
LocalAddress string `json:"localAddress"`
|
||||
RemoteAddress string `json:"remoteAddress"`
|
||||
Inbound bool `json:"inbound"`
|
||||
Trusted bool `json:"trusted"`
|
||||
Static bool `json:"static"`
|
||||
}{
|
||||
LocalAddress: rpcPeer.ConnLocalAddr,
|
||||
RemoteAddress: rpcPeer.ConnRemoteAddr,
|
||||
Inbound: rpcPeer.ConnIsInbound,
|
||||
Trusted: rpcPeer.ConnIsTrusted,
|
||||
Static: rpcPeer.ConnIsStatic,
|
||||
},
|
||||
Protocols: nil,
|
||||
}
|
||||
|
||||
peers = append(peers, &peer)
|
||||
}
|
||||
|
||||
json.NewEncoder(w).Encode(peers)
|
||||
}
|
@ -25,4 +25,6 @@ func Setup(ctx *cli.Context, metricsMux *http.ServeMux, node *node.ErigonNode) {
|
||||
SetupBlockBodyDownload(debugMux)
|
||||
SetupHeaderDownloadStats(debugMux)
|
||||
SetupNodeInfoAccess(debugMux, node)
|
||||
SetupPeersAccess(ctx, debugMux, node)
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user