summaryrefslogtreecommitdiff
path: root/ToxToXMPP.hs
diff options
context:
space:
mode:
Diffstat (limited to 'ToxToXMPP.hs')
-rw-r--r--ToxToXMPP.hs28
1 files changed, 19 insertions, 9 deletions
diff --git a/ToxToXMPP.hs b/ToxToXMPP.hs
index 9391a232..5495f5ad 100644
--- a/ToxToXMPP.hs
+++ b/ToxToXMPP.hs
@@ -100,11 +100,21 @@ key2jid nospam key = T.pack $ show $ NoSpamId nsp key
100 nlo = fromIntegral (0x0FFFF .&. nospam) :: Word16 100 nlo = fromIntegral (0x0FFFF .&. nospam) :: Word16
101 nhi = fromIntegral (0x0FFFF .&. (nospam `shiftR` 16)) :: Word16 101 nhi = fromIntegral (0x0FFFF .&. (nospam `shiftR` 16)) :: Word16
102 102
103type JabberClients = Map.Map ConnectionKey PerClient
104
105data PerClient = PerClient
106 {
107 }
108
109initPerClient :: STM PerClient
110initPerClient = do
111 return PerClient {}
112
103data ToxToXMPP = ToxToXMPP 113data ToxToXMPP = ToxToXMPP
104 { txAnnouncer :: Announcer 114 { txAnnouncer :: Announcer
105 , txAccount :: Account 115 , txAccount :: Account JabberClients
106 , txPresence :: PresenceState 116 , txPresence :: PresenceState
107 , txTox :: Tox 117 , txTox :: Tox JabberClients
108 } 118 }
109 119
110dispatch :: ToxToXMPP -> ContactEvent -> IO () 120dispatch :: ToxToXMPP -> ContactEvent -> IO ()
@@ -119,8 +129,8 @@ dispatch tx (OnionRouted theirkey (OnionFriendRequest fr) ) = do
119 , txAccount = acnt 129 , txAccount = acnt
120 , txPresence = st } = tx 130 , txPresence = st } = tx
121 k2c <- atomically $ do 131 k2c <- atomically $ do
122 refs <- readTVar (clientRefs acnt) 132 refs <- readTVar (accountExtra acnt)
123 k2c <- Map.filterWithKey (\k _ -> k `Set.member` refs) <$> readTVar (keyToChan st) 133 k2c <- Map.filterWithKey (\k _ -> isJust $ k `Map.lookup` refs) <$> readTVar (keyToChan st)
124 clients <- readTVar (clients st) 134 clients <- readTVar (clients st)
125 return $ Map.intersectionWith (,) k2c clients 135 return $ Map.intersectionWith (,) k2c clients
126 -- TODO: Below we're using a hard coded default as their jabber user id. 136 -- TODO: Below we're using a hard coded default as their jabber user id.
@@ -204,7 +214,7 @@ stopConnecting ToxToXMPP{txAnnouncer=announcer,txAccount=acnt} them = do
204 akey <- akeyDHTKeyShare announcer me them 214 akey <- akeyDHTKeyShare announcer me them
205 cancel announcer akey 215 cancel announcer akey
206 216
207forkAccountWatcher :: Account -> Tox -> PresenceState -> Announcer -> IO ThreadId 217forkAccountWatcher :: Account JabberClients -> Tox JabberClients -> PresenceState -> Announcer -> IO ThreadId
208forkAccountWatcher acc tox st announcer = forkIO $ do 218forkAccountWatcher acc tox st announcer = forkIO $ do
209 myThreadId >>= flip labelThread ("tox-xmpp:" 219 myThreadId >>= flip labelThread ("tox-xmpp:"
210 ++ show (key2id $ toPublic $ userSecret acc)) 220 ++ show (key2id $ toPublic $ userSecret acc))
@@ -220,13 +230,13 @@ forkAccountWatcher acc tox st announcer = forkIO $ do
220 forM_ (HashMap.toList cs) $ \(them,c) -> do 230 forM_ (HashMap.toList cs) $ \(them,c) -> do
221 startConnecting0 tx (id2key them) c 231 startConnecting0 tx (id2key them) c
222 232
223 -- Loop endlessly until clientRefs is null. 233 -- Loop endlessly until accountExtra is null.
224 fix $ \loop -> do 234 fix $ \loop -> do
225 mev <- atomically $ 235 mev <- atomically $
226 (Just <$> readTChan chan) 236 (Just <$> readTChan chan)
227 `orElse` do 237 `orElse` do
228 refs <- readTVar $ clientRefs acc 238 refs <- readTVar $ accountExtra acc
229 check $ Set.null refs 239 check $ Map.null refs
230 return Nothing 240 return Nothing
231 241
232 forM_ mev $ \ev -> dispatch tx ev >> loop 242 forM_ mev $ \ev -> dispatch tx ev >> loop
@@ -236,7 +246,7 @@ forkAccountWatcher acc tox st announcer = forkIO $ do
236 stopConnecting tx (id2key them) 246 stopConnecting tx (id2key them)
237 247
238 248
239toxQSearch :: Tox.Tox -> Search Tox.NodeId (IP, PortNumber) Nonce32 Tox.NodeInfo Tox.Rendezvous 249toxQSearch :: Tox extra -> Search Tox.NodeId (IP, PortNumber) Nonce32 Tox.NodeInfo Tox.Rendezvous
240toxQSearch tox = Tox.toxidSearch (Tox.onionTimeout tox) (Tox.toxCryptoKeys tox) (Tox.toxOnion tox) 250toxQSearch tox = Tox.toxidSearch (Tox.onionTimeout tox) (Tox.toxCryptoKeys tox) (Tox.toxOnion tox)
241 251
242toxAnnounceInterval :: POSIXTime 252toxAnnounceInterval :: POSIXTime