Expand description
RPC server module (native only). This module encapsulates
server-side types used to create an RPC server: RpcServer
,
RpcHandler
, Messenger
, Interface
and the
protocol handlers: BorshProtocol
and JsonProtocol
.
Re-exports§
pub use crate::encoding::Encoding;
pub use protocol::BorshProtocol;
pub use protocol::JsonProtocol;
pub use protocol::ProtocolHandler;
pub use super::error::*;
Modules§
- error
Error
declarations for theserver
module- handshake
- WebSocket handshake helpers
- prelude
- Convenience module exporting all types required for using the
RpcServer
- protocol
- Protocol module containing protocol handlers in charge of incoming and outgoing message serialization and RPC method and notification dispatch.
- result
Result
enum encapsulating serverError
enum.
Macros§
- method
- method!() macro for declaration of RPC method handlers
- notification
- notification!() macro for declaration of RPC notification handlers
Structs§
- Interface
Interface
struct carries a mapping of RPC methods and notifications, used by protocols to dispatch calls to their respective handlers.- Messenger
- The
Messenger
struct is supplied to theRpcHandler::handshake()
call at the connection negotiation time. This structure comes in asArc<Messenger>
and can be retained for later processing. It provides two methods:Messenger::notify
that can be used asynchronously to dispatch RPC notifications to the client andMessenger::close
that can be used to terminate the RPC connection with the client. - Method
- RPC method wrapper. Contains the method closure function.
- Notification
- RPC notification wrapper. Contains the notification closure function.
- RpcContext
- A basic example RpcContext, can be used to keep track of connected peers.
- RpcServer
RpcServer
- a server-side object that listens for incoming websocket connections and delegates interaction with them to the supplied interfaces:RpcHandler
(for RPC server management) andInterface
(for method and notification dispatch).- TcpListener
- A TCP socket server, listening for connections.
- Tokio
Unbounded Sender - Send values to the associated
UnboundedReceiver
. - WebSocket
Config - The configuration for WebSocket connection.
- WebSocket
Counters - Atomic counters that allow tracking connection counts
and cumulative message sizes in bytes (bandwidth consumption
without accounting for the websocket framing overhead).
These counters can be created and supplied externally or
supplied as
None
. - WebSocket
Server - WebSocketServer that provides the main websocket connection and message processing loop that delivers messages to the installed WebSocketHandler trait.
Enums§
- Message
- An enum representing the various forms of a WebSocket message.
- Socket
Addr - An internet socket address, either IPv4 or IPv6.
- WebSocket
Error - Errors produced by the
WebSocketServer
.
Traits§
- RpcHandler
RpcHandler
- a server-side event handler for RPC connections.- WebSocket
Handler - WebSocketHandler trait that represents the WebSocket processor
functionality. This trait is supplied to the WebSocket
which subsequently invokes it’s functions during websocket
connection and messages. The trait can override
with_handshake()
method to enable invocation of thehandshake()
method upon receipt of the first valid websocket message from the incoming connection. - WebSocket
Server Trait - Base WebSocketServer trait allows the
WebSocketServer<T>
struct to be retained by the trait reference by casting it to the trait as follows:
Functions§
Type Aliases§
- WebSocket
Receiver - WebSocket stream receiver for receiving
tungstenite::Message
. This stream object must have a mutable reference and can not be cloned. - WebSocket
Result Result
encapsulatingError
produced by theWebSocketServer
- WebSocket
Sender - WebSocket stream sender for dispatching
tungstenite::Message
. This stream object must have a mutable reference and can not be cloned. - WebSocket
Sink - WebSocketSink
tokio::sync::mpsc::UnboundedSender
for dispatching messages from within theWebSocketHandler::message
. This is anMPSC
channel that can be cloned and retained externally for the lifetime of the WebSocket connection.