Portability | portable |
---|---|
Stability | experimental |
Maintainer | pxqr.sta@gmail.com |
Safe Haskell | None |
Normally, you don't need to import this module.
- class (MonadBaseControl IO m, MonadLogger m, MonadIO m) => MonadKRPC h m | m -> h where
- getManager :: m (Manager h)
- liftHandler :: h a -> m a
- data Options = Options {
- optSeedTransaction :: !Int
- optQueryTimeout :: !Int
- optMaxMsgSize :: !Int
- data Manager h
- newManager :: Options -> SockAddr -> [Handler h] -> IO (Manager h)
- closeManager :: Manager m -> IO ()
- withManager :: Options -> SockAddr -> [Handler h] -> (Manager h -> IO a) -> IO a
- isActive :: Manager m -> IO Bool
- listen :: MonadKRPC h m => m ()
- data QueryFailure
- query :: forall h m a b. (MonadKRPC h m, KRPC a b) => SockAddr -> a -> m b
- getQueryCount :: MonadKRPC h m => m Int
- data HandlerFailure
- type Handler h = (MethodName, HandlerBody h)
- handler :: forall h a b. (KRPC a b, Monad h) => (SockAddr -> a -> h b) -> Handler h
Manager
class (MonadBaseControl IO m, MonadLogger m, MonadIO m) => MonadKRPC h m | m -> h whereSource
A monad which can perform or handle queries.
getManager :: m (Manager h)Source
Ask for manager.
liftHandler :: h a -> m aSource
Can be used to add logging for instance.
(MonadBaseControl IO h, MonadLogger h, MonadIO h) => MonadKRPC h (ReaderT (Manager h) h) |
RPC manager options.
Options | |
|
Keep track pending queries made by this node and handle queries made by remote nodes.
(MonadBaseControl IO h, MonadLogger h, MonadIO h) => MonadKRPC h (ReaderT (Manager h) h) |
:: Options | various protocol options; |
-> SockAddr | address to listen on; |
-> [Handler h] | handlers to run on incoming queries. |
-> IO (Manager h) | new rpc manager. |
Bind socket to the specified address. To enable query handling
run listen
.
closeManager :: Manager m -> IO ()Source
Unblock all pending calls and close socket.
withManager :: Options -> SockAddr -> [Handler h] -> (Manager h -> IO a) -> IO aSource
Normally you should use Control.Monad.Trans.Resource.allocate function.
isActive :: Manager m -> IO BoolSource
Check if the manager is still active. Manager becomes active
until closeManager
called.
listen :: MonadKRPC h m => m ()Source
Should be run before any query
, otherwise they will never
succeed.
Queries
data QueryFailure Source
Used to signal query
errors.
SendFailed | unable to send query; |
QueryFailed ErrorCode Text | remote node return error; |
TimeoutExpired | remote node not responding. |
query :: forall h m a b. (MonadKRPC h m, KRPC a b) => SockAddr -> a -> m bSource
Enqueue query to the given node.
This function should throw QueryFailure
exception if quered node
respond with error
message or the query timeout expires.
getQueryCount :: MonadKRPC h m => m IntSource
How many times query
call have been performed.
Handlers
data HandlerFailure Source
Used to signal protocol errors.
BadAddress | for e.g.: node calls herself; |
InvalidParameter Text | for e.g.: bad session token. |
type Handler h = (MethodName, HandlerBody h)Source
Handler is a function which will be invoked then some remote node querying this node.