p2pgrpc

package module
v0.0.0-...-c6820d0 Latest Latest
Warning

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

Go to latest
Published: Aug 21, 2023 License: MIT Imports: 13 Imported by: 5

README

go-libp2p-grpc

go-libp2p-grpc provides gRPC support on top of libp2p.

Install

$ go get github.com/birros/go-libp2p-grpc

Usage

Examples

Examples can be found in the examples folder.

Contributing

PRs accepted.

Small note: If editing the Readme, please conform to the standard-readme specification.

Inspirations

This repo is heavily inspired by go-libp2p-grpc.

License

MIT © Birros

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewListener

func NewListener(
	ctx context.Context,
	h host.Host,
	pid protocol.ID,
) net.Listener

NewListener turns a libp2p host into a net listener.

func RemotePeerFromContext

func RemotePeerFromContext(ctx context.Context) (peer.ID, bool)

RemotePeerFromContext extracts remote peer from ctx

func WithP2PCredentials

func WithP2PCredentials() grpc.ServerOption

WithP2PCredentials exposes the libp2p stream to the grpc service via a custom AuthInfo.

func WithP2PDialer

func WithP2PDialer(h host.Host, pid protocol.ID) grpc.DialOption

WithP2PDialer uses a libp2p host as dialer. Use the id of the target host to create a connection. The dialer does not connect the current host to the target host, this must be checked before establishing a connection. It just wraps a gRPC connection in a libp2p stream.

Types

type AuthInfo

type AuthInfo struct {
	Stream network.Stream
}

AuthInfo embed original libp2p stream

func AuthInfoFromContext

func AuthInfoFromContext(ctx context.Context) (AuthInfo, bool)

AuthInfoFromContext extracts p2p AuthInfo from ctx

func (AuthInfo) AuthType

func (ai AuthInfo) AuthType() string

AuthType ...

type Conn

type Conn struct {
	network.Stream
}

Conn as libp2p stream

func (Conn) LocalAddr

func (c Conn) LocalAddr() net.Addr

LocalAddr shows local peer net addr

func (Conn) RemoteAddr

func (c Conn) RemoteAddr() net.Addr

RemoteAddr shows remote peer net addr

Directories

Path Synopsis
examples
echo Module

Jump to

Keyboard shortcuts

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