krpc-0.2.2.0: KRPC remote procedure call protocol implementation.

Portabilityportable
Stabilityexperimental
Maintainerpxqr.sta@gmail.com
Safe HaskellNone

Remote.KRPC.Protocol

Contents

Description

This module provides straightforward implementation of KRPC protocol. In many situations KRPC should be prefered since it gives more safe, convenient and high level api.

 See http://www.bittorrent.org/beps/bep_0005.html#krpc-protocol

Synopsis

Error

data KError Source

Errors used to signal that some error occurred while processing a procedure call. Error may be send only from server to client but not in the opposite direction.

Errors are encoded as bencoded dictionary:

 { "y" : "e", "e" : [<error_code>, <human_readable_error_reason>] }

Constructors

GenericError

Some error doesn't fit in any other category.

ServerError

Occur when server fail to process procedure call.

ProtocolError

Malformed packet, invalid arguments or bad token.

MethodUnknown

Occur when client trying to call method server don't know.

Query

data KQuery Source

Query used to signal that caller want to make procedure call to callee and pass arguments in. Therefore query may be only sent from client to server but not in the opposite direction.

Queries are encoded as bencoded dictionary:

 { "y" : "q", "q" : "<method_name>", "a" : [<arg1>, <arg2>, ...] }

Response

data KResponse Source

KResponse used to signal that callee successufully process a procedure call and to return values from procedure. KResponse should not be sent if error occurred during RPC. Thus KResponse may be only sent from server to client.

Responses are encoded as bencoded dictionary:

 { "y" : "r", "r" : [<val1>, <val2>, ...] }

Remote

type KRemote = SocketSource

type KRemoteAddr = (HostAddress, PortNumber)Source

withRemote :: (MonadBaseControl IO m, MonadIO m) => (KRemote -> m a) -> m aSource

remoteServerSource

Arguments

:: (MonadBaseControl IO remote, MonadIO remote) 
=> PortNumber

Port number to listen.

-> (KRemoteAddr -> KQuery -> remote (Either KError KResponse))

Handler.

-> remote () 

Run server using a given port. Method invocation should be done manually.

Re-exports

encode :: BEncode -> ByteString

Convert bencoded value to raw bytestring according to the specification.

encoded :: BEncodable a => a -> ByteString

The same as encode but takes any bencodable value.

decode :: ByteString -> Result BEncode

Try to convert raw bytestring to bencoded value according to specification.

decoded :: BEncodable a => ByteString -> Result a

The same as decode but returns any bencodable value.

toBEncode :: BEncodable a => a -> BEncode

See an example of implementation here Assoc

fromBEncode :: BEncodable a => BEncode -> Result a

See an example of implementation here reqKey.