fcrserver

package
v0.0.0-...-7a4b066 Latest Latest
Warning

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

Go to latest
Published: Aug 3, 2021 License: Apache-2.0 Imports: 19 Imported by: 3

Documentation

Overview

Package fcrserver - provides an interface to do networking.

Package fcrserver - provides an interface to do networking.

Index

Constants

View Source
const (
	Lowwater    = 100
	Highwater   = 400
	GracePeriod = time.Hour
)

Variables

This section is empty.

Functions

func GetMultiAddr

func GetMultiAddr(privKeyStr string, ip string, port uint) (string, error)

GetMultiAddr returns the supposed multiaddr string from given private key, ip address and port.

func IsTimeoutError

func IsTimeoutError(err error) bool

IsTimeoutError checks if the given error is a timeout error

Types

type FCRServer

type FCRServer interface {
	// Start starts the server.
	Start() error

	// Shutdown stops the server.
	Shutdown()

	// AddHandler adds a handler to the server, which handles a given message type.
	AddHandler(msgType byte, handler func(reader FCRServerRequestReader, writer FCRServerResponseWriter, request *fcrmessages.FCRReqMsg) error) FCRServer

	// AddRequester adds a requester to the server, which is used to send a request for a given message type.
	AddRequester(msgType byte, requester func(reader FCRServerResponseReader, writer FCRServerRequestWriter, args ...interface{}) (*fcrmessages.FCRACKMsg, error)) FCRServer

	// Request uses a requester corresponding to the given message type to send a request to given multiaddr.
	Request(multiaddrStr string, msgType byte, args ...interface{}) (*fcrmessages.FCRACKMsg, error)
}

FCRServer represents a server handling p2p connection.

func NewFCRServerImplV1

func NewFCRServerImplV1(privKeyStr string, port uint, timeout time.Duration) FCRServer

type FCRServerImplV1

type FCRServerImplV1 struct {
	// contains filtered or unexported fields
}

FCRServerImplV1 implements FCRServer, it is built on top of libp2p.

func (*FCRServerImplV1) AddHandler

func (s *FCRServerImplV1) AddHandler(msgType byte, handler func(reader FCRServerRequestReader, writer FCRServerResponseWriter, request *fcrmessages.FCRReqMsg) error) FCRServer

func (*FCRServerImplV1) AddRequester

func (s *FCRServerImplV1) AddRequester(msgType byte, requester func(reader FCRServerResponseReader, writer FCRServerRequestWriter, args ...interface{}) (*fcrmessages.FCRACKMsg, error)) FCRServer

func (*FCRServerImplV1) Request

func (s *FCRServerImplV1) Request(multiaddrStr string, msgType byte, args ...interface{}) (*fcrmessages.FCRACKMsg, error)

func (*FCRServerImplV1) Shutdown

func (s *FCRServerImplV1) Shutdown()

func (*FCRServerImplV1) Start

func (s *FCRServerImplV1) Start() error

type FCRServerRequestReader

type FCRServerRequestReader interface {
	// Read reads a message for a given timeout.
	// It returns the message, and error.
	Read(timeout time.Duration) (*fcrmessages.FCRReqMsg, error)
}

FCRServerRequestReader is a reader for reading message.

type FCRServerRequestReaderImplV1

type FCRServerRequestReaderImplV1 struct {
	// contains filtered or unexported fields
}

FCRServerRequestReaderImplV1 implements FCRServerRequestReader.

func (*FCRServerRequestReaderImplV1) Read

type FCRServerRequestWriter

type FCRServerRequestWriter interface {
	// Write writes a message for a given timeout.
	// It returns error.
	Write(msg *fcrmessages.FCRReqMsg, privKey string, keyVer byte, timeout time.Duration) error
}

FCRServerRequesterWriter is a writer for writer request.

type FCRServerRequestWriterImplV1

type FCRServerRequestWriterImplV1 struct {
	// contains filtered or unexported fields
}

FCRServerRequestWriterImplV1 implements FCRServerRequestWriter.

func (*FCRServerRequestWriterImplV1) Write

func (w *FCRServerRequestWriterImplV1) Write(msg *fcrmessages.FCRReqMsg, privKey string, keyVer byte, timeout time.Duration) error

type FCRServerResponseReader

type FCRServerResponseReader interface {
	// Read reads a message for a given timeout.
	// It returns the message, and error.
	Read(timeout time.Duration) (*fcrmessages.FCRACKMsg, error)
}

FCRServerResponseReader is a reader for reading message.

type FCRServerResponseReaderImplV1

type FCRServerResponseReaderImplV1 struct {
	// contains filtered or unexported fields
}

FCRServerResponseReaderImplV1 implements FCRServerResponseReader.

func (*FCRServerResponseReaderImplV1) Read

type FCRServerResponseWriter

type FCRServerResponseWriter interface {
	// Write writes a message for a given timeout.
	// It returns error.
	Write(msg *fcrmessages.FCRACKMsg, privKey string, keyVer byte, timeout time.Duration) error
}

FCRServerResponseWriter is a writer for writer response.

type FCRServerResponseWriterImplV1

type FCRServerResponseWriterImplV1 struct {
	// contains filtered or unexported fields
}

FCRServerResponseWriterImplV1 implements FCRServerResponseWriter.

func (*FCRServerResponseWriterImplV1) Write

func (w *FCRServerResponseWriterImplV1) Write(msg *fcrmessages.FCRACKMsg, privKey string, keyVer byte, timeout time.Duration) error

Jump to

Keyboard shortcuts

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