diff options
Diffstat (limited to 'dht/src/Network/Tox/DHT/Transport.hs')
-rw-r--r-- | dht/src/Network/Tox/DHT/Transport.hs | 17 |
1 files changed, 9 insertions, 8 deletions
diff --git a/dht/src/Network/Tox/DHT/Transport.hs b/dht/src/Network/Tox/DHT/Transport.hs index ff743f29..9136caeb 100644 --- a/dht/src/Network/Tox/DHT/Transport.hs +++ b/dht/src/Network/Tox/DHT/Transport.hs | |||
@@ -292,26 +292,27 @@ instance Serialize LongTermKeyWrap where | |||
292 | 292 | ||
293 | 293 | ||
294 | instance Sized DHTPublicKey where | 294 | instance Sized DHTPublicKey where |
295 | -- NOTE: 41 bytes includes the 1-byte tag 0x9c in the size. | 295 | size = VarSize $ \(DHTPublicKey _ _ nodes) -> 40 + case size of |
296 | -- WARNING: Serialize instance does not include this byte FIXME | ||
297 | size = VarSize $ \(DHTPublicKey _ _ nodes) -> 41 + case size of | ||
298 | ConstSize nodes -> nodes | 296 | ConstSize nodes -> nodes |
299 | VarSize sznodes -> sznodes nodes | 297 | VarSize sznodes -> sznodes nodes |
300 | 298 | ||
301 | instance Sized Word32 where size = ConstSize 4 | 299 | instance Sized Word32 where size = ConstSize 4 |
302 | 300 | ||
303 | -- FIXME: Inconsitently, this type does not include the 0x20 or 0x12 tag byte | ||
304 | -- where the DHTPublicKey type does include its tag. | ||
305 | instance Sized FriendRequest where | 301 | instance Sized FriendRequest where |
306 | size = contramap friendNoSpam size <> contramap friendRequestText (VarSize B.length) | 302 | size = contramap friendNoSpam size <> contramap friendRequestText (VarSize B.length) |
307 | 303 | ||
304 | getTCPNodeList :: S.Get [TCP.NodeInfo] | ||
305 | getTCPNodeList = do | ||
306 | n <- S.get | ||
307 | (:) n <$> (getTCPNodeList <|> pure []) | ||
308 | |||
308 | instance Serialize DHTPublicKey where | 309 | instance Serialize DHTPublicKey where |
309 | -- TODO: This should agree with Sized instance. | 310 | -- TODO: This should agree with Sized instance. |
310 | get = DHTPublicKey <$> get <*> getPublicKey <*> get | 311 | get = DHTPublicKey <$> get <*> getPublicKey <*> (SendNodes <$> getTCPNodeList) |
311 | put (DHTPublicKey nonce key nodes) = do | 312 | put (DHTPublicKey nonce key (SendNodes nodes)) = do |
312 | put nonce | 313 | put nonce |
313 | putPublicKey key | 314 | putPublicKey key |
314 | put nodes | 315 | mapM_ put nodes |
315 | 316 | ||
316 | instance Serialize FriendRequest where | 317 | instance Serialize FriendRequest where |
317 | get = FriendRequest <$> get <*> (remaining >>= getBytes) | 318 | get = FriendRequest <$> get <*> (remaining >>= getBytes) |