summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrew Cady <d@jerkface.net>2018-06-23 21:14:44 -0400
committerAndrew Cady <d@jerkface.net>2018-06-23 21:14:44 -0400
commitcd18190b8f66b5480dfbafebb52f201094bab233 (patch)
tree8a93737c32806fee71a1bade89d49506482d7538
parent87a1867f3a69a3e00be49130d54d4fff5216692b (diff)
try to avoid bug where NodeInfo rapidly cycles between ipv4 and ipv6 addresses
-rw-r--r--ToxToXMPP.hs36
1 files changed, 22 insertions, 14 deletions
diff --git a/ToxToXMPP.hs b/ToxToXMPP.hs
index 56cc297f..d8b704b7 100644
--- a/ToxToXMPP.hs
+++ b/ToxToXMPP.hs
@@ -242,9 +242,17 @@ gotDhtPubkey pubkey tx theirKey = do
242 observe :: AnnounceKey -> POSIXTime -> NodeInfo -> STM () 242 observe :: AnnounceKey -> POSIXTime -> NodeInfo -> STM ()
243 observe akey time ni@(nodeAddr -> addr) = do 243 observe akey time ni@(nodeAddr -> addr) = do
244 tput XNodeinfoSearch $ show ("observation", akey, time, addr) 244 tput XNodeinfoSearch $ show ("observation", akey, time, addr)
245 scheduleImmediately (txAnnouncer tx) akey $ 245
246 ScheduledItem $ getCookie ni (activeSesh addr) (getContact theirKey (txAccount tx)) 246 contact <- getContact theirKey (txAccount tx)
247 setContactAddr time theirKey addr (txAccount tx) 247 join <$> traverse (readTVar . contactLastSeenAddr) contact >>= \case
248 -- Don't update address if we already have one from the last minute.
249 -- Really we need to be collecting a list of these. :-(
250 Just (t, addr') | addr == addr' && time - t < 60 -> return ()
251 _ -> do
252
253 scheduleImmediately (txAnnouncer tx) akey $
254 ScheduledItem $ getCookie ni (activeSesh addr) (getContact theirKey (txAccount tx))
255 setContactAddr time theirKey addr (txAccount tx)
248 256
249 getCookie 257 getCookie
250 :: NodeInfo 258 :: NodeInfo
@@ -254,15 +262,15 @@ gotDhtPubkey pubkey tx theirKey = do
254 -> AnnounceKey 262 -> AnnounceKey
255 -> POSIXTime 263 -> POSIXTime
256 -> STM (IO ()) 264 -> STM (IO ())
257 getCookie ni isActive getC ann akey now = fix $ \goBack -> do 265 getCookie ni isActive getC ann akey now = getCookieAgain
258 mbContact <- getC
259 case mbContact of
260 Nothing -> return $ return ()
261 Just contact -> do
262 active <- isActive
263 return $ when (not active) (getCookieIO goBack)
264
265 where 266 where
267 getCookieAgain = do
268 mbContact <- getC
269 case mbContact of
270 Nothing -> return $ return ()
271 Just contact -> do
272 active <- isActive
273 return $ when (not active) getCookieIO
266 274
267 callRealShakeHands = realShakeHands (userSecret (txAccount tx)) theirKey (dhtpk pubkey) (toxCryptoSessions tox) (nodeAddr ni) 275 callRealShakeHands = realShakeHands (userSecret (txAccount tx)) theirKey (dhtpk pubkey) (toxCryptoSessions tox) (nodeAddr ni)
268 276
@@ -271,8 +279,8 @@ gotDhtPubkey pubkey tx theirKey = do
271 279
272 cookieMaxAge = 60 * 5 280 cookieMaxAge = 60 * 5
273 281
274 getCookieIO :: STM (IO ()) -> IO () 282 getCookieIO :: IO ()
275 getCookieIO getCookieAgain = do 283 getCookieIO = do
276 cookieRequest crypto client myPublicKey ni >>= \case 284 cookieRequest crypto client myPublicKey ni >>= \case
277 Nothing -> atomically $ reschedule' 5 (const getCookieAgain) 285 Nothing -> atomically $ reschedule' 5 (const getCookieAgain)
278 Just cookie -> do 286 Just cookie -> do
@@ -281,7 +289,7 @@ gotDhtPubkey pubkey tx theirKey = do
281 let shaker :: POSIXTime -> STM (IO ()) 289 let shaker :: POSIXTime -> STM (IO ())
282 shaker now = do 290 shaker now = do
283 if (now > cookieCreationStamp + cookieMaxAge) 291 if (now > cookieCreationStamp + cookieMaxAge)
284 then return (getCookieIO getCookieAgain) 292 then return $ dput XUnused "getCookieIO"
285 else do 293 else do
286 reschedule' 5 shaker 294 reschedule' 5 shaker
287 return . void $ callRealShakeHands cookie 295 return . void $ callRealShakeHands cookie