From 32a9be9211583f8405e92ecc1158f035141820be Mon Sep 17 00:00:00 2001 From: Joe Crayne Date: Wed, 15 Jan 2020 20:12:26 -0500 Subject: Rewrite ConnectNotification to RoutingResponse. --- dht/src/Network/Tox/TCP.hs | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/dht/src/Network/Tox/TCP.hs b/dht/src/Network/Tox/TCP.hs index cb0f0a1b..f8ec430b 100644 --- a/dht/src/Network/Tox/TCP.hs +++ b/dht/src/Network/Tox/TCP.hs @@ -429,9 +429,21 @@ partitionRelay tr = partitionTransportM parse encode tr return $ Left (bs, ViaRelay (Just conid) nid ni) parse ((_,OOBRecv key bs), ni) = return $ Left (bs, ViaRelay Nothing (UDP.key2id key) ni) - parse passthrough@((st,RoutingResponse conid k),ni) = do + parse ((st,RoutingResponse conid k),ni) = do setRelayedRemote st conid (UDP.key2id k) - return $ Right passthrough + -- Note: Rewriting inbound RoutingResponse to be a RoutingRequest + -- instead. This is because the routing reqest is not yet fullfilled + -- until a ConnectNotification is received. + -- + -- We could use Left here instead as inbound RoutingRequest packets are + -- not normally responded to by a client. + return $ Right ((st,RoutingRequest k),ni) + parse ((st,ConnectNotification conid),ni) = do + nid <- getRelayedRemote st conid + -- Note: Rewriting inbound ConnectNotification to a RoutingResponse + -- because we want to include the public key and connection id in a + -- single message. + return $ Right ((st,RoutingResponse conid (UDP.id2key nid)),ni) parse passthrough = return $ Right passthrough -- cgit v1.2.3