summaryrefslogtreecommitdiff
path: root/ToxToXMPP.hs
diff options
context:
space:
mode:
authorAndrew Cady <d@jerkface.net>2018-06-22 14:45:49 -0400
committerAndrew Cady <d@jerkface.net>2018-06-22 17:41:03 -0400
commitf955aa71a7e57f166300ea02436d1284fc5d1480 (patch)
tree806c1447e022cddbb522505b96c0212e3464f4b9 /ToxToXMPP.hs
parent4869629a14a440e3423033a11e11e4f2434a1660 (diff)
stub out the handshake announcer
Diffstat (limited to 'ToxToXMPP.hs')
-rw-r--r--ToxToXMPP.hs30
1 files changed, 29 insertions, 1 deletions
diff --git a/ToxToXMPP.hs b/ToxToXMPP.hs
index 2659f56e..e2cefc9d 100644
--- a/ToxToXMPP.hs
+++ b/ToxToXMPP.hs
@@ -176,6 +176,17 @@ gotDhtPubkey pubkey tx theirKey = do
176 scheduleSearch (txAnnouncer tx) akey meth pubkey 176 scheduleSearch (txAnnouncer tx) akey meth pubkey
177 tox :: Tox JabberClients 177 tox :: Tox JabberClients
178 tox = txTox tx 178 tox = txTox tx
179 byKey :: TVar (Map.Map PublicKey [Tox.NetCryptoSession])
180 byKey = Tox.netCryptoSessionsByKey $ toxCryptoSessions tox
181 chillSesh :: STM (Maybe (Status Tox.ToxProgress))
182 chillSesh = do
183 x <- (fmap.fmap) Tox.ncState . Map.lookup theirKey <$> readTVar byKey
184 y <- (traverse.traverse) readTVar x
185 return $ join $ listToMaybe <$> y
186 activeSesh :: STM Bool
187 activeSesh = chillSesh >>= return . \case
188 Just Established -> True
189 _ -> False
179 target = key2id $ dhtpk pubkey 190 target = key2id $ dhtpk pubkey
180 meth :: SearchMethod Tox.DHTPublicKey 191 meth :: SearchMethod Tox.DHTPublicKey
181 meth = 192 meth =
@@ -201,9 +212,26 @@ gotDhtPubkey pubkey tx theirKey = do
201 observe :: AnnounceKey -> POSIXTime -> NodeInfo -> STM () 212 observe :: AnnounceKey -> POSIXTime -> NodeInfo -> STM ()
202 observe akey time ni = do 213 observe akey time ni = do
203 tput XNodeinfoSearch $ show ("observation", akey, time, ni) 214 tput XNodeinfoSearch $ show ("observation", akey, time, ni)
204 unschedule (txAnnouncer tx) akey -- todo: schedule the handshake here 215 scheduleImmediately (txAnnouncer tx) akey $
216 ScheduledItem $ shakeHands activeSesh (getContact theirKey (txAccount tx))
205 setContactAddr time theirKey (nodeAddr ni) (txAccount tx) 217 setContactAddr time theirKey (nodeAddr ni) (txAccount tx)
206 218
219shakeHands :: STM Bool -> STM (Maybe Contact) -> Announcer -> AnnounceKey -> POSIXTime -> STM (IO ())
220shakeHands isActive getC ann akey now = do
221 mbContact <- getC
222 case mbContact of
223 Nothing -> return $ return ()
224 Just contact -> do
225 active <- isActive
226 if (not active) then do
227 scheduleAbs ann akey (ScheduledItem $ shakeHands isActive getC) (now + 5)
228 return $ shakeHandsIO contact
229 else
230 return $ return ()
231
232shakeHandsIO :: Contact -> IO ()
233shakeHandsIO _ = return ()
234
207dispatch :: ToxToXMPP -> ContactEvent -> IO () 235dispatch :: ToxToXMPP -> ContactEvent -> IO ()
208dispatch tx (SessionEstablished theirKey) = stopConnecting tx theirKey 236dispatch tx (SessionEstablished theirKey) = stopConnecting tx theirKey
209dispatch tx (SessionTerminated theirKey) = startConnecting tx theirKey 237dispatch tx (SessionTerminated theirKey) = startConnecting tx theirKey