summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Connection/Tox.hs23
-rw-r--r--src/Network/Tox.hs1
-rw-r--r--src/Network/Tox/Crypto/Handlers.hs1
3 files changed, 8 insertions, 17 deletions
diff --git a/Connection/Tox.hs b/Connection/Tox.hs
index 08a930bf..1fe07f82 100644
--- a/Connection/Tox.hs
+++ b/Connection/Tox.hs
@@ -75,8 +75,7 @@ launch lbl st f = do
75 75
76 76
77data SessionTasks = SessionTasks 77data SessionTasks = SessionTasks
78 { accepting :: StatefulTask (G.Status ToxProgress) 78 { persuing :: StatefulTask (G.Status ToxProgress)
79 , persuing :: StatefulTask (G.Status ToxProgress)
80 , refreshing :: StatefulTask (G.Status ToxProgress) 79 , refreshing :: StatefulTask (G.Status ToxProgress)
81 } 80 }
82 81
@@ -96,10 +95,9 @@ sessionStatus st = G.Connection
96 95
97combinedStatus :: SessionTasks -> STM (G.Status ToxProgress) 96combinedStatus :: SessionTasks -> STM (G.Status ToxProgress)
98combinedStatus tasks = do 97combinedStatus tasks = do
99 a <- readTVar (taskState $ accepting tasks)
100 p <- readTVar (taskState $ persuing tasks) 98 p <- readTVar (taskState $ persuing tasks)
101 r <- readTVar (taskState $ refreshing tasks) 99 r <- readTVar (taskState $ refreshing tasks)
102 return $ maximum [a,p,r] 100 return $ maximum [p,r]
103 101
104lookupForPolicyChange :: TVar (Map.Map Key SessionState) 102lookupForPolicyChange :: TVar (Map.Map Key SessionState)
105 -> Key -> Policy -> IO (Maybe SessionState) 103 -> Key -> Policy -> IO (Maybe SessionState)
@@ -145,14 +143,6 @@ setToxPolicy params conmap k policy = case policy of
145 forM_ mst $ \st -> do 143 forM_ mst $ \st -> do
146 let getPolicy = readTVar $ connPolicy st 144 let getPolicy = readTVar $ connPolicy st
147 tasks <- atomically $ readTVar (sessionTasks st) 145 tasks <- atomically $ readTVar (sessionTasks st)
148 --TODO This check to determine whether to launch the accepting thread
149 --is probably racey.
150 astat <- threadStatus (taskThread $ accepting tasks)
151 accepting <- if astat /= ThreadRunning
152 then launch ("accept:"++show k)
153 (G.InProgress $ toEnum 0)
154 $ acceptContact getPolicy accept_methods
155 else return $ accepting tasks
156 persuing <- launch ("persue:"++show k) 146 persuing <- launch ("persue:"++show k)
157 (G.InProgress $ toEnum 0) 147 (G.InProgress $ toEnum 0)
158 $ persueContact getPolicy _get_status persue_methods 148 $ persueContact getPolicy _get_status persue_methods
@@ -160,7 +150,7 @@ setToxPolicy params conmap k policy = case policy of
160 (G.InProgress $ toEnum 0) 150 (G.InProgress $ toEnum 0)
161 $ freshenContact getPolicy _get_status freshen_methods 151 $ freshenContact getPolicy _get_status freshen_methods
162 atomically $ do 152 atomically $ do
163 writeTVar (sessionTasks st) $ SessionTasks accepting persuing refreshing 153 writeTVar (sessionTasks st) $ SessionTasks persuing refreshing
164 let routing = dhtRouting params 154 let routing = dhtRouting params
165 Key _ nid = k 155 Key _ nid = k
166 registerNodeCallback routing $ NodeInfoCallback 156 registerNodeCallback routing $ NodeInfoCallback
@@ -183,12 +173,11 @@ setToxPolicy params conmap k policy = case policy of
183 unregisterNodeCallback callbackId routing nid 173 unregisterNodeCallback callbackId routing nid
184 atomically $ do 174 atomically $ do
185 tasks <- readTVar (sessionTasks st) 175 tasks <- readTVar (sessionTasks st)
186 a <- readTVar $ taskState (accepting tasks)
187 p <- readTVar $ taskState (persuing tasks) 176 p <- readTVar $ taskState (persuing tasks)
188 r <- readTVar $ taskState (refreshing tasks) 177 r <- readTVar $ taskState (refreshing tasks)
189 case (a,p,r) of 178 case (p,r) of
190 (G.Dormant,G.Dormant,G.Dormant) -> return () 179 (G.Dormant,G.Dormant) -> return ()
191 _ -> retry 180 _ -> retry
192 OpenToConnect -> do -- passively accept connections if they initiate. 181 OpenToConnect -> do -- passively accept connections if they initiate.
193 mst <- lookupForPolicyChange conmap k policy 182 mst <- lookupForPolicyChange conmap k policy
194 forM_ mst $ \st -> do 183 forM_ mst $ \st -> do
diff --git a/src/Network/Tox.hs b/src/Network/Tox.hs
index 3324c934..4d244199 100644
--- a/src/Network/Tox.hs
+++ b/src/Network/Tox.hs
@@ -492,6 +492,7 @@ newTox keydb addr mbSessionsState suppliedDHTKey = do
492 , toxOnionRoutes = orouter 492 , toxOnionRoutes = orouter
493 , toxContactInfo = roster 493 , toxContactInfo = roster
494 , toxAnnounceToLan = announceToLan sock (key2id $ transportPublic crypto) 494 , toxAnnounceToLan = announceToLan sock (key2id $ transportPublic crypto)
495 , toxMgr = mgr
495 } 496 }
496 497
497onionTimeout :: Tox -> DHT.TransactionId -> Onion.OnionDestination RouteId -> STM (Onion.OnionDestination RouteId, Int) 498onionTimeout :: Tox -> DHT.TransactionId -> Onion.OnionDestination RouteId -> STM (Onion.OnionDestination RouteId, Int)
diff --git a/src/Network/Tox/Crypto/Handlers.hs b/src/Network/Tox/Crypto/Handlers.hs
index 61b2ab3c..1acc333e 100644
--- a/src/Network/Tox/Crypto/Handlers.hs
+++ b/src/Network/Tox/Crypto/Handlers.hs
@@ -57,6 +57,7 @@ import Text.Printf
57import Data.Bool 57import Data.Bool
58import Connection (Status(..), Policy(..)) 58import Connection (Status(..), Policy(..))
59import Connection.Tox.Threads (ToxProgress(..)) 59import Connection.Tox.Threads (ToxProgress(..))
60import Network.Tox.ContactInfo
60 61
61type LookupPolicyFunction = Key -> STM Policy 62type LookupPolicyFunction = Key -> STM Policy
62 63