diff options
-rw-r--r-- | src/Network/Tox/Crypto/Handlers.hs | 31 |
1 files changed, 29 insertions, 2 deletions
diff --git a/src/Network/Tox/Crypto/Handlers.hs b/src/Network/Tox/Crypto/Handlers.hs index 1cb9c48e..66de618d 100644 --- a/src/Network/Tox/Crypto/Handlers.hs +++ b/src/Network/Tox/Crypto/Handlers.hs | |||
@@ -741,8 +741,13 @@ runUponHandshake netCryptoSession0 addr pktoq = do | |||
741 | labelThread tid ("NetCryptoDequeue." ++ show (key2id remotePublicKey) ++ sidStr) | 741 | labelThread tid ("NetCryptoDequeue." ++ show (key2id remotePublicKey) ++ sidStr) |
742 | fix $ \loop -> do | 742 | fix $ \loop -> do |
743 | cd <- atomically $ PQ.dequeue pktq | 743 | cd <- atomically $ PQ.dequeue pktq |
744 | dput XNetCrypto $ "Dequeued::" ++ show (bufferData cd) ++ " now running hook..." | 744 | if msgID (bufferData cd) == PacketRequest |
745 | _ <- runCryptoHook netCryptoSession0 (bufferData cd) | 745 | then do |
746 | dput XNetCrypto $ "Dequeued::PacketRequest seqno=" ++ show (bufferStart cd) ++ " " ++ show (bufferData cd) | ||
747 | handlePacketRequest netCryptoSession0 cd | ||
748 | else do | ||
749 | dput XNetCrypto $ "Dequeued::" ++ show (bufferData cd) ++ " now running hook..." | ||
750 | void $ runCryptoHook netCryptoSession0 (bufferData cd) | ||
746 | loop | 751 | loop |
747 | dput XNetCrypto $ "runUponHandshake: " ++ show threadid ++ " = NetCryptoDequeue." ++ show (key2id remotePublicKey) ++ sidStr | 752 | dput XNetCrypto $ "runUponHandshake: " ++ show threadid ++ " = NetCryptoDequeue." ++ show (key2id remotePublicKey) ++ sidStr |
748 | -- launch request thread | 753 | -- launch request thread |
@@ -1327,6 +1332,28 @@ defaultCryptoDataHooks | |||
1327 | , (Msg KillPacket, [defaultKillHook]) | 1332 | , (Msg KillPacket, [defaultKillHook]) |
1328 | ] | 1333 | ] |
1329 | 1334 | ||
1335 | handlePacketRequest :: NetCryptoSession -> CryptoData -> IO () | ||
1336 | handlePacketRequest session (CryptoData { bufferStart=buffstart | ||
1337 | , bufferData=cm@(msgID -> PacketRequest) | ||
1338 | }) | let getbytes (OneByte _) = [] | ||
1339 | getbytes (TwoByte _ b) = [b] | ||
1340 | getbytes (UpToN _ bs) = B.unpack bs | ||
1341 | , bs <- getbytes cm | ||
1342 | , not (null bs) | ||
1343 | , HaveDHTKey addr <- ncSockAddr session | ||
1344 | = do | ||
1345 | mbOutQ <- atomically $ readTVar (ncOutgoingQueue session) | ||
1346 | case mbOutQ of | ||
1347 | HaveHandshake pktoq -> do | ||
1348 | getOutGoingParam <-PQ.readyOutGoing pktoq | ||
1349 | ps <- atomically $ PQ.getRequested getOutGoingParam pktoq buffstart bs | ||
1350 | let resend (Just (pkt,n)) = sendSessionPacket (ncAllSessions session) addr pkt | ||
1351 | resend _ = return () | ||
1352 | mapM_ resend ps | ||
1353 | _ -> return () | ||
1354 | |||
1355 | handlePacketRequest session cd = return () | ||
1356 | |||
1330 | defaultKillHook :: NetCryptoSession -> CryptoMessage -> IO (Maybe (CryptoMessage -> CryptoMessage)) | 1357 | defaultKillHook :: NetCryptoSession -> CryptoMessage -> IO (Maybe (CryptoMessage -> CryptoMessage)) |
1331 | defaultKillHook session cm@(msgID -> KillPacket) = do | 1358 | defaultKillHook session cm@(msgID -> KillPacket) = do |
1332 | dput XNetCrypto $ "Recieved kill packet (sessionid: " ++ show (ncSessionId session) ++ ") destroying session" | 1359 | dput XNetCrypto $ "Recieved kill packet (sessionid: " ++ show (ncSessionId session) ++ ") destroying session" |