Categorygithub.com/libp2p/go-libp2p-gorpc
modulepackage
0.6.0
Repository: https://github.com/libp2p/go-libp2p-gorpc.git
Documentation: pkg.go.dev

# README

go-libp2p-gorpc

GoDoc Codecov Discourse posts

Simple Go RPC for libp2p.

go-libp2p-gorpc provides RPC support on top of libp2p in the same way that net/rpc does on HTTP with a few additional features like:

  • Streaming RPC calls using channels.
  • Contexts and async calls.

Table of Contents

Install

This module can be installed with go get:

> go get github.com/libp2p/go-libp2p-gorpc

This repo is gomod-compatible, and users of go 1.11 and later with modules enabled will automatically pull the latest tagged release by referencing this package. Upgrades to future releases can be managed using go get, or by editing your go.mod file as described by the gomod documentation.

Usage

Documentation for this module is maintained in pkg.go.dev.

There are also examples inside the examples directory

Contribute

PRs accepted.

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

License

MIT


The last gx published version of this module was: 1.1.4: QmcJCApoEsCJJap2iS1os9GFX5EuRrfuPeZdjCopz2SyPm

# Packages

No description provided by the author
No description provided by the author

# Functions

AuthorizeWithMap returns an authrorization function that follows the strategy as described in the given map(maps "service.method" of a peer to boolean permission).
GetRequestSender gets current request sender from RPC service's function context.
IsAuthorizationError returns whether an error is authorizationError.
IsClientError returns whether an error is clientError.
IsRPCError returns whether an error is either a serverError or clientError.
IsServerError returns whether an error is serverError.
NewClient returns a new Client which uses the given libp2p host and protocol ID, which must match the one used by the server.
NewClientWithServer takes an additional RPC Server and returns a Client.
NewServer creates a Server object with the given LibP2P host and protocol.
WithAuthorizeFunc adds authorization strategy(A function defining whether the given peer id is allowed to access given method of the given service) to the server using given authorization function.
WithClientStatsHandler provides an implementation of stats.Handler to be used by the Client.
WithMultiStreamBufferSize sets the channel sizes for multiStream calls.
WithServerStatsHandler providers a implementation of stats.Handler to be used by the Server.
WithStreamBufferSize sets the channel buffer size for streaming requests.

# Constants

AuthorizationErr is an error that has arisen because client doesn't have permissions to make the given rpc request.
ClientErr is an error that has arisen on the client side.
ContextKeyRequestSender is default key for RPC service function context to retrieve peer ID of current request sender.
MaxServiceIDLength specifies a maximum length for the "ServiceName.MethodName" so that an attacker cannot send an arbitrarily large ServiceID.
NonRPCErr is an error that hasn't arisen from the gorpc package.
ServerErr is an error that has arisen on the server side.

# Structs

Call represents an active RPC.
Client represents an RPC client which can perform calls to a remote (or local, see below) Server.
Response wraps all elements necessary to reply to a call: Service ID, Error and data.
Server is an LibP2P RPC server.
ServiceID is a header sent when performing an RPC request which identifies the service and method being called.

# Type aliases

ClientOption allows for functional setting of options on a Client.
ContextKey is special type for using as a key with context.Context.
ErrorType is an enum type for providing error type information over the wire between rpc server and client.
ServerOption allows for functional setting of options on a Server.