krpc-0.6.1.0: KRPC protocol implementation

Portabilityportable
Stabilityexperimental
Maintainerpxqr.sta@gmail.com
Safe HaskellNone

Network.KRPC.Manager

Contents

Description

Normally, you don't need to import this module.

Synopsis

Manager

class (MonadBaseControl IO m, MonadLogger m, MonadIO m) => MonadKRPC h m | m -> h whereSource

A monad which can perform or handle queries.

Methods

getManager :: m (Manager h)Source

Ask for manager.

liftHandler :: h a -> m aSource

Can be used to add logging for instance.

Instances

data Options Source

RPC manager options.

Constructors

Options 

Fields

optSeedTransaction :: !Int

Initial TransactionId incremented with each query;

optQueryTimeout :: !Int

Time to wait for response from remote node, in seconds.

optMaxMsgSize :: !Int

Maximum number of bytes to receive.

Instances

Eq Options 
Show Options 
Default Options

Permissive defaults.

data Manager h Source

Keep track pending queries made by this node and handle queries made by remote nodes.

Instances

newManagerSource

Arguments

:: 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.

Constructors

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.

Constructors

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.

handler :: forall h a b. (KRPC a b, Monad h) => (SockAddr -> a -> h b) -> Handler hSource

Make handler from handler function. Any thrown exception will be supressed and send over the wire back to the querying node.

If the handler make some query normally it should handle corresponding QueryFailures.