summaryrefslogtreecommitdiff
path: root/ToxPacket.hs
diff options
context:
space:
mode:
Diffstat (limited to 'ToxPacket.hs')
-rw-r--r--ToxPacket.hs46
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
74newtype GetNodes = GetNodes NodeId
75 deriving (Eq,Ord,Show,Read,S.Serialize)
76
74newtype SendNodes = SendNodes [NodeInfo] 77newtype SendNodes = SendNodes [NodeInfo]
75 deriving (Eq,Ord,Show,Read) 78 deriving (Eq,Ord,Show,Read)
76 79
80instance 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
91data Ping = Ping deriving Show
92data Pong = Pong deriving Show
93
94instance 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
101instance 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
108newtype CookieRequest = CookieRequest PublicKey
109newtype CookieResponse = CookieResponse Cookie
110
111data Cookie = Cookie Nonce24 (Encrypted CookieData)
112
113instance Sized Cookie where size = ConstSize 112 -- 24 byte nonce + 88 byte cookie data
114
115data CookieData = CookieData -- 16 (mac)
116 { cookieTime :: Word64 -- 8
117 , longTermKey :: PublicKey -- 32
118 , dhtKey :: PublicKey -- + 32
119 } -- = 88 bytes when encrypted.
120
121instance Sized CookieRequest where
122 size = ConstSize 64 -- 32 byte key + 32 byte padding