summaryrefslogtreecommitdiff
path: root/ToxManager.hs
diff options
context:
space:
mode:
authorJoe Crayne <joe@jerkface.net>2018-09-09 02:32:20 -0400
committerJoe Crayne <joe@jerkface.net>2018-10-03 06:49:55 -0400
commitfbf9890a6bcd4e6212b5947f908bc34f233b279d (patch)
tree1ceee1e2dcc2a1bb53c6ca03d0d4986099381630 /ToxManager.hs
parent037508fe7ed09e3b4f4c00b7778f6c0dc4a3d5f9 (diff)
Moved resolving duty to Connection manager.
Diffstat (limited to 'ToxManager.hs')
-rw-r--r--ToxManager.hs24
1 files changed, 19 insertions, 5 deletions
diff --git a/ToxManager.hs b/ToxManager.hs
index 78049010..2aeff620 100644
--- a/ToxManager.hs
+++ b/ToxManager.hs
@@ -9,6 +9,7 @@ module ToxManager where
9import Announcer 9import Announcer
10import Announcer.Tox 10import Announcer.Tox
11import ClientState 11import ClientState
12import Control.Arrow
12import Control.Concurrent.STM 13import Control.Concurrent.STM
13import Control.Monad 14import Control.Monad
14import Crypto.Tox 15import Crypto.Tox
@@ -57,6 +58,7 @@ import GHC.Conc (labelThread)
57#endif 58#endif
58import GHC.Conc (unsafeIOToSTM) 59import GHC.Conc (unsafeIOToSTM)
59import Connection 60import Connection
61import Connection.Tcp (TCPStatus)
60 62
61 63
62toxAnnounceSendData :: Tox.Tox JabberClients 64toxAnnounceSendData :: Tox.Tox JabberClients
@@ -91,7 +93,7 @@ toxman :: TVar (Map.Map Uniq24 AggregateSession)
91 -> Announcer 93 -> Announcer
92 -> [(String,TVar (BucketList Tox.NodeInfo))] 94 -> [(String,TVar (BucketList Tox.NodeInfo))]
93 -> Tox.Tox JabberClients 95 -> Tox.Tox JabberClients
94 -> PresenceState 96 -> PresenceState TCPStatus
95 -> ToxManager ClientAddress 97 -> ToxManager ClientAddress
96toxman ssvar announcer toxbkts tox presence = ToxManager 98toxman ssvar announcer toxbkts tox presence = ToxManager
97 { activateAccount = \k pubname seckey -> do 99 { activateAccount = \k pubname seckey -> do
@@ -197,6 +199,18 @@ toxman ssvar announcer toxbkts tox presence = ToxManager
197 , stringToKey = stringToKey_ 199 , stringToKey = stringToKey_
198 , showProgress = show 200 , showProgress = show
199 , showKey = show 201 , showKey = show
202 , resolvePeer = \(ToxContact me them) -> do
203 let mek = id2key me
204 themk = id2key them
205 u <- xor24 <$> hash24 mek <*> hash24 themk
206 return [uniqueAsKey u]
207 , reverseAddress = \paddr -> atomically $ do
208 -- This will only succeed if there is an established session.
209 -- TODO: Is that sufficient?
210 ss <- readTVar ssvar
211 m <- forM (keyAsUnique paddr >>= (`Map.lookup` ss)) $ \c -> do
212 fmap (uncurry ToxContact . (key2id *** key2id)) <$> compatibleKeys c
213 return $ maybeToList (join m)
200 } 214 }
201 , resolveToxPeer = \me them -> do 215 , resolveToxPeer = \me them -> do
202 let m = do meid <- readMaybe $ T.unpack me 216 let m = do meid <- readMaybe $ T.unpack me
@@ -204,7 +218,7 @@ toxman ssvar announcer toxbkts tox presence = ToxManager
204 return (id2key meid, id2key themid) 218 return (id2key meid, id2key themid)
205 forM m $ \(me,them) -> do 219 forM m $ \(me,them) -> do
206 u <- xor24 <$> hash24 me <*> hash24 them 220 u <- xor24 <$> hash24 me <*> hash24 them
207 return $ addrToPeerKey $ Remote $ uniqueAsKey u 221 return $ addrToPeerKey $ Remote $ peerAddress $ uniqueAsKey u
208 } 222 }
209 223
210key2jid :: Word32 -> PublicKey -> Text 224key2jid :: Word32 -> PublicKey -> Text
@@ -231,7 +245,7 @@ initPerClient = do
231data ToxToXMPP = ToxToXMPP 245data ToxToXMPP = ToxToXMPP
232 { txAnnouncer :: Announcer 246 { txAnnouncer :: Announcer
233 , txAccount :: Account JabberClients 247 , txAccount :: Account JabberClients
234 , txPresence :: PresenceState 248 , txPresence :: PresenceState TCPStatus
235 , txTox :: Tox JabberClients 249 , txTox :: Tox JabberClients
236 , txSessions :: TVar (Map.Map Uniq24 AggregateSession) 250 , txSessions :: TVar (Map.Map Uniq24 AggregateSession)
237 } 251 }
@@ -510,7 +524,7 @@ akeyConnect announcer me them =
510-- | Returns a list of nospam values to use for friend requests to send to a 524-- | Returns a list of nospam values to use for friend requests to send to a
511-- remote peer. This list is non-empty only when it is desirable to send 525-- remote peer. This list is non-empty only when it is desirable to send
512-- friend requests. 526-- friend requests.
513checkSoliciting :: PresenceState -> PublicKey -> PublicKey -> Contact -> IO [NoSpam] 527checkSoliciting :: PresenceState TCPStatus -> PublicKey -> PublicKey -> Contact -> IO [NoSpam]
514checkSoliciting presence me them contact = do 528checkSoliciting presence me them contact = do
515 let theirhost = T.pack $ show (key2id them) ++ ".tox" 529 let theirhost = T.pack $ show (key2id them) ++ ".tox"
516 myhost = T.pack $ show (key2id me) ++ ".tox" 530 myhost = T.pack $ show (key2id me) ++ ".tox"
@@ -616,7 +630,7 @@ stopConnecting ToxToXMPP{txAnnouncer=announcer,txAccount=acnt} them reason = do
616 cancel announcer akeyD 630 cancel announcer akeyD
617 631
618forkAccountWatcher :: TVar (Map.Map Uniq24 AggregateSession) 632forkAccountWatcher :: TVar (Map.Map Uniq24 AggregateSession)
619 -> Account JabberClients -> Tox JabberClients -> PresenceState -> Announcer -> IO ThreadId 633 -> Account JabberClients -> Tox JabberClients -> PresenceState TCPStatus -> Announcer -> IO ThreadId
620forkAccountWatcher ssvar acc tox st announcer = forkIO $ do 634forkAccountWatcher ssvar acc tox st announcer = forkIO $ do
621 myThreadId >>= flip labelThread ("online:" 635 myThreadId >>= flip labelThread ("online:"
622 ++ show (key2id $ toPublic $ userSecret acc)) 636 ++ show (key2id $ toPublic $ userSecret acc))