Documentation ¶
Index ¶
- Constants
- Variables
- type API
- type CodecOption
- type Config
- type Error
- type ID
- type Notifier
- type RpcServer
- func (s *RpcServer) HandleFunc(w http.ResponseWriter, r *http.Request)
- func (s *RpcServer) RegisterService(namespace string, regSvc interface{}) error
- func (s *RpcServer) ServeSingleRequest(ctx context.Context, codec ServerCodec, options CodecOption)
- func (s *RpcServer) Start() error
- func (s *RpcServer) Stop()
- type ServerCodec
- type Subscription
Constants ¶
const (
DefaultServiceNameSpace = "|nox|"
)
Variables ¶
var ( // ErrNotificationsUnsupported is returned when the connection doesn't support notifications ErrNotificationsUnsupported = errors.New("notifications not supported") // ErrNotificationNotFound is returned when the notification for the given id is not found ErrSubscriptionNotFound = errors.New("subscription not found") )
Functions ¶
This section is empty.
Types ¶
type API ¶
type API struct { NameSpace string // namespace under which the rpc methods of Service are exposed Service interface{} // receiver instance which holds the methods }
API describes the set of methods offered over the RPC interface
type CodecOption ¶
type CodecOption int
CodecOption specifies which type of messages this codec supports
const ( // OptionMethodInvocation is an indication that the codec supports RPC method calls OptionMethodInvocation CodecOption = 1 << iota // OptionSubscriptions is an indication that the codec suports RPC notifications OptionSubscriptions = 1 << iota // support pub sub )
type Config ¶
type Config struct { RPCUser string `short:"u" long:"rpcuser" description:"Username for RPC connections"` RPCPass string `short:"P" long:"rpcpass" default-mask:"-" description:"Password for RPC connections"` RPCCert string `long:"rpccert" description:"File containing the certificate file"` RPCKey string `long:"rpckey" description:"File containing the certificate key"` RPCMaxClients int `long:"rpcmaxclients" description:"Max number of RPC clients for standard connections"` DisableRPC bool `` /* 165-byte string literal not displayed */ DisableTLS bool `` /* 127-byte string literal not displayed */ }
Config Server config
type ID ¶
type ID string
ID defines a pseudo random number that is used to identify RPC subscriptions.
type Notifier ¶
type Notifier struct {
// contains filtered or unexported fields
}
Notifier is tight to a RPC connection that supports subscriptions. Server callbacks use the notifier to send notifications.
func NotifierFromContext ¶
NotifierFromContext returns the Notifier value stored in ctx, if any.
func (*Notifier) Closed ¶
func (n *Notifier) Closed() <-chan interface{}
Closed returns a channel that is closed when the RPC connection is closed.
func (*Notifier) CreateSubscription ¶
func (n *Notifier) CreateSubscription() *Subscription
CreateSubscription returns a new subscription that is coupled to the RPC connection. By default subscriptions are inactive and notifications are dropped until the subscription is marked as active. This is done by the RPC server after the subscription ID is send to the client.
type RpcServer ¶
type RpcServer struct {
// contains filtered or unexported fields
}
RpcServer provides a concurrent safe RPC server to a chain server.
func NewRPCServer ¶
newRPCServer returns a new instance of the rpcServer struct.
func (*RpcServer) HandleFunc ¶
func (s *RpcServer) HandleFunc(w http.ResponseWriter, r *http.Request)
func (*RpcServer) RegisterService ¶
RegisterService will create a service for the given type under the given namespace. When no methods on the given type match the criteria to be either a RPC method or a subscription an error is returned. Otherwise a new service is created and added to the service registry.
func (*RpcServer) ServeSingleRequest ¶
func (s *RpcServer) ServeSingleRequest(ctx context.Context, codec ServerCodec, options CodecOption)
ServeSingleRequest reads and processes a single RPC request from the given codec. It will not close the codec unless a non-recoverable error has occurred. Note, this method will return after a single request has been processed!
type ServerCodec ¶
type ServerCodec interface { // Read next request ReadRequestHeaders() ([]rpcRequest, bool, Error) // Parse request argument to the given types ParseRequestArguments(argTypes []reflect.Type, params interface{}) ([]reflect.Value, Error) // Assemble success response, expects response id and payload CreateResponse(id interface{}, reply interface{}) interface{} // Assemble error response, expects response id and error CreateErrorResponse(id interface{}, err Error) interface{} // Assemble error response with extra information about the error through info CreateErrorResponseWithInfo(id interface{}, err Error, info interface{}) interface{} // Create notification response CreateNotification(id, namespace string, event interface{}) interface{} // Write msg to client. Write(msg interface{}) error // Close underlying data stream Close() // Closed when underlying connection is closed Closed() <-chan interface{} }
ServerCodec implements reading, parsing and writing RPC messages for the server side of a RPC session. Implementations must be go-routine safe since the codec can be called in multiple go-routines concurrently.
func NewJSONCodec ¶
func NewJSONCodec(rwc io.ReadWriteCloser) ServerCodec
NewJSONCodec creates a new RPC server codec with support for JSON-RPC 2.0.
type Subscription ¶
type Subscription struct { ID ID // contains filtered or unexported fields }
a Subscription is created by a notifier and tight to that notifier. The client can use this subscription to wait for an unsubscribe request for the client, see Err().
func (*Subscription) Err ¶
func (s *Subscription) Err() <-chan error
Err returns a channel that is closed when the client send an unsubscribe request.