service

package
v0.7.8 Latest Latest
Warning

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

Go to latest
Published: Mar 4, 2020 License: MIT Imports: 27 Imported by: 1

Documentation

Index

Constants

View Source
const DefaultTimeout = time.Second * 30

DefaultTimeout is the context timeout for sending / requesting messages

Variables

View Source
var ErrReadTimeout = fmt.Errorf("timed out reading response")

Functions

This section is empty.

Types

type Handler

type Handler interface {
	Protocol() protocol.ID
	Start()
	Ping(pid peer.ID) (PeerStatus, error)
	Handle(env *pb.Envelope, pid peer.ID) (*pb.Envelope, error)
	HandleStream(env *pb.Envelope, pid peer.ID) (chan *pb.Envelope, chan error, chan interface{})
}

Handler is used to handle messages for a specific protocol

type PeerStatus

type PeerStatus string

PeerStatus is the possible results from pinging another peer

const (
	PeerOnline  PeerStatus = "online"
	PeerOffline PeerStatus = "offline"
)

type Service

type Service struct {
	Account *keypair.Full
	Node    func() *core.IpfsNode
	// contains filtered or unexported fields
}

service represents a libp2p service

func NewService

func NewService(account *keypair.Full, handler Handler, node func() *core.IpfsNode) *Service

NewService returns a service for the given config

func (*Service) NewEnvelope

func (srv *Service) NewEnvelope(mtype pb.Message_Type, msg proto.Message, id *int32, response bool) (*pb.Envelope, error)

NewEnvelope returns a signed pb message for transport

func (*Service) NewError

func (srv *Service) NewError(code int, msg string, id int32) (*pb.Envelope, error)

NewError returns a signed pb error message

func (*Service) Ping

func (srv *Service) Ping(p string) (PeerStatus, error)

Ping pings another peer and returns status

func (*Service) SendHTTPStreamRequest

func (srv *Service) SendHTTPStreamRequest(addr string, pmes *pb.Envelope, access string) (chan *pb.Envelope, chan error, *func())

SendHTTPStreamRequest sends a request over HTTP

func (*Service) SendMessage

func (srv *Service) SendMessage(ctx context.Context, p string, pmes *pb.Envelope) error

SendMessage sends out a message

func (*Service) SendRequest

func (srv *Service) SendRequest(p string, pmes *pb.Envelope) (*pb.Envelope, error)

SendRequest sends out a request

func (*Service) Start

func (srv *Service) Start()

Start sets the peer host stream handler

func (*Service) VerifyEnvelope

func (srv *Service) VerifyEnvelope(env *pb.Envelope, pid peer.ID) error

VerifyEnvelope verifies the authenticity of an envelope

Jump to

Keyboard shortcuts

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