diff options
author | Andrew Cady <d@jerkface.net> | 2018-06-22 14:45:49 -0400 |
---|---|---|
committer | Andrew Cady <d@jerkface.net> | 2018-06-22 17:41:03 -0400 |
commit | f955aa71a7e57f166300ea02436d1284fc5d1480 (patch) | |
tree | 806c1447e022cddbb522505b96c0212e3464f4b9 /ToxToXMPP.hs | |
parent | 4869629a14a440e3423033a11e11e4f2434a1660 (diff) |
stub out the handshake announcer
Diffstat (limited to 'ToxToXMPP.hs')
-rw-r--r-- | ToxToXMPP.hs | 30 |
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 | ||
219 | shakeHands :: STM Bool -> STM (Maybe Contact) -> Announcer -> AnnounceKey -> POSIXTime -> STM (IO ()) | ||
220 | shakeHands 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 | |||
232 | shakeHandsIO :: Contact -> IO () | ||
233 | shakeHandsIO _ = return () | ||
234 | |||
207 | dispatch :: ToxToXMPP -> ContactEvent -> IO () | 235 | dispatch :: ToxToXMPP -> ContactEvent -> IO () |
208 | dispatch tx (SessionEstablished theirKey) = stopConnecting tx theirKey | 236 | dispatch tx (SessionEstablished theirKey) = stopConnecting tx theirKey |
209 | dispatch tx (SessionTerminated theirKey) = startConnecting tx theirKey | 237 | dispatch tx (SessionTerminated theirKey) = startConnecting tx theirKey |