A lightweight libp2p host service that exposes general information about the host and the network.
go get github.com/drgomesp/go-libp2p-hostinfo
- A gRPC service that exposes general host/network information
- HTTP/OpenAPI gateway support
- Support for configurable info to expose
For a given libp2p host, create a new hostinfo.Service
and start it:
host, err := libp2p.New()
if err != nil {
log.Fatal(err)
}
// create a mux to handle the grpc gateway requests
// this can also be combined with other muxes
mux := runtime.NewServeMux()
ctx := context.Background()
svc, err := hostinfo.NewService(
ctx,
host,
hostinfo.WithGrpcGatewayAddr(":4000"),
hostinfo.WithHttpServeMux(mux),
)
go svc.ListenAndServe()
log.Println("visit: http://localhost:4000/v1/hostinfo")
<-ctx.Done()
You should now be able to access the hostinfo endpoint:
$ curl http://localhost:4000/v1/hostinfo | jq
{
"id": "QmRmkUZCHZ1LdvayoKFtevmzE7RzkVVjGKA6uZ9yHoPCUW",
"addresses": [
"/ip4/127.0.0.1/tcp/46079/p2p/QmRmkUZCHZ1LdvayoKFtevmzE7RzkVVjGKA6uZ9yHoPCUW"
],
"protocols": [
"/p2p/id/delta/1.0.0",
"/ipfs/id/1.0.0",
"/ipfs/id/push/1.0.0",
"/ipfs/ping/1.0.0",
"/libp2p/grpc/1.0.0"
],
"peers": []
}
PRs accepted.
MIT © Daniel Ribeiro