summaryrefslogtreecommitdiff
path: root/Connection
diff options
context:
space:
mode:
authorJames Crayne <jim.crayne@gmail.com>2018-06-15 20:19:17 +0000
committerJames Crayne <jim.crayne@gmail.com>2018-06-16 02:27:52 +0000
commitd6ed1d376d5e374428a7f9ba23e973213e9efd10 (patch)
tree3138f854368afad831537cc23f71825f736bbbc9 /Connection
parentbc5a84c34ba400f3d319387f34a7259923ca64e6 (diff)
remove accepting-task, and initialize toxMgr field
Diffstat (limited to 'Connection')
-rw-r--r--Connection/Tox.hs23
1 files changed, 6 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