From 8df4213da5b8ff9faff6194a06bd2c9c00dbad16 Mon Sep 17 00:00:00 2001 From: Joe Crayne Date: Fri, 10 Jan 2020 02:51:51 -0500 Subject: First successful TCP relay mediated chat link! --- dht/src/Network/Tox/DHT/Transport.hs | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) (limited to 'dht/src/Network/Tox/DHT') 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 instance Sized DHTPublicKey where - -- NOTE: 41 bytes includes the 1-byte tag 0x9c in the size. - -- WARNING: Serialize instance does not include this byte FIXME - size = VarSize $ \(DHTPublicKey _ _ nodes) -> 41 + case size of + size = VarSize $ \(DHTPublicKey _ _ nodes) -> 40 + case size of ConstSize nodes -> nodes VarSize sznodes -> sznodes nodes instance Sized Word32 where size = ConstSize 4 --- FIXME: Inconsitently, this type does not include the 0x20 or 0x12 tag byte --- where the DHTPublicKey type does include its tag. instance Sized FriendRequest where size = contramap friendNoSpam size <> contramap friendRequestText (VarSize B.length) +getTCPNodeList :: S.Get [TCP.NodeInfo] +getTCPNodeList = do + n <- S.get + (:) n <$> (getTCPNodeList <|> pure []) + instance Serialize DHTPublicKey where -- TODO: This should agree with Sized instance. - get = DHTPublicKey <$> get <*> getPublicKey <*> get - put (DHTPublicKey nonce key nodes) = do + get = DHTPublicKey <$> get <*> getPublicKey <*> (SendNodes <$> getTCPNodeList) + put (DHTPublicKey nonce key (SendNodes nodes)) = do put nonce putPublicKey key - put nodes + mapM_ put nodes instance Serialize FriendRequest where get = FriendRequest <$> get <*> (remaining >>= getBytes) -- cgit v1.2.3