hostinfo

package module
v0.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 9, 2022 License: MIT Imports: 11 Imported by: 0

README

go-libp2p-hostinfo

madeby Go Report Card build codecov

A lightweight libp2p host service that exposes general information about the host and the network.

Table of Contents

Install

go get github.com/drgomesp/go-libp2p-hostinfo

Features

  • A gRPC service that exposes general host/network information
  • HTTP/OpenAPI gateway support
  • Support for configurable info to expose

Usage

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": []
}

Contributing

PRs accepted.

License

MIT © Daniel Ribeiro

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Service

type Service struct {
	v1.UnimplementedHostInfoServiceServer
	// contains filtered or unexported fields
}

func NewService

func NewService(ctx context.Context, host host.Host, opts ...ServiceOption) (*Service, error)

func (*Service) Info

func (*Service) ListenAndServe

func (s *Service) ListenAndServe() error

type ServiceOption

type ServiceOption func(*Service)

func WithGrpcGatewayAddr

func WithGrpcGatewayAddr(addr string) ServiceOption

func WithHttpServeMux

func WithHttpServeMux(mux *runtime.ServeMux) ServiceOption

Directories

Path Synopsis
proto
v1
Package v1 is a reverse proxy.
Package v1 is a reverse proxy.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL