proxy

package
v0.10.4 Latest Latest
Warning

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

Go to latest
Published: Nov 15, 2019 License: MIT Imports: 18 Imported by: 0

Documentation

Index

Constants

View Source
const ErrAuthFailed int = -32085

ErrAuthFailed is when supplied auth_token / account_id is not present in the database.

View Source
const ErrInternal int = -32603

ErrInternal is a general server error code

View Source
const ErrInvalidParams int = -32602

ErrInvalidParams signifies a client-supplied params error

View Source
const ErrInvalidRequest int = -32600

ErrInvalidRequest signifies a general client error

View Source
const ErrJSONParse int = -32700

ErrJSONParse means invalid JSON was received by the server.

View Source
const ErrMethodUnavailable int = -32601

ErrMethodUnavailable means the client-requested method cannot be found

View Source
const ErrProxy int = -32080

ErrProxy is for general errors that originate inside the proxy module

View Source
const MethodAccountBalance = "account_balance"
View Source
const MethodAccountList = "account_list"
View Source
const MethodClaimSearch = "claim_search"
View Source
const MethodCommentList = "comment_list"
View Source
const MethodFileList = "file_list"
View Source
const MethodGet = "get"
View Source
const MethodResolve = "resolve"
View Source
const MethodStatus = "status"

Variables

View Source
var ResolveTime float64

Functions

func ForwardCall

func ForwardCall(request jsonrpc.RPCRequest) ([]byte, error)

ForwardCall passes a prepared jsonrpc request to the SDK and calls post-processors on the response.

func InitResponseCache

func InitResponseCache(c ResponseCache)

InitResponseCache initializes module-level responseCache variable

func MarshalResponse

func MarshalResponse(r *jsonrpc.RPCResponse) ([]byte, error)

MarshalResponse takes a raw json request body and serializes it into RPCRequest struct for further processing.

func NewErrorResponse

func NewErrorResponse(message string, code int) *jsonrpc.RPCResponse

NewErrorResponse is a shorthand for creating an RPCResponse instance with specified error message and code

func NewRequest

func NewRequest(method string, params ...interface{}) jsonrpc.RPCRequest

func Proxy

func Proxy(r *jsonrpc.RPCRequest, accountID string) ([]byte, error)

Proxy takes a parsed jsonrpc request, calls processors on it and passes it over to the daemon. If accountID is supplied, it's injected as a request param.

func RawCall

func RawCall(request jsonrpc.RPCRequest) (*jsonrpc.RPCResponse, error)

RawCall makes an arbitrary jsonrpc request to the SDK

func UnmarshalRequest

func UnmarshalRequest(r []byte) (*jsonrpc.RPCRequest, error)

UnmarshalRequest takes a raw json request body and serializes it into RPCRequest struct for further processing.

Types

type AuthFailed added in v0.7.0

type AuthFailed struct {
	CallError
}

AuthFailed is for authentication failures when jsonrpc client has provided a token

func (AuthFailed) Code added in v0.7.0

func (e AuthFailed) Code() int

Code returns JSRON-RPC error code

func (AuthFailed) Error added in v0.7.0

func (e AuthFailed) Error() string

type CallError added in v0.7.0

type CallError interface {
	AsRPCResponse() *jsonrpc.RPCResponse
	Code() int
	Error() string
}

CallError is for whatever errors might occur when processing or forwarding client JSON-RPC request

type Caller added in v0.7.0

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

Caller patches through JSON-RPC requests from clients, doing pre/post-processing, account processing and validation.

func (*Caller) Call added in v0.7.0

func (c *Caller) Call(rawQuery []byte) []byte

Call method processes a raw query received from JSON-RPC client and forwards it to LbrynetServer. It returns a response that is ready to be sent back to the JSON-RPC client as is.

func (*Caller) SetPreprocessor added in v0.8.0

func (c *Caller) SetPreprocessor(p Preprocessor)

SetPreprocessor applies provided function to query before it's sent to the LbrynetServer.

func (*Caller) WalletID added in v0.9.0

func (c *Caller) WalletID() string

WalletID is an LbrynetServer wallet ID for the client this caller instance is serving.

