summaryrefslogtreecommitdiff
path: root/src/Network/Tox/TCP.hs
diff options
context:
space:
mode:
authorJoe Crayne <joe@jerkface.net>2019-01-16 21:50:19 -0500
committerJoe Crayne <joe@jerkface.net>2019-01-16 21:50:19 -0500
commitb5df06bf0fed5a30a9b16e1032037e6cea378464 (patch)
tree4cba15d7523f45911ec5682ac05c25fe6c5e6487 /src/Network/Tox/TCP.hs
parentf9339cd18bceba3f5000f1d2ccd9ce7dbc5f2cb0 (diff)
Queries table: Switched MVar with callback.
Diffstat (limited to 'src/Network/Tox/TCP.hs')
-rw-r--r--src/Network/Tox/TCP.hs9
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
34import ControlMaybe 34import ControlMaybe
35import Crypto.Tox 35import Crypto.Tox
36import Data.ByteString (hPut,hGet,ByteString,length) 36import Data.ByteString (hPut,hGet,ByteString,length)
37import Data.TableMethods
37import Data.Tox.Relay 38import Data.Tox.Relay
38import qualified Data.Word64Map 39import qualified Data.Word64Map
39import DebugTag 40import 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.
271newClient :: TransportCrypto 272newClient :: 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 }