summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrew Cady <d@jerkface.net>2018-06-22 20:56:46 -0400
committerAndrew Cady <d@jerkface.net>2018-06-22 22:33:27 -0400
commitff7449f50c634bb1d7d135ae0fa21172a9323f6c (patch)
treeb29bd647616ab3449fcfc22cd502201a1b3283f4
parent9d8a4436a2d894030a51bba2b773901ffdc4788d (diff)
active nc sessions should be looked up by sockaddr, not key
-rw-r--r--ToxToXMPP.hs26
1 files changed, 12 insertions, 14 deletions
diff --git a/ToxToXMPP.hs b/ToxToXMPP.hs
index b004083f..8d28507a 100644
--- a/ToxToXMPP.hs
+++ b/ToxToXMPP.hs
@@ -1,3 +1,4 @@
1{-# LANGUAGE ViewPatterns #-}
1{-# LANGUAGE CPP #-} 2{-# LANGUAGE CPP #-}
2{-# LANGUAGE LambdaCase #-} 3{-# LANGUAGE LambdaCase #-}
3{-# LANGUAGE NamedFieldPuns #-} 4{-# LANGUAGE NamedFieldPuns #-}
@@ -166,15 +167,12 @@ gotDhtPubkey pubkey tx theirKey = do
166 scheduleSearch (txAnnouncer tx) akey meth pubkey 167 scheduleSearch (txAnnouncer tx) akey meth pubkey
167 tox :: Tox JabberClients 168 tox :: Tox JabberClients
168 tox = txTox tx 169 tox = txTox tx
169 byKey :: TVar (Map.Map PublicKey [Tox.NetCryptoSession]) 170 byAddr :: TVar (Map.Map SockAddr Tox.NetCryptoSession)
170 byKey = Tox.netCryptoSessionsByKey $ toxCryptoSessions tox 171 byAddr = Tox.netCryptoSessions (toxCryptoSessions tox)
171 chillSesh :: STM (Maybe (Status Tox.ToxProgress)) 172 chillSesh :: SockAddr -> STM (Maybe (Status Tox.ToxProgress))
172 chillSesh = do 173 chillSesh addr = traverse readTVar =<< fmap Tox.ncState . Map.lookup addr <$> readTVar byAddr
173 x <- (fmap.fmap) Tox.ncState . Map.lookup theirKey <$> readTVar byKey 174 activeSesh :: SockAddr -> STM Bool
174 y <- (traverse.traverse) readTVar x 175 activeSesh a = chillSesh a >>= return . \case
175 return $ join $ listToMaybe <$> y
176 activeSesh :: STM Bool
177 activeSesh = chillSesh >>= return . \case
178 Just Established -> True 176 Just Established -> True
179 _ -> False 177 _ -> False
180 target = key2id $ dhtpk pubkey 178 target = key2id $ dhtpk pubkey
@@ -200,11 +198,11 @@ gotDhtPubkey pubkey tx theirKey = do
200 tput XNodeinfoSearch $ show ("rumor", akey, time, addr, ni) 198 tput XNodeinfoSearch $ show ("rumor", akey, time, addr, ni)
201 199
202 observe :: AnnounceKey -> POSIXTime -> NodeInfo -> STM () 200 observe :: AnnounceKey -> POSIXTime -> NodeInfo -> STM ()
203 observe akey time ni = do 201 observe akey time (nodeAddr -> addr) = do
204 tput XNodeinfoSearch $ show ("observation", akey, time, ni) 202 tput XNodeinfoSearch $ show ("observation", akey, time, addr)
205 scheduleImmediately (txAnnouncer tx) akey $ 203 scheduleImmediately (txAnnouncer tx) akey $
206 ScheduledItem $ shakeHands activeSesh (getContact theirKey (txAccount tx)) 204 ScheduledItem $ shakeHands (activeSesh addr) (getContact theirKey (txAccount tx))
207 setContactAddr time theirKey (nodeAddr ni) (txAccount tx) 205 setContactAddr time theirKey addr (txAccount tx)
208 206
209shakeHands :: STM Bool -> STM (Maybe Contact) -> Announcer -> AnnounceKey -> POSIXTime -> STM (IO ()) 207shakeHands :: STM Bool -> STM (Maybe Contact) -> Announcer -> AnnounceKey -> POSIXTime -> STM (IO ())
210shakeHands isActive getC ann akey now = do 208shakeHands isActive getC ann akey now = do
@@ -214,7 +212,7 @@ shakeHands isActive getC ann akey now = do
214 Just contact -> do 212 Just contact -> do
215 active <- isActive 213 active <- isActive
216 if (not active) then do 214 if (not active) then do
217 scheduleAbs ann akey (ScheduledItem $ shakeHands isActive getC) (now + 5) 215 scheduleRel ann akey (ScheduledItem $ shakeHands isActive getC) 5
218 return $ shakeHandsIO contact 216 return $ shakeHandsIO contact
219 else 217 else
220 return $ return () 218 return $ return ()