From 362d36e4e31da0d3e3f78cd0aa6dd99cddeaba49 Mon Sep 17 00:00:00 2001 From: joe Date: Tue, 13 Jun 2017 00:43:40 -0400 Subject: Updated Tox module to reflect underlying type changes. --- src/Network/DatagramServer/Tox.hs | 22 +++++++++++++--------- src/Network/DatagramServer/Types.hs | 2 +- 2 files changed, 14 insertions(+), 10 deletions(-) (limited to 'src/Network') diff --git a/src/Network/DatagramServer/Tox.hs b/src/Network/DatagramServer/Tox.hs index d7d20824..300c8f4c 100644 --- a/src/Network/DatagramServer/Tox.hs +++ b/src/Network/DatagramServer/Tox.hs @@ -16,9 +16,9 @@ module Network.DatagramServer.Tox where import Data.Bits import Data.ByteString (ByteString) import qualified Data.Serialize as S -import qualified Data.ByteString.Lazy as L +-- import qualified Data.ByteString.Lazy as L import qualified Data.ByteString.Char8 as Char8 -import Data.Data (Data) +-- import Data.Data (Data) import Data.Word import Data.LargeWord import Data.IP @@ -98,7 +98,7 @@ instance (Serialize a, Serialize b) => Serialize (LargeKey a b) where data Message a = Message { msgType :: MessageType , msgClient :: NodeId Message - , msgNonce :: Nonce24 + , msgNonce :: TransactionID Message , msgPayload :: a } deriving (Show, Generic, Functor, Foldable, Traversable) @@ -257,25 +257,29 @@ curve25519 = CurveFP (CurvePrime prime curvecommon) instance Envelope Message where newtype TransactionID Message = TID Nonce24 - deriving (Eq,Ord,Show,Read,Serialize) + deriving (Eq,Ord,Show,Serialize) -- Read newtype NodeId Message = NodeId Word256 deriving (Serialize, Eq, Ord, Bits, FiniteBits) + type QueryMethod Message = MessageType + envelopePayload = msgPayload envelopeTransaction = msgNonce - envelopeClass Message { msgType = Ping } = Query - envelopeClass Message { msgType = Pong } = Response - envelopeClass Message { msgType = GetNodes } = Query - envelopeClass Message { msgType = SendNodes } = Response + envelopeClass Message { msgType = Ping } = Query Ping + envelopeClass Message { msgType = Pong } = Response Nothing + envelopeClass Message { msgType = GetNodes } = Query GetNodes + envelopeClass Message { msgType = SendNodes } = Response Nothing buildReply self addr qry payload = (fmap (const payload) qry) { msgClient = self } + -- buildQuery = todo + uniqueTransactionId cnt = do return $ either (error "failed to create TransactionId") TID - $ S.decode $ Char8.pack (L.take 24 $ show cur ++ L.repeat ' ') + $ S.decode $ Char8.pack (take 24 $ show cnt ++ repeat ' ') instance WireFormat ByteString Message where type SerializableTo ByteString = Serialize diff --git a/src/Network/DatagramServer/Types.hs b/src/Network/DatagramServer/Types.hs index 37fc40db..afc357b0 100644 --- a/src/Network/DatagramServer/Types.hs +++ b/src/Network/DatagramServer/Types.hs @@ -319,7 +319,7 @@ class Envelope envelope => WireFormat raw envelope where parsePacket :: Proxy envelope -> ByteString -> Either String raw - default parsePacket :: Proxy envelope -> ByteString -> Either String ByteString + default parsePacket :: raw ~ ByteString => Proxy envelope -> ByteString -> Either String ByteString parsePacket _ = Right buildError :: KError (TransactionID envelope) -> Maybe (envelope raw) -- cgit v1.2.3