diff options
author | Joe Crayne <joe@jerkface.net> | 2019-01-16 21:50:19 -0500 |
---|---|---|
committer | Joe Crayne <joe@jerkface.net> | 2019-01-16 21:50:19 -0500 |
commit | b5df06bf0fed5a30a9b16e1032037e6cea378464 (patch) | |
tree | 4cba15d7523f45911ec5682ac05c25fe6c5e6487 /src/Network/Tox/TCP.hs | |
parent | f9339cd18bceba3f5000f1d2ccd9ce7dbc5f2cb0 (diff) |
Queries table: Switched MVar with callback.
Diffstat (limited to 'src/Network/Tox/TCP.hs')
-rw-r--r-- | src/Network/Tox/TCP.hs | 9 |
1 files changed, 4 insertions, 5 deletions
diff --git a/src/Network/Tox/TCP.hs b/src/Network/Tox/TCP.hs index adb42514..9c1ffe48 100644 --- a/src/Network/Tox/TCP.hs +++ b/src/Network/Tox/TCP.hs | |||
@@ -34,6 +34,7 @@ import System.Timeout | |||
34 | import ControlMaybe | 34 | import ControlMaybe |
35 | import Crypto.Tox | 35 | import Crypto.Tox |
36 | import Data.ByteString (hPut,hGet,ByteString,length) | 36 | import Data.ByteString (hPut,hGet,ByteString,length) |
37 | import Data.TableMethods | ||
37 | import Data.Tox.Relay | 38 | import Data.Tox.Relay |
38 | import qualified Data.Word64Map | 39 | import qualified Data.Word64Map |
39 | import DebugTag | 40 | import DebugTag |
@@ -269,7 +270,7 @@ type RelayClient = Client String PacketNumber Nonce8 NodeInfo (Bool,RelayPacket) | |||
269 | -- defaults are 'id' and 'tryPutMVar'. The resulting customized table state | 270 | -- defaults are 'id' and 'tryPutMVar'. The resulting customized table state |
270 | -- will be returned to the caller along with the new client. | 271 | -- will be returned to the caller along with the new client. |
271 | newClient :: TransportCrypto | 272 | newClient :: TransportCrypto |
272 | -> (MVar (Bool,RelayPacket) -> a) -- ^ store mvar for query | 273 | -> ((Maybe (Bool,RelayPacket) -> IO ()) -> a) -- ^ store mvar for query |
273 | -> (a -> RelayPacket -> IO void) -- ^ load mvar for query | 274 | -> (a -> RelayPacket -> IO void) -- ^ load mvar for query |
274 | -> IO ( ( TVar (ChaChaDRG, Data.Word64Map.Word64Map a) | 275 | -> IO ( ( TVar (ChaChaDRG, Data.Word64Map.Word64Map a) |
275 | , TCPCache (SessionProtocol RelayPacket RelayPacket) ) | 276 | , TCPCache (SessionProtocol RelayPacket RelayPacket) ) |
@@ -299,16 +300,14 @@ newClient crypto store load = do | |||
299 | { methodParse = \x -> Left "tcp-lookuphandler?" -- :: x -> Either err a | 300 | { methodParse = \x -> Left "tcp-lookuphandler?" -- :: x -> Either err a |
300 | , noreplyAction = \addr a -> dput XTCP $ "tcp-lookupHandler: "++show w | 301 | , noreplyAction = \addr a -> dput XTCP $ "tcp-lookupHandler: "++show w |
301 | } | 302 | } |
302 | , tableMethods = transactionMethods' store (\x -> load x . snd) (contramap (\(Nonce8 w64) -> w64) w64MapMethods) | 303 | , tableMethods = transactionMethods' store (\x -> mapM_ (load x . snd)) (contramap (\(Nonce8 w64) -> w64) w64MapMethods) |
303 | $ first (either error Nonce8 . decode) . randomBytesGenerate 8 | 304 | $ first (either error Nonce8 . decode) . randomBytesGenerate 8 |
304 | } | 305 | } |
305 | , clientErrorReporter = logErrors { reportTimeout = reportTimeout ignoreErrors } | 306 | , clientErrorReporter = logErrors |
306 | , clientPending = map_var | 307 | , clientPending = map_var |
307 | , clientAddress = \_ -> return $ NodeInfo | 308 | , clientAddress = \_ -> return $ NodeInfo |
308 | { udpNodeInfo = either error id $ UDP.nodeInfo (UDP.key2id $ transportPublic crypto) (SockAddrInet 0 0) | 309 | { udpNodeInfo = either error id $ UDP.nodeInfo (UDP.key2id $ transportPublic crypto) (SockAddrInet 0 0) |
309 | , tcpPort = 0 | 310 | , tcpPort = 0 |
310 | } | 311 | } |
311 | , clientResponseId = return | 312 | , clientResponseId = return |
312 | , clientEnterQuery = \_ -> return () | ||
313 | , clientLeaveQuery = \_ _ -> return () | ||
314 | } | 313 | } |