service

package
v1.0.0-rc18 Latest Latest
Warning

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

Go to latest
Published: Dec 29, 2018 License: MIT Imports: 25 Imported by: 0

Documentation

Index

Constants

View Source
const DirectTimeout = time.Second * 1

DirectTimeout is the context timeout used when we want to first try a direct p2p send but fail fast

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
	Ping(pid peer.ID) (PeerStatus, error)
	Handle(pid peer.ID, env *pb.Envelope) (*pb.Envelope, error)
}

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    *core.IpfsNode
	// contains filtered or unexported fields
}

service represents a libp2p service

func NewService

func NewService(account *keypair.Full, handler Handler, node *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 peer.ID) (PeerStatus, error)

Ping pings another peer and returns status

func (*Service) SendHTTPMessage

func (srv *Service) SendHTTPMessage(addr string, pmes *pb.Envelope) error

SendHTTPMessage sends a message over HTTP

func (*Service) SendHTTPRequest

func (srv *Service) SendHTTPRequest(addr string, pmes *pb.Envelope) (*pb.Envelope, error)

SendHTTPRequest sends a request over HTTP

func (*Service) SendMessage

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

SendMessage sends out a message

func (*Service) SendRequest

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

SendRequest sends out a request

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