summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Connection/Tox.hs31
1 files changed, 17 insertions, 14 deletions
diff --git a/Connection/Tox.hs b/Connection/Tox.hs
index 436e7599..2b39ef1c 100644
--- a/Connection/Tox.hs
+++ b/Connection/Tox.hs
@@ -12,14 +12,13 @@ import Connection.Tox.Threads
12import Control.Concurrent.STM 12import Control.Concurrent.STM
13import Control.Monad 13import Control.Monad
14import Crypto.Tox 14import Crypto.Tox
15import Data.Functor.Identity
16import qualified Data.HashMap.Strict as HashMap 15import qualified Data.HashMap.Strict as HashMap
17import qualified Data.Map as Map 16import qualified Data.Map as Map
17import Data.Maybe
18import Network.Tox.ContactInfo 18import Network.Tox.ContactInfo
19import Network.Tox.Crypto.Handlers 19import Network.Tox.Crypto.Handlers
20import Network.Tox.DHT.Handlers as DHT 20import Network.Tox.DHT.Handlers as DHT
21import Network.Tox.DHT.Transport as DHT 21import Network.Tox.DHT.Transport as DHT
22import Network.Tox.NodeId
23import PingMachine 22import PingMachine
24import Text.Read 23import Text.Read
25#ifdef THREAD_DEBUG 24#ifdef THREAD_DEBUG
@@ -139,12 +138,7 @@ setToxPolicy params conmap k@(Key me them) policy = case policy of
139 mst <- lookupForPolicyChange conmap k policy 138 mst <- lookupForPolicyChange conmap k policy
140 r <- atomically $ lookupContact k (roster params) 139 r <- atomically $ lookupContact k (roster params)
141 forM_ r $ \(sec,c) -> do 140 forM_ r $ \(sec,c) -> do
142 let accept_methods = AcceptContactMethods 141 let persue_methods = PersueContactMethods
143 { getHandshake = retry -- :: STM (Handshake Identity)
144 , handshakeIsSuitable = (\_ -> return False) -- :: Handshake Identity -> STM Bool
145 , transitionToState = (\_ -> return ()) :: G.Status ToxProgress -> STM ()
146 }
147 persue_methods = PersueContactMethods
148 { allsessions = sessions params 142 { allsessions = sessions params
149 , myseckey = sec 143 , myseckey = sec
150 , theirpubkey = id2key them 144 , theirpubkey = id2key them
@@ -156,21 +150,26 @@ setToxPolicy params conmap k@(Key me them) policy = case policy of
156 freshen_methods = FreshenContactMethods 150 freshen_methods = FreshenContactMethods
157 { dhtkeyInterval = _todo :: Int 151 { dhtkeyInterval = _todo :: Int
158 , sockAddrInterval = _todo :: Int 152 , sockAddrInterval = _todo :: Int
159 , nodeSch = _todo :: NodeSearch 153 , nodeSch = nodeSearch (dhtClient params)
154 (nodesOfInterest $ dhtRouting params)
160 , getDHTKey = retry :: STM (Maybe NodeId) 155 , getDHTKey = retry :: STM (Maybe NodeId)
161 , getSockAddr = retry -- :: STM (Maybe SockAddr) 156 , getSockAddr = retry -- :: STM (Maybe SockAddr)
162 , getBuckets = retry -- :: STM (BucketList NodeInfo) 157 , getBuckets = retry -- :: STM (BucketList NodeInfo)
163 } 158 }
164 get_status = readTVar (ncState _todo) 159 get_status = do
160 sbk <- readTVar $ netCryptoSessionsByKey (sessions params)
161 fmap (fromMaybe G.Dormant) $ forM (Map.lookup (id2key them) sbk) $ \ss -> do
162 stats <- mapM (readTVar . ncState) ss
163 return $ maximum stats
165 forM_ mst $ \st -> do 164 forM_ mst $ \st -> do
166 let getPolicy = readTVar $ connPolicy st 165 let getPolicy = readTVar $ connPolicy st
167 tasks <- atomically $ readTVar (sessionTasks st) 166 tasks <- atomically $ readTVar (sessionTasks st)
168 persuing <- launch ("persue:"++show k) 167 persuing <- launch ("persue:"++show k)
169 (G.InProgress $ toEnum 0) 168 (G.InProgress $ toEnum 0)
170 $ persueContact getPolicy _get_status persue_methods 169 $ persueContact getPolicy get_status persue_methods
171 refreshing <- launch ("refresh:"++show k) 170 refreshing <- launch ("refresh:"++show k)
172 (G.InProgress $ toEnum 0) 171 (G.InProgress $ toEnum 0)
173 $ freshenContact getPolicy _get_status freshen_methods 172 $ freshenContact getPolicy get_status freshen_methods
174 atomically $ do 173 atomically $ do
175 writeTVar (sessionTasks st) $ SessionTasks persuing refreshing 174 writeTVar (sessionTasks st) $ SessionTasks persuing refreshing
176 let routing = dhtRouting params 175 let routing = dhtRouting params
@@ -178,8 +177,12 @@ setToxPolicy params conmap k@(Key me them) policy = case policy of
178 registerNodeCallback routing $ NodeInfoCallback 177 registerNodeCallback routing $ NodeInfoCallback
179 { interestingNodeId = nid 178 { interestingNodeId = nid
180 , listenerId = callbackId 179 , listenerId = callbackId
181 , observedAddress = \ni -> return () -- TODO 180 , observedAddress = \ni -> writeTVar (contactLastSeenAddr c) (Just $ nodeAddr ni)
182 , rumoredAddress = \saddr ni -> return () -- TODO 181 , rumoredAddress = \saddr ni -> do
182 m <- readTVar (contactLastSeenAddr c)
183 -- TODO remember information source and handle multiple rumors.
184 case m of Just _ -> return ()
185 Nothing -> writeTVar (contactLastSeenAddr c) (Just $ nodeAddr ni)
183 } 186 }
184 return () 187 return ()
185 RefusingToConnect -> do -- disconnect or cancel any pending connection 188 RefusingToConnect -> do -- disconnect or cancel any pending connection