From b525f62e07f3372b00673c01a618a1f64037590b Mon Sep 17 00:00:00 2001 From: joe Date: Sun, 18 Jun 2017 04:21:08 -0400 Subject: Removed tox-only customizatino from Network.DatagramServer(.Error). --- src/Network/DatagramServer.hs | 12 ---------- src/Network/DatagramServer/Error.hs | 42 ---------------------------------- src/Network/DatagramServer/Mainline.hs | 38 ++++++++++++++++++++++++++++++ 3 files changed, 38 insertions(+), 54 deletions(-) diff --git a/src/Network/DatagramServer.hs b/src/Network/DatagramServer.hs index cd74f589..eed2ced1 100644 --- a/src/Network/DatagramServer.hs +++ b/src/Network/DatagramServer.hs @@ -109,10 +109,6 @@ import Control.Monad import Control.Monad.Logger import Control.Monad.Reader import Control.Monad.Trans.Control -#ifdef VERSION_bencoding -#else --- import qualified Network.DatagramServer.Tox as Tox -#endif import qualified Data.ByteString.Base16 as Base16 import Data.ByteString as BS import Data.ByteString.Char8 as BC @@ -372,14 +368,6 @@ queryK meth addr params kont = do q <- buildQuery cli addr meth tid params let qb = encodePayload (q :: msg a) :: msg raw qbs = encodeHeaders ctx qb -#ifdef VERSION_bencoding -#else - let q = Tox.Message (methodName queryMethod) cli tid params - cli = error "TODO TOX client node id" - ctx = error "TODO TOX ToxCipherContext" - qb = encodePayload q :: Tox.Message BC.ByteString - qbs = encodeHeaders ctx qb :: BC.ByteString -#endif sendQuery sock addr qbs `onException` unregisterQuery (tid, addr) pendingCalls diff --git a/src/Network/DatagramServer/Error.hs b/src/Network/DatagramServer/Error.hs index 2cbb76c3..77b132a7 100644 --- a/src/Network/DatagramServer/Error.hs +++ b/src/Network/DatagramServer/Error.hs @@ -3,9 +3,6 @@ module Network.DatagramServer.Error where import Control.Exception.Lifted as Lifted -#ifdef VERSION_bencoding -import Data.BEncode as BE -#endif import Data.ByteString (ByteString) import Data.ByteString.Char8 as Char8 import Data.Data @@ -47,15 +44,6 @@ instance Enum ErrorCode where toEnum _ = GenericError {-# INLINE toEnum #-} -#ifdef VERSION_bencoding -instance BEncode ErrorCode where - toBEncode = toBEncode . fromEnum - {-# INLINE toBEncode #-} - - fromBEncode b = toEnum <$> fromBEncode b - {-# INLINE fromBEncode #-} -#endif - -- | Errors are sent when a query cannot be fulfilled. Error message -- can be send only from server to client but not in the opposite -- direction. @@ -66,36 +54,6 @@ data KError tid = KError , errorId :: !tid -- ^ match to the corresponding 'queryId'. } deriving ( Show, Eq, Ord, Typeable, Data, Read ) --- | 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: --- --- > d1:eli201e23:A Generic Error Ocurrede1:t2:aa1:y1:ee --- -#ifdef VERSION_bencoding -instance (Typeable tid, BEncode tid) => BEncode (KError tid) where - toBEncode KError {..} = toDict $ - "e" .=! (errorCode, errorMessage) - .: "t" .=! errorId - .: "y" .=! ("e" :: ByteString) - .: endDict - {-# INLINE toBEncode #-} - - fromBEncode = fromDict $ do - lookAhead $ match "y" (BString "e") - (code, msg) <- field (req "e") - KError code msg <$>! "t" - {-# INLINE fromBEncode #-} -#endif - instance (Typeable tid, Show tid) => Exception (KError tid) -- | Received 'queryArgs' or 'respVals' can not be decoded. diff --git a/src/Network/DatagramServer/Mainline.hs b/src/Network/DatagramServer/Mainline.hs index dd3c8bcd..e9e2798c 100644 --- a/src/Network/DatagramServer/Mainline.hs +++ b/src/Network/DatagramServer/Mainline.hs @@ -331,4 +331,42 @@ instance Pretty ip => Pretty [NodeInfo KMessageOf ip ()] where pPrint = PP.vcat . PP.punctuate "," . map pPrint +#ifdef VERSION_bencoding +instance BEncode ErrorCode where + toBEncode = toBEncode . fromEnum + {-# INLINE toBEncode #-} + + fromBEncode b = toEnum <$> fromBEncode b + {-# INLINE fromBEncode #-} +#endif + +-- | 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: +-- +-- > d1:eli201e23:A Generic Error Ocurrede1:t2:aa1:y1:ee +-- +#ifdef VERSION_bencoding +instance (Typeable tid, BEncode tid) => BEncode (KError tid) where + toBEncode KError {..} = toDict $ + "e" .=! (errorCode, errorMessage) + .: "t" .=! errorId + .: "y" .=! ("e" :: ByteString) + .: endDict + {-# INLINE toBEncode #-} + + fromBEncode = fromDict $ do + lookAhead $ match "y" (BString "e") + (code, msg) <- field (req "e") + KError code msg <$>! "t" + {-# INLINE fromBEncode #-} +#endif -- cgit v1.2.3