summaryrefslogtreecommitdiff
path: root/src/Network/Tox
diff options
context:
space:
mode:
Diffstat (limited to 'src/Network/Tox')
-rw-r--r--src/Network/Tox/AggregateSession.hs21
-rw-r--r--src/Network/Tox/Crypto/Handlers.hs14
2 files changed, 11 insertions, 24 deletions
diff --git a/src/Network/Tox/AggregateSession.hs b/src/Network/Tox/AggregateSession.hs
index 26e7153a..27258a6f 100644
--- a/src/Network/Tox/AggregateSession.hs
+++ b/src/Network/Tox/AggregateSession.hs
@@ -242,26 +242,7 @@ dispatchMessage c msid msg = join $ atomically $ do
242 imap <- readTVar (contactSession c) 242 imap <- readTVar (contactSession c)
243 let go = case msid of Nothing -> forM_ imap 243 let go = case msid of Nothing -> forM_ imap
244 Just sid -> forM_ (IntMap.lookup sid imap) 244 Just sid -> forM_ (IntMap.lookup sid imap)
245 return $ go $ \con -> do 245 return $ go $ \con -> sendLossless (transportCrypto (ncAllSessions (singleSession con))) (singleSession con) msg
246 outq <- atomically $ do
247 mbOutq <- readTVar (ncOutgoingQueue $ singleSession con)
248 case mbOutq of
249 HaveHandshake outq -> return outq
250 NeedHandshake -> retry
251 extra <- nqToWireIO outq
252 r <- atomically $ do
253 rTry <- tryAppendQueueOutgoing extra outq msg
254 case rTry of
255 OGFull -> retry
256 OGSuccess x -> return (OGSuccess x)
257 OGEncodeFail -> return OGEncodeFail
258 case r of
259 OGSuccess x -> case ncSockAddr (singleSession con) of
260 HaveDHTKey saddr -> sendSessionPacket (ncAllSessions $ singleSession con) saddr x
261 _ -> return ()
262 OGEncodeFail -> dput XMisc ("FAILURE to Encode Outgoing: " ++ show msg)
263 _ -> return ()
264
265 246
266-- | Retry until: 247-- | Retry until:
267-- 248--
diff --git a/src/Network/Tox/Crypto/Handlers.hs b/src/Network/Tox/Crypto/Handlers.hs
index 50224178..8975e4dc 100644
--- a/src/Network/Tox/Crypto/Handlers.hs
+++ b/src/Network/Tox/Crypto/Handlers.hs
@@ -39,6 +39,7 @@ import SensibleDir
39import System.FilePath 39import System.FilePath
40import System.Environment 40import System.Environment
41import System.Directory 41import System.Directory
42import System.Timeout
42#ifdef THREAD_DEBUG 43#ifdef THREAD_DEBUG
43import Control.Concurrent.Lifted.Instrument 44import Control.Concurrent.Lifted.Instrument
44#else 45#else
@@ -766,8 +767,9 @@ tryAppendQueueOutgoing getExtra outq msg = do
766 mbWire <- nqToWire outq getExtra nextno be pktno msg 767 mbWire <- nqToWire outq getExtra nextno be pktno msg
767 case mbWire of 768 case mbWire of
768 Just (payload,seqno) -> do 769 Just (payload,seqno) -> do
769 PB.grokOutboundPacket (nqPacketBuffer outq) (PacketSent seqno payload) 770 (isFull,_) <- PB.grokOutboundPacket (nqPacketBuffer outq) (PacketSent seqno payload)
770 return $ OGSuccess payload 771 if isFull then return OGFull
772 else return $ OGSuccess payload
771 Nothing -> return OGEncodeFail 773 Nothing -> return OGEncodeFail
772 774
773 775
@@ -1253,12 +1255,16 @@ sendCrypto crypto session updateLocal cm = do
1253 dput XNetCrypto "sendCrypto: enter " 1255 dput XNetCrypto "sendCrypto: enter "
1254 getOutGoingParam <- nqToWireIO outq 1256 getOutGoingParam <- nqToWireIO outq
1255 dput XNetCrypto "sendCrypto: got the io extra stuff" 1257 dput XNetCrypto "sendCrypto: got the io extra stuff"
1256 r <- atomically $ do 1258 ncTime <- atomically $ readTVar (ncTimeOut session)
1259 r0 <- timeout (ncTime*1000) . atomically $ do
1257 result <- tryAppendQueueOutgoing getOutGoingParam outq cm 1260 result <- tryAppendQueueOutgoing getOutGoingParam outq cm
1258 case result of 1261 case result of
1259 OGSuccess x -> updateLocal >> return (Right x) 1262 OGSuccess x -> updateLocal >> return (Right x)
1260 OGFull -> return (Left "Outgoing packet buffer is full") 1263 OGFull -> retry -- return (Left "Outgoing packet buffer is full")
1261 OGEncodeFail -> return (Left "Failed to encode outgoing packet") 1264 OGEncodeFail -> return (Left "Failed to encode outgoing packet")
1265 let r = case r0 of
1266 Nothing -> Left "Outgoing packet buffer is full"
1267 Just x -> x
1262 case ncSockAddr session of 1268 case ncSockAddr session of
1263 HaveDHTKey saddr -> mapM_ (sendSessionPacket (ncAllSessions session) saddr) r 1269 HaveDHTKey saddr -> mapM_ (sendSessionPacket (ncAllSessions session) saddr) r
1264 _ -> return () 1270 _ -> return ()