diff options
author | joe <joe@jerkface.net> | 2017-08-30 06:17:23 -0400 |
---|---|---|
committer | joe <joe@jerkface.net> | 2017-08-30 06:17:23 -0400 |
commit | 2d0d30e70bea230ede343bd1cc2700b11becb494 (patch) | |
tree | 1650c5339a90c29a33624a5caf0f8841d6741023 /ToxPacket.hs | |
parent | 9d16ca2529a184309cbd50bd3b6bc228b31c5e91 (diff) |
More progress on ToxTransport and related modules.
Diffstat (limited to 'ToxPacket.hs')
-rw-r--r-- | ToxPacket.hs | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/ToxPacket.hs b/ToxPacket.hs index d10a7597..bc20f480 100644 --- a/ToxPacket.hs +++ b/ToxPacket.hs | |||
@@ -71,6 +71,52 @@ data Assym a = Assym | |||
71 | , assymData :: a | 71 | , assymData :: a |
72 | } | 72 | } |
73 | 73 | ||
74 | newtype GetNodes = GetNodes NodeId | ||
75 | deriving (Eq,Ord,Show,Read,S.Serialize) | ||
76 | |||
74 | newtype SendNodes = SendNodes [NodeInfo] | 77 | newtype SendNodes = SendNodes [NodeInfo] |
75 | deriving (Eq,Ord,Show,Read) | 78 | deriving (Eq,Ord,Show,Read) |
76 | 79 | ||
80 | instance S.Serialize SendNodes where | ||
81 | get = do | ||
82 | cnt <- S.get :: S.Get Word8 | ||
83 | ns <- sequence $ replicate (fromIntegral cnt) S.get | ||
84 | return $ SendNodes ns | ||
85 | |||
86 | put (SendNodes ns) = do | ||
87 | let ns' = take 4 ns | ||
88 | S.put (fromIntegral (length ns') :: Word8) | ||
89 | mapM_ S.put ns' | ||
90 | |||
91 | data Ping = Ping deriving Show | ||
92 | data Pong = Pong deriving Show | ||
93 | |||
94 | instance S.Serialize Ping where | ||
95 | get = do w8 <- S.get | ||
96 | if (w8 :: Word8) /= 0 | ||
97 | then fail "Malformed ping." | ||
98 | else return Ping | ||
99 | put Ping = S.put (0 :: Word8) | ||
100 | |||
101 | instance S.Serialize Pong where | ||
102 | get = do w8 <- S.get | ||
103 | if (w8 :: Word8) /= 1 | ||
104 | then fail "Malformed pong." | ||
105 | else return Pong | ||
106 | put Pong = S.put (1 :: Word8) | ||
107 | |||
108 | newtype CookieRequest = CookieRequest PublicKey | ||
109 | newtype CookieResponse = CookieResponse Cookie | ||
110 | |||
111 | data Cookie = Cookie Nonce24 (Encrypted CookieData) | ||
112 | |||
113 | instance Sized Cookie where size = ConstSize 112 -- 24 byte nonce + 88 byte cookie data | ||
114 | |||
115 | data CookieData = CookieData -- 16 (mac) | ||
116 | { cookieTime :: Word64 -- 8 | ||
117 | , longTermKey :: PublicKey -- 32 | ||
118 | , dhtKey :: PublicKey -- + 32 | ||
119 | } -- = 88 bytes when encrypted. | ||
120 | |||
121 | instance Sized CookieRequest where | ||
122 | size = ConstSize 64 -- 32 byte key + 32 byte padding | ||