type GenericError added in v0.7.0

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

func NewError added in v0.7.0

func NewError(e error) GenericError

NewError is for general internal errors

func NewInternalError added in v0.7.0

func NewInternalError(e error) GenericError

NewInternalError is for SDK-related errors (connection problems etc)

func NewMethodError added in v0.7.0

func NewMethodError(e error) GenericError

NewMethodError creates a call method error

func NewParamsError added in v0.7.0

func NewParamsError(e error) GenericError

NewParamsError signifies an error in method parameters

func NewParseError added in v0.7.0

func NewParseError(e error) GenericError

NewParseError is for json parsing errors

func (GenericError) AsRPCResponse added in v0.7.0

func (e GenericError) AsRPCResponse() *jsonrpc.RPCResponse

AsRPCResponse returns error as jsonrpc.RPCResponse

func (GenericError) Code added in v0.7.0

func (e GenericError) Code() int

Code returns JSRON-RPC error code

func (GenericError) Error added in v0.7.0

func (e GenericError) Error() string

func (GenericError) Unwrap added in v0.9.0

func (e GenericError) Unwrap() error

type Preprocessor added in v0.8.0

type Preprocessor func(q *Query)

type ProxyService added in v0.10.4

type ProxyService struct {
	Router router.SDKRouter
	// contains filtered or unexported fields
}

ProxyService generates Caller objects and keeps execution time metrics for all calls proxied through those objects.

func NewService added in v0.7.0

func NewService(sdkRouter router.SDKRouter) *ProxyService

NewService is the entry point to proxy module. Normally only one instance of ProxyService should be created per running server.

func (*ProxyService) NewCaller added in v0.10.4

func (ps *ProxyService) NewCaller(walletID string) *Caller

NewCaller returns an instance of Caller ready to proxy requests. Note that `SetWalletID` needs to be called if an authenticated user is making this call.

type Query added in v0.7.0

type Query struct {
	Request *jsonrpc.RPCRequest
	// contains filtered or unexported fields
}

Query is a wrapper around client JSON-RPC query for easier (un)marshaling and processing.

func NewQuery added in v0.7.0

func NewQuery(r []byte) (*Query, error)

NewQuery initializes Query object with JSON-RPC request supplied as bytes. The object is immediately usable and returns an error in case request parsing fails.

func (*Query) Method added in v0.7.0

func (q *Query) Method() string

Method is a shortcut for query method.

func (*Query) Params added in v0.7.0

func (q *Query) Params() interface{}

Params is a shortcut for query params.

func (*Query) ParamsAsMap added in v0.7.0

func (q *Query) ParamsAsMap() map[string]interface{}

ParamsAsMap returns query params converted to plain map.

func (*Query) ParamsToStruct added in v0.8.0

func (q *Query) ParamsToStruct(targetStruct interface{}) error

ParamsToStruct returns query params parsed into a supplied structure.

func (*Query) SetWalletID added in v0.9.0

func (q *Query) SetWalletID(id string)

type RequestHandler added in v0.7.0

type RequestHandler struct {
	*ProxyService
}

RequestHandler is a wrapper for passing proxy.ProxyService instance to proxy HTTP handler.

func NewRequestHandler added in v0.8.2

func NewRequestHandler(svc *ProxyService) *RequestHandler

NewRequestHandler initializes request handler with a provided Proxy ProxyService instance

func (*RequestHandler) Handle added in v0.7.0

func (rh *RequestHandler) Handle(w http.ResponseWriter, r *http.Request)

Handle forwards client JSON-RPC request to proxy.

func (*RequestHandler) HandleOptions added in v0.8.2

func (rh *RequestHandler) HandleOptions(w http.ResponseWriter, r *http.Request)

HandleOptions returns necessary CORS headers for pre-flight requests to proxy API

type ResponseCache

type ResponseCache interface {
	Save(method string, params interface{}, r interface{})
	Retrieve(method string, params interface{}) interface{}
	Count() int
	// contains filtered or unexported methods
}

ResponseCache interface describes methods for SDK response cache saving and retrieval

Jump to

Keyboard shortcuts

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