diff options
Diffstat (limited to 'src/Network/DatagramServer')
-rw-r--r-- | src/Network/DatagramServer/Mainline.hs | 8 | ||||
-rw-r--r-- | src/Network/DatagramServer/Tox.hs | 6 | ||||
-rw-r--r-- | src/Network/DatagramServer/Types.hs | 11 |
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 | ||
237 | instance (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 | |||
241 | instance Serialize (NodeId KMessageOf) where | 236 | instance 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. |
260 | instance Pretty (NodeId KMessageOf) where | 255 | instance 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 | ||
264 | instance Serialize (TransactionID KMessageOf) where | 258 | instance 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 | |||
30 | import qualified Network.DatagramServer.Types as Envelope (NodeId) | 30 | import qualified Network.DatagramServer.Types as Envelope (NodeId) |
31 | import Crypto.PubKey.ECC.Types | 31 | import Crypto.PubKey.ECC.Types |
32 | 32 | ||
33 | |||
33 | type Key32 = Word256 -- 32 byte key | 34 | type Key32 = Word256 -- 32 byte key |
34 | type Nonce8 = Word64 -- 8 bytes | 35 | type Nonce8 = Word64 -- 8 bytes |
35 | type Nonce24 = Word192 -- 24 bytes | 36 | type 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 | ||
93 | instance (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' |
98 | data Message a = Message | 94 | data 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 | |||
41 | import Data.ByteString.Base16 as Base16 | 41 | import Data.ByteString.Base16 as Base16 |
42 | import System.Entropy | 42 | import System.Entropy |
43 | import Network.DatagramServer.Error | 43 | import Network.DatagramServer.Error |
44 | import Data.LargeWord | ||
45 | |||
44 | 46 | ||
45 | class (Eq a, Serialize a, Typeable a, Hashable a, Pretty a) | 47 | class (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 | |||
336 | encodeHexDoc :: Serialize x => x -> Doc | ||
337 | encodeHexDoc nid = PP.text $ Char8.unpack $ Base16.encode $ S.encode nid | ||
338 | |||
339 | -- FIXME Orphan Serialize intance for large words | ||
340 | instance (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 | |||