summaryrefslogtreecommitdiff
path: root/src/Network/DatagramServer
diff options
context:
space:
mode:
Diffstat (limited to 'src/Network/DatagramServer')
-rw-r--r--src/Network/DatagramServer/Mainline.hs8
-rw-r--r--src/Network/DatagramServer/Tox.hs6
-rw-r--r--src/Network/DatagramServer/Types.hs11
3 files changed, 13 insertions, 12 deletions
diff --git a/src/Network/DatagramServer/Mainline.hs b/src/Network/DatagramServer/Mainline.hs
index e9e2798c..c2333a42 100644
--- a/src/Network/DatagramServer/Mainline.hs
+++ b/src/Network/DatagramServer/Mainline.hs
@@ -233,11 +233,6 @@ instance BEncode (NodeId KMessageOf) where
233 233
234-- instance BEncode NodeId where TODO 234-- instance BEncode NodeId where TODO
235 235
236-- TODO: put this somewhere appropriate
237instance (Serialize a, Serialize b) => Serialize (LargeKey a b) where
238 put (LargeKey lo hi) = put hi >> put lo
239 get = flip LargeKey <$> get <*> get
240
241instance Serialize (NodeId KMessageOf) where 236instance Serialize (NodeId KMessageOf) where
242 get = NodeId <$> get 237 get = NodeId <$> get
243 {-# INLINE get #-} 238 {-# INLINE get #-}
@@ -257,8 +252,7 @@ instance Default (NodeId KMessageOf) where
257 def = NodeId 0 252 def = NodeId 0
258 253
259-- | base16 encoded. 254-- | base16 encoded.
260instance Pretty (NodeId KMessageOf) where 255instance Pretty (NodeId KMessageOf) where pPrint (NodeId nid) = encodeHexDoc nid
261 pPrint (NodeId nid) = PP.text $ Char8.unpack $ Base16.encode $ S.encode nid
262 256
263 257
264instance Serialize (TransactionID KMessageOf) where 258instance Serialize (TransactionID KMessageOf) where
diff --git a/src/Network/DatagramServer/Tox.hs b/src/Network/DatagramServer/Tox.hs
index 300c8f4c..2c432d70 100644
--- a/src/Network/DatagramServer/Tox.hs
+++ b/src/Network/DatagramServer/Tox.hs
@@ -30,6 +30,7 @@ import Network.DatagramServer.Types
30import qualified Network.DatagramServer.Types as Envelope (NodeId) 30import qualified Network.DatagramServer.Types as Envelope (NodeId)
31import Crypto.PubKey.ECC.Types 31import Crypto.PubKey.ECC.Types
32 32
33
33type Key32 = Word256 -- 32 byte key 34type Key32 = Word256 -- 32 byte key
34type Nonce8 = Word64 -- 8 bytes 35type Nonce8 = Word64 -- 8 bytes
35type Nonce24 = Word192 -- 24 bytes 36type Nonce24 = Word192 -- 24 bytes
@@ -89,11 +90,6 @@ pattern SendNodes = MessageType 4
89 -} 90 -}
90 91
91 92
92-- FIXME Orphan Serialize intance for large words
93instance (Serialize a, Serialize b) => Serialize (LargeKey a b) where
94 put (LargeKey lo hi) = put hi >> put lo
95 get = flip LargeKey <$> get <*> get
96
97-- | Use with 'PingPayload', 'GetNodesPayload', or 'SendNodesPayload' 93-- | Use with 'PingPayload', 'GetNodesPayload', or 'SendNodesPayload'
98data Message a = Message 94data Message a = Message
99 { msgType :: MessageType 95 { msgType :: MessageType
diff --git a/src/Network/DatagramServer/Types.hs b/src/Network/DatagramServer/Types.hs
index afc357b0..dd915fdb 100644
--- a/src/Network/DatagramServer/Types.hs
+++ b/src/Network/DatagramServer/Types.hs
@@ -41,6 +41,8 @@ import qualified Data.ByteString as BS
41import Data.ByteString.Base16 as Base16 41import Data.ByteString.Base16 as Base16
42import System.Entropy 42import System.Entropy
43import Network.DatagramServer.Error 43import Network.DatagramServer.Error
44import Data.LargeWord
45
44 46
45class (Eq a, Serialize a, Typeable a, Hashable a, Pretty a) 47class (Eq a, Serialize a, Typeable a, Hashable a, Pretty a)
46 => Address a where 48 => Address a where
@@ -330,3 +332,12 @@ class Envelope envelope => WireFormat raw envelope where
330 332
331 encodeHeaders :: CipherContext raw envelope -> envelope raw -> ByteString 333 encodeHeaders :: CipherContext raw envelope -> envelope raw -> ByteString
332 encodePayload :: SerializableTo raw a => envelope a -> envelope raw 334 encodePayload :: SerializableTo raw a => envelope a -> envelope raw
335
336encodeHexDoc :: Serialize x => x -> Doc
337encodeHexDoc nid = PP.text $ Char8.unpack $ Base16.encode $ S.encode nid
338
339-- FIXME Orphan Serialize intance for large words
340instance (Serialize a, Serialize b) => Serialize (LargeKey a b) where
341 put (LargeKey lo hi) = put hi >> put lo
342 get = flip LargeKey <$> get <*> get
343