summaryrefslogtreecommitdiff
path: root/DHTTransport.hs
diff options
context:
space:
mode:
authorjoe <joe@jerkface.net>2017-09-12 01:59:09 -0400
committerjoe <joe@jerkface.net>2017-09-12 01:59:09 -0400
commitf6678edece2fa77a5ff91abfc8c19913e4d1acdd (patch)
treec6268dc78cedf78718b000ea5e6f2cedcb425ed6 /DHTTransport.hs
parent7372d2458b5f9c33e6aa676e5bae74dba438b289 (diff)
DHTMessage Show instance for debugging.
Diffstat (limited to 'DHTTransport.hs')
-rw-r--r--DHTTransport.hs18
1 files changed, 17 insertions, 1 deletions
diff --git a/DHTTransport.hs b/DHTTransport.hs
index ac263cdc..49d3034d 100644
--- a/DHTTransport.hs
+++ b/DHTTransport.hs
@@ -2,8 +2,10 @@
2{-# LANGUAGE KindSignatures #-} 2{-# LANGUAGE KindSignatures #-}
3{-# LANGUAGE LambdaCase #-} 3{-# LANGUAGE LambdaCase #-}
4{-# LANGUAGE RankNTypes #-} 4{-# LANGUAGE RankNTypes #-}
5{-# LANGUAGE StandaloneDeriving #-}
5{-# LANGUAGE TupleSections #-} 6{-# LANGUAGE TupleSections #-}
6{-# LANGUAGE TypeOperators #-} 7{-# LANGUAGE TypeOperators #-}
8{-# LANGUAGE UndecidableInstances #-}
7module DHTTransport 9module DHTTransport
8 ( parseDHTAddr 10 ( parseDHTAddr
9 , encodeDHTAddr 11 , encodeDHTAddr
@@ -52,6 +54,15 @@ data DHTMessage (f :: * -> *)
52 | DHTCookie Nonce24 (f Cookie) 54 | DHTCookie Nonce24 (f Cookie)
53 | DHTDHTRequest PublicKey (Assym (f DHTRequest)) 55 | DHTDHTRequest PublicKey (Assym (f DHTRequest))
54 56
57deriving instance ( Show (f Cookie)
58 , Show (Assym (f Ping))
59 , Show (Assym (f Pong))
60 , Show (Assym (f GetNodes))
61 , Show (Assym (f SendNodes))
62 , Show (Assym (f CookieRequest))
63 , Show (Assym (f DHTRequest))
64 ) => Show (DHTMessage f)
65
55mapMessage :: forall f b. (forall a. Nonce24 -> f a -> b) -> DHTMessage f -> b 66mapMessage :: forall f b. (forall a. Nonce24 -> f a -> b) -> DHTMessage f -> b
56mapMessage f (DHTPing a) = f (assymNonce a) (assymData a) 67mapMessage f (DHTPing a) = f (assymNonce a) (assymData a)
57mapMessage f (DHTPong a) = f (assymNonce a) (assymData a) 68mapMessage f (DHTPong a) = f (assymNonce a) (assymData a)
@@ -152,6 +163,7 @@ data DHTRequest
152-- `8` `uint64_t` random number (the same that was received in request) 163-- `8` `uint64_t` random number (the same that was received in request)
153 | NATPong Nonce8 164 | NATPong Nonce8
154 | DHTPK LongTermKeyWrap 165 | DHTPK LongTermKeyWrap
166 deriving Show
155 167
156instance Sized DHTRequest where 168instance Sized DHTRequest where
157 size = VarSize $ \case 169 size = VarSize $ \case
@@ -204,6 +216,7 @@ data LongTermKeyWrap = LongTermKeyWrap
204 , wrapNonce :: Nonce24 216 , wrapNonce :: Nonce24
205 , wrapData :: Encrypted DHTPublicKey 217 , wrapData :: Encrypted DHTPublicKey
206 } 218 }
219 deriving Show
207 220
208instance Serialize LongTermKeyWrap where 221instance Serialize LongTermKeyWrap where
209 get = LongTermKeyWrap <$> getPublicKey <*> get <*> get 222 get = LongTermKeyWrap <$> getPublicKey <*> get <*> get
@@ -268,9 +281,12 @@ instance S.Serialize Pong where
268 put Pong = S.put (1 :: Word8) 281 put Pong = S.put (1 :: Word8)
269 282
270newtype CookieRequest = CookieRequest PublicKey 283newtype CookieRequest = CookieRequest PublicKey
284 deriving (Eq, Show)
271newtype CookieResponse = CookieResponse Cookie 285newtype CookieResponse = CookieResponse Cookie
286 deriving (Eq, Show)
272 287
273data Cookie = Cookie Nonce24 (Encrypted CookieData) 288data Cookie = Cookie Nonce24 (Encrypted CookieData)
289 deriving (Eq, Ord, Show)
274 290
275instance Sized Cookie where size = ConstSize 112 -- 24 byte nonce + 88 byte cookie data 291instance Sized Cookie where size = ConstSize 112 -- 24 byte nonce + 88 byte cookie data
276 292