diff options
-rw-r--r-- | Connection/Tox.hs | 31 |
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 | |||
12 | import Control.Concurrent.STM | 12 | import Control.Concurrent.STM |
13 | import Control.Monad | 13 | import Control.Monad |
14 | import Crypto.Tox | 14 | import Crypto.Tox |
15 | import Data.Functor.Identity | ||
16 | import qualified Data.HashMap.Strict as HashMap | 15 | import qualified Data.HashMap.Strict as HashMap |
17 | import qualified Data.Map as Map | 16 | import qualified Data.Map as Map |
17 | import Data.Maybe | ||
18 | import Network.Tox.ContactInfo | 18 | import Network.Tox.ContactInfo |
19 | import Network.Tox.Crypto.Handlers | 19 | import Network.Tox.Crypto.Handlers |
20 | import Network.Tox.DHT.Handlers as DHT | 20 | import Network.Tox.DHT.Handlers as DHT |
21 | import Network.Tox.DHT.Transport as DHT | 21 | import Network.Tox.DHT.Transport as DHT |
22 | import Network.Tox.NodeId | ||
23 | import PingMachine | 22 | import PingMachine |
24 | import Text.Read | 23 | import 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 |