summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/Network/DatagramServer/Tox.hs22
-rw-r--r--src/Network/DatagramServer/Types.hs2
2 files changed, 14 insertions, 10 deletions
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
16import Data.Bits 16import Data.Bits
17import Data.ByteString (ByteString) 17import Data.ByteString (ByteString)
18import qualified Data.Serialize as S 18import qualified Data.Serialize as S
19import qualified Data.ByteString.Lazy as L 19-- import qualified Data.ByteString.Lazy as L
20import qualified Data.ByteString.Char8 as Char8 20import qualified Data.ByteString.Char8 as Char8
21import Data.Data (Data) 21-- import Data.Data (Data)
22import Data.Word 22import Data.Word
23import Data.LargeWord 23import Data.LargeWord
24import Data.IP 24import Data.IP
@@ -98,7 +98,7 @@ instance (Serialize a, Serialize b) => Serialize (LargeKey a b) where
98data Message a = Message 98data Message a = Message
99 { msgType :: MessageType 99 { msgType :: MessageType
100 , msgClient :: NodeId Message 100 , msgClient :: NodeId Message
101 , msgNonce :: Nonce24 101 , msgNonce :: TransactionID Message
102 , msgPayload :: a 102 , msgPayload :: a
103 } 103 }
104 deriving (Show, Generic, Functor, Foldable, Traversable) 104 deriving (Show, Generic, Functor, Foldable, Traversable)
@@ -257,25 +257,29 @@ curve25519 = CurveFP (CurvePrime prime curvecommon)
257 257
258instance Envelope Message where 258instance Envelope Message where
259 newtype TransactionID Message = TID Nonce24 259 newtype TransactionID Message = TID Nonce24
260 deriving (Eq,Ord,Show,Read,Serialize) 260 deriving (Eq,Ord,Show,Serialize) -- Read
261 261
262 newtype NodeId Message = NodeId Word256 262 newtype NodeId Message = NodeId Word256
263 deriving (Serialize, Eq, Ord, Bits, FiniteBits) 263 deriving (Serialize, Eq, Ord, Bits, FiniteBits)
264 264
265 type QueryMethod Message = MessageType
266
265 envelopePayload = msgPayload 267 envelopePayload = msgPayload
266 268
267 envelopeTransaction = msgNonce 269 envelopeTransaction = msgNonce
268 270
269 envelopeClass Message { msgType = Ping } = Query 271 envelopeClass Message { msgType = Ping } = Query Ping
270 envelopeClass Message { msgType = Pong } = Response 272 envelopeClass Message { msgType = Pong } = Response Nothing
271 envelopeClass Message { msgType = GetNodes } = Query 273 envelopeClass Message { msgType = GetNodes } = Query GetNodes
272 envelopeClass Message { msgType = SendNodes } = Response 274 envelopeClass Message { msgType = SendNodes } = Response Nothing
273 275
274 buildReply self addr qry payload = (fmap (const payload) qry) { msgClient = self } 276 buildReply self addr qry payload = (fmap (const payload) qry) { msgClient = self }
275 277
278 -- buildQuery = todo
279
276 uniqueTransactionId cnt = do 280 uniqueTransactionId cnt = do
277 return $ either (error "failed to create TransactionId") TID 281 return $ either (error "failed to create TransactionId") TID
278 $ S.decode $ Char8.pack (L.take 24 $ show cur ++ L.repeat ' ') 282 $ S.decode $ Char8.pack (take 24 $ show cnt ++ repeat ' ')
279 283
280instance WireFormat ByteString Message where 284instance WireFormat ByteString Message where
281 type SerializableTo ByteString = Serialize 285 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
319 319
320 parsePacket :: Proxy envelope -> ByteString -> Either String raw 320 parsePacket :: Proxy envelope -> ByteString -> Either String raw
321 321
322 default parsePacket :: Proxy envelope -> ByteString -> Either String ByteString 322 default parsePacket :: raw ~ ByteString => Proxy envelope -> ByteString -> Either String ByteString
323 parsePacket _ = Right 323 parsePacket _ = Right
324 324
325 buildError :: KError (TransactionID envelope) -> Maybe (envelope raw) 325 buildError :: KError (TransactionID envelope) -> Maybe (envelope raw)