rpc

package
v0.0.3 Latest Latest
Warning

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

Go to latest
Published: Nov 15, 2018 License: Apache-2.0 Imports: 31 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// MaxBodyBytes controls the maximum number of bytes the
	// server will read parsing the request body.
	MaxBodyBytes = int64(1000000) // 1MB
)

Variables

View Source
var (

	// RegexpInt 整数正则
	RegexpInt = regexp.MustCompile(`^-?[0-9]+$`)
	// RegexpHex 16进制正则
	RegexpHex = regexp.MustCompile(`^(?i)[a-f0-9]+$`)
	// RegexpEmail 正则
	RegexpEmail = regexp.MustCompile(`^(?i)(` + dotAtom + `)@(` + dotAtom + `)$`)
	// RegexpAddress 正则
	RegexpAddress = regexp.MustCompile(`^(?i)[a-z0-9]{25,34}$`)
	// RegexpHost 正则
	RegexpHost = regexp.MustCompile(`^(?i)(` + domain + `)$`)
)

Functions

func EventSubscriber

func EventSubscriber(eventSub types.EventSubscriber) func(*wsConnection)

EventSubscriber sets object that is used to subscribe / unsubscribe from events - not Goroutine-safe. If none given, default node's eventBus will be used.

func GetParam

func GetParam(r *http.Request, param string) string

GetParam 获取指定参数

func GetParamByteSlice

func GetParamByteSlice(r *http.Request, param string) ([]byte, error)

GetParamByteSlice 获取指定字节切片

func GetParamFloat64

func GetParamFloat64(r *http.Request, param string) (float64, error)

GetParamFloat64 获取指定参数

func GetParamInt32

func GetParamInt32(r *http.Request, param string) (int32, error)

GetParamInt32 获取指定参数

func GetParamInt64

func GetParamInt64(r *http.Request, param string) (int64, error)

GetParamInt64 获取指定参数

func GetParamRegexp

func GetParamRegexp(r *http.Request, param string, re *regexp.Regexp) (string, error)

GetParamRegexp 获取指定参数

func GetParamUint

func GetParamUint(r *http.Request, param string) (uint, error)

GetParamUint 获取指定参数

func GetParamUint64

func GetParamUint64(r *http.Request, param string) (uint64, error)

GetParamUint64 获取指定参数

func NewWSConnection

func NewWSConnection(
	baseConn *websocket.Conn,
	funcMap map[string]*RPCFunc,
	cdc *amino.Codec,
	options ...func(*wsConnection),
) *wsConnection

NewWSConnection wraps websocket.Conn.

See the commentary on the func(*wsConnection) functions for a detailed description of how to configure ping period and pong wait time. NOTE: if the write buffer is full, pongs may be dropped, which may cause clients to disconnect. see https://github.com/gorilla/websocket/issues/97

func PingPeriod

func PingPeriod(pingPeriod time.Duration) func(*wsConnection)

PingPeriod sets the duration for sending websocket pings. It should only be used in the constructor - not Goroutine-safe.

func ReadWait

func ReadWait(readWait time.Duration) func(*wsConnection)

ReadWait sets the amount of time to wait before a websocket read times out. It should only be used in the constructor - not Goroutine-safe.

func RecoverAndLogHandler

func RecoverAndLogHandler(handler http.Handler) http.Handler

RecoverAndLogHandler Wraps an HTTP handler, adding error logging. If the inner function panics, the outer function recovers, logs, sends an HTTP 500 error response.

func RegisterRPCFuncs

func RegisterRPCFuncs(mux *http.ServeMux, funcMap map[string]*RPCFunc, cdc *amino.Codec)

RegisterRPCFuncs adds a route for each function in the funcMap, as well as general jsonrpc and websocket handlers for all functions. "result" is the interface on which the result objects are registered, and is popualted with every RPCResponse

func StartHTTPAndTLSServer

func StartHTTPAndTLSServer(
	listenAddr string,
	handler http.Handler,
	certFile, keyFile string,
	config Config,
) (listener net.Listener, err error)

StartHTTPAndTLSServer starts an HTTPS server on listenAddr with the given handler. It wraps handler with RecoverAndLogHandler.

func StartHTTPServer

func StartHTTPServer(
	listenAddr string,
	handler http.Handler,
	config Config,
) (listener net.Listener, err error)

StartHTTPServer starts an HTTP server on listenAddr with the given handler. It wraps handler with RecoverAndLogHandler.

