úÎVÅR82      !"#$%&'()*+,-./01portable experimentalpxqr.sta@gmail.com Safe-InferredGeneric KRPC message. ;Response messages are sent upon successful completion of a  query: > KResponse used to signal that callee successufully process a 7 procedure call and to return values from procedure. < KResponse should not be sent if error occurred during RPC,   should be sent instead. 3 KResponse can be only sent from server to client. 2 containing return values; match to the corresponding . @Query used to signal that caller want to make procedure call to E callee and pass arguments in. Therefore query may be only sent from 5 client to server but not in the opposite direction. values to be passed to method; method to call; one-time query token. @Errors are sent when a query cannot be fulfilled. Error message B can be send only from server to client but not in the opposite  direction. the type of error; human-readable text message; match to the corresponding . Types of RPC errors. 2Occur when client trying to call method server don't know. 2Malformed packet, invalid arguments or bad token. 2Occur when server fail to process procedure call. Some error doesn't fit in any other category. =This transaction ID is generated by the querying node and is = echoed in the response, so responses may be correlated with A multiple queries to the same node. The transaction ID should be E encoded as a short string of binary numbers, typically 2 characters 4 are enough as they cover 2^16 outstanding queries. %Happen when some query handler fail.  Received  or   can not be decoded. If remote node send query this node doesn't know about then 0 this error message should be sent in response. A remote node has send some  this node is unable to  decode. !A remote node is not responding to the our request the for  specified period of time. 3/Responses, or KRPC message dictionaries with a "y" value of  "r", contain one additional key "r". The value of "r" is a , dictionary containing named return values. Example Response packet: A { "t" : "aa", "y" : "r", "r" : { "msg" : "you've sent: hi!" } } 4-Queries, or KRPC message dictionaries with a "y" value of  "q", contain two additional keys; "q" and "a". Key "q" has = a string value containing the method name of the query. Key "a" A has a dictionary value containing named arguments to the query. Example Query packet: B { "t" : "aa", "y" : "q", "q" : "ping", "a" : { "msg" : "hi!" } } 5,Errors, or KRPC message dictionaries with a "y" value of "e",  contain one additional key "e". The value of "e" is a @ list. The first element is an integer representing the error = code. The second element is a string containing the error  message. Example Error Packet:  = { "t": "aa", "y":"e", "e":[201, "A Generic Error Ocurred"]}  or bencoded: 5 d1:eli201e23:A Generic Error Ocurrede1:t2:aa1:y1:ee 6According to the table:   /http://bittorrent.org/beps/bep_0005.html#errors & 7 !83495:6  ! !    7 !83495:6portable experimentalpxqr.sta@gmail.comNone"=In order to perform or handle KRPC query you need to provide  corresponding " class.  Example:  * data Ping = Ping Text deriving BEncode * data Pong = Pong Text deriving BEncode   instance " Ping Pong where  method = "ping" #4Method name. Default implementation uses lowercased req  datatype name. $=Method datatype used to describe method name, parameters and 4 return values of procedure. Client use a method to invoke , server   implements% the method to make the actual work. :We use the following fantom types to ensure type-safiety: # param: Type of method parameters. - result: Type of return value of the method. ; Example:  show (Method "concat" :: [Int] Int) == "concat :: [Int] -> Int""#$%<;"#$%$%"#"#$%<;None &-A monad which can perform or handle queries. 'Ask for manager. ()Can be used to add logging for instance. )#Keep track pending queries made by this node and handle queries  made by remote nodes. = in seconds *6Handler is a function which will be invoked then some remote  node querying this node. +?Bind socket to the specified address. To enable query handling  run 1. ,,Unblock all pending calls and close socket. ->Normally you should use Control.Monad.Trans.Resource.allocate  function. .!Enqueue query to the given node. ?This function will throw exception if quered node respond with  error message or timeout expires. /AMake handler from handler function. Any thrown exception will be = supressed and send over the wire back to the querying node. 1Should be run before any ., otherwise they will never  succeed. (&'()>?=@ABC*DEFGHIJKL+address to listen on; %handlers to run on incoming queries.  new manager. ,-MNOPQ./RSTUVW01X &'()*+,-./01 &'()+,-.*/01&'()>?=@ABC*DEFGHIJKL+,-MNOPQ./RSTUVW01Xportable experimentalpxqr.sta@gmail.comNone"#$&'()*+,-./1$"#*/.&'()+,-1Y      !"#$%&'(()*+,-./0123456789:;<=>?@AB,CDEFGHIJKLMNOPQRSTUVWXYZ[\] krpc-0.5.0.0 Network.KRPCNetwork.KRPC.MessageNetwork.KRPC.MethodNetwork.KRPC.Managernetwork-2.4.1.2Network.Socket.Types SockAddrInet SockAddrInet6 SockAddrUnixSockAddrKMessageERQ KResponserespValsrespIdKQuery queryArgs queryMethodqueryId MethodNameKError errorCode errorMessageerrorId ErrorCode MethodUnknown ProtocolError ServerError GenericError TransactionId serverError decodeError unknownMethodunknownMessagetimeoutExpiredKRPCmethodMethod MonadKRPC getManager liftHandlerManagerHandler newManager closeManager withManagerqueryhandlerlistenerlistenbencoding-0.4.3.0Data.BEncode.TypesBDict$fBEncodeKResponse$fBEncodeKQuery$fBEncodeKError$fEnumErrorCodeunknownTransaction$fBEncodeKMessage$fExceptionKError$fBEncodeErrorCode $fShowMethod showsMethod queryTimeoutsocklistenerThreadtransactionCounter pendingCallshandlers HandlerBody PendingCallsCallResCallIdTransactionCounterKResultsockAddrFamilyseedTransactiondefaultQueryTimeout sendMessagegenTransactionId registerQueryunregisterQuery queryResponse runHandlerdispatchHandler handleQueryhandleResponse handleMessage maxMsgSize$fMonadKRPChReaderT