diff options
author | joe <joe@jerkface.net> | 2017-09-12 01:59:09 -0400 |
---|---|---|
committer | joe <joe@jerkface.net> | 2017-09-12 01:59:09 -0400 |
commit | f6678edece2fa77a5ff91abfc8c19913e4d1acdd (patch) | |
tree | c6268dc78cedf78718b000ea5e6f2cedcb425ed6 /DHTTransport.hs | |
parent | 7372d2458b5f9c33e6aa676e5bae74dba438b289 (diff) |
DHTMessage Show instance for debugging.
Diffstat (limited to 'DHTTransport.hs')
-rw-r--r-- | DHTTransport.hs | 18 |
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 #-} | ||
7 | module DHTTransport | 9 | module 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 | ||
57 | deriving 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 | |||
55 | mapMessage :: forall f b. (forall a. Nonce24 -> f a -> b) -> DHTMessage f -> b | 66 | mapMessage :: forall f b. (forall a. Nonce24 -> f a -> b) -> DHTMessage f -> b |
56 | mapMessage f (DHTPing a) = f (assymNonce a) (assymData a) | 67 | mapMessage f (DHTPing a) = f (assymNonce a) (assymData a) |
57 | mapMessage f (DHTPong a) = f (assymNonce a) (assymData a) | 68 | mapMessage 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 | ||
156 | instance Sized DHTRequest where | 168 | instance 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 | ||
208 | instance Serialize LongTermKeyWrap where | 221 | instance 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 | ||
270 | newtype CookieRequest = CookieRequest PublicKey | 283 | newtype CookieRequest = CookieRequest PublicKey |
284 | deriving (Eq, Show) | ||
271 | newtype CookieResponse = CookieResponse Cookie | 285 | newtype CookieResponse = CookieResponse Cookie |
286 | deriving (Eq, Show) | ||
272 | 287 | ||
273 | data Cookie = Cookie Nonce24 (Encrypted CookieData) | 288 | data Cookie = Cookie Nonce24 (Encrypted CookieData) |
289 | deriving (Eq, Ord, Show) | ||
274 | 290 | ||
275 | instance Sized Cookie where size = ConstSize 112 -- 24 byte nonce + 88 byte cookie data | 291 | instance Sized Cookie where size = ConstSize 112 -- 24 byte nonce + 88 byte cookie data |
276 | 292 | ||