func WriteChanCapacity

func WriteChanCapacity(cap int) func(*wsConnection)

WriteChanCapacity sets the capacity of the websocket write channel. It should only be used in the constructor - not Goroutine-safe.

func WriteRPCResponseHTTP

func WriteRPCResponseHTTP(w http.ResponseWriter, res trtypes.RPCResponse)

WriteRPCResponseHTTP write rpc response

func WriteRPCResponseHTTPError

func WriteRPCResponseHTTPError(
	w http.ResponseWriter,
	httpCode int,
	res trtypes.RPCResponse,
)

WriteRPCResponseHTTPError write rpc response error

func WriteWait

func WriteWait(writeWait time.Duration) func(*wsConnection)

WriteWait sets the amount of time to wait before a websocket write times out. It should only be used in the constructor - not Goroutine-safe.

Types

type Config

type Config struct {
	MaxOpenConnections int
}

Config is an RPC server configuration.

type RPCFunc

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

RPCFunc contains the introspected type information for a function

func NewRPCFunc

func NewRPCFunc(f interface{}, args string) *RPCFunc

NewRPCFunc wraps a function for introspection. f is the function, args are comma separated argument names

func NewWSRPCFunc

func NewWSRPCFunc(f interface{}, args string) *RPCFunc

NewWSRPCFunc wraps a function for introspection and use in the websockets.

type RequestHandler

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

RequestHandler handle rpc request

func NewRequestHandler

func NewRequestHandler(h *tmtypes.EventBus, p *pool.TxPool) *RequestHandler

NewRequestHandler new a rpc request handler

func (RequestHandler) ABCIQuery

func (s RequestHandler) ABCIQuery(path string, data cmn.HexBytes, height int64, trusted bool) (*ctypes.ResultABCIQuery, error)

ABCIQuery 交易、交易序号查询。

func (RequestHandler) BroadcastTxSync

func (s RequestHandler) BroadcastTxSync(tx tmttypes.Tx) (*ctypes.ResultBroadcastTx, error)

BroadcastTxSync 广播交易。

func (RequestHandler) Health

func (s RequestHandler) Health() (*ctypes.ResultHealth, error)

Health health check

func (RequestHandler) Routes

func (s RequestHandler) Routes() map[string]*RPCFunc

Routes rpc request/handler mapper

func (RequestHandler) Subscribe

func (s RequestHandler) Subscribe(wsCtx rpctypes.WSRPCContext, query string) (*ctypes.ResultSubscribe, error)

Subscribe 指定订阅条件,订阅交易事件。

func (RequestHandler) Unsubscribe

func (s RequestHandler) Unsubscribe(wsCtx rpctypes.WSRPCContext, query string) (*ctypes.ResultUnsubscribe, error)

Unsubscribe 根据具体订阅条件,取消交易事件的订阅。

func (RequestHandler) UnsubscribeAll

func (s RequestHandler) UnsubscribeAll(wsCtx rpctypes.WSRPCContext) (*ctypes.ResultUnsubscribe, error)

UnsubscribeAll 取消全部交易事件订阅。

type ResponseWriterWrapper

type ResponseWriterWrapper struct {
	Status int
	http.ResponseWriter
}

ResponseWriterWrapper Remember the status for logging

func (*ResponseWriterWrapper) Hijack

Hijack implements http.Hijacker

func (*ResponseWriterWrapper) WriteHeader

func (w *ResponseWriterWrapper) WriteHeader(status int)

WriteHeader write header

type WebsocketManager

type WebsocketManager struct {
	websocket.Upgrader
	// contains filtered or unexported fields
}

WebsocketManager provides a WS handler for incoming connections and passes a map of functions along with any additional params to new connections. NOTE: The websocket path is defined externally, e.g. in node/node.go

func NewWebsocketManager

func NewWebsocketManager(funcMap map[string]*RPCFunc, cdc *amino.Codec, wsConnOptions ...func(*wsConnection)) *WebsocketManager

NewWebsocketManager returns a new WebsocketManager that passes a map of functions, connection options and logger to new WS connections.

func (*WebsocketManager) WebsocketHandler

func (wm *WebsocketManager) WebsocketHandler(w http.ResponseWriter, r *http.Request)

WebsocketHandler upgrades the request/response (via http.Hijack) and starts the wsConnection.

Jump to

Keyboard shortcuts

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