From b5df06bf0fed5a30a9b16e1032037e6cea378464 Mon Sep 17 00:00:00 2001 From: Joe Crayne Date: Wed, 16 Jan 2019 21:50:19 -0500 Subject: Queries table: Switched MVar with callback. --- src/Network/Tox.hs | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-) (limited to 'src/Network/Tox.hs') diff --git a/src/Network/Tox.hs b/src/Network/Tox.hs index c14339e4..98c03b80 100644 --- a/src/Network/Tox.hs +++ b/src/Network/Tox.hs @@ -44,6 +44,7 @@ import Network.Socket import System.Endian import System.IO.Error +import Data.TableMethods import qualified Data.Word64Map import Network.BitTorrent.DHT.Token as Token import qualified Data.Wrapper.PSQ as PSQ @@ -159,12 +160,10 @@ newClient drg net classify selfAddr handlers modifytbl modifynet = do let client = Client { clientNet = addHandler (reportParseError eprinter) (handleMessage client) $ modifynet client net , clientDispatcher = dispatch tbl var (handlers client) client - , clientErrorReporter = eprinter { reportTimeout = reportTimeout ignoreErrors } + , clientErrorReporter = eprinter , clientPending = var , clientAddress = selfAddr , clientResponseId = genNonce24 var - , clientEnterQuery = \_ -> return () - , clientLeaveQuery = \_ _ -> return () } in client return $ either mkclient mkclient tblvar handlers @@ -250,8 +249,8 @@ newOnionClient :: DRG g => -> TVar Onion.AnnouncedKeys -> OnionRouter -> TVar (g, Data.Word64Map.Word64Map a) - -> (MVar Onion.Message -> a) - -> (a -> Onion.Message -> IO void) + -> ((Maybe Onion.Message -> IO ()) -> a) + -> (a -> Maybe Onion.Message -> IO void) -> Client String DHT.PacketKind DHT.TransactionId @@ -268,12 +267,10 @@ newOnionClient crypto net r toks keydb orouter map_var store load = c , tableMethods = hookQueries orouter DHT.transactionKey $ transactionMethods' store load (contramap w64Key w64MapMethods) gen } - , clientErrorReporter = eprinter { reportTimeout = reportTimeout ignoreErrors } + , clientErrorReporter = eprinter , clientPending = map_var , clientAddress = getOnionAlias crypto $ R.thisNode <$> readTVar (DHT.routing4 r) , clientResponseId = genNonce24 map_var - , clientEnterQuery = \_ -> return () - , clientLeaveQuery = \_ _ -> return () } newTox :: TVar Onion.AnnouncedKeys -- ^ Store of announced keys we are a rendezvous for. @@ -359,10 +356,9 @@ newToxOverTransport keydb addr onNewSession suppliedDHTKey udp tcp = do let onionnet = layerTransportM (Onion.decrypt crypto) (Onion.encrypt crypto) onioncrypt let onionclient = newOnionClient crypto onionnet (mkrouting dhtclient) toks keydb orouter' otbl Right $ \case - Right v -> tryPutMVar v - Left v -> \_ -> do + Right v -> v + Left v -> \_ -> dput XUnexpected "TCP-sent onion query got response over UDP?" - return False return Tox { toxDHT = dhtclient -- cgit v1.2.3