diff options
author | Joe Crayne <joe@jerkface.net> | 2018-09-09 02:32:20 -0400 |
---|---|---|
committer | Joe Crayne <joe@jerkface.net> | 2018-10-03 06:49:55 -0400 |
commit | fbf9890a6bcd4e6212b5947f908bc34f233b279d (patch) | |
tree | 1ceee1e2dcc2a1bb53c6ca03d0d4986099381630 /ToxManager.hs | |
parent | 037508fe7ed09e3b4f4c00b7778f6c0dc4a3d5f9 (diff) |
Moved resolving duty to Connection manager.
Diffstat (limited to 'ToxManager.hs')
-rw-r--r-- | ToxManager.hs | 24 |
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 | |||
9 | import Announcer | 9 | import Announcer |
10 | import Announcer.Tox | 10 | import Announcer.Tox |
11 | import ClientState | 11 | import ClientState |
12 | import Control.Arrow | ||
12 | import Control.Concurrent.STM | 13 | import Control.Concurrent.STM |
13 | import Control.Monad | 14 | import Control.Monad |
14 | import Crypto.Tox | 15 | import Crypto.Tox |
@@ -57,6 +58,7 @@ import GHC.Conc (labelThread) | |||
57 | #endif | 58 | #endif |
58 | import GHC.Conc (unsafeIOToSTM) | 59 | import GHC.Conc (unsafeIOToSTM) |
59 | import Connection | 60 | import Connection |
61 | import Connection.Tcp (TCPStatus) | ||
60 | 62 | ||
61 | 63 | ||
62 | toxAnnounceSendData :: Tox.Tox JabberClients | 64 | toxAnnounceSendData :: 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 |
96 | toxman ssvar announcer toxbkts tox presence = ToxManager | 98 | toxman 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 | ||
210 | key2jid :: Word32 -> PublicKey -> Text | 224 | key2jid :: Word32 -> PublicKey -> Text |
@@ -231,7 +245,7 @@ initPerClient = do | |||
231 | data ToxToXMPP = ToxToXMPP | 245 | data 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. |
513 | checkSoliciting :: PresenceState -> PublicKey -> PublicKey -> Contact -> IO [NoSpam] | 527 | checkSoliciting :: PresenceState TCPStatus -> PublicKey -> PublicKey -> Contact -> IO [NoSpam] |
514 | checkSoliciting presence me them contact = do | 528 | checkSoliciting 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 | ||
618 | forkAccountWatcher :: TVar (Map.Map Uniq24 AggregateSession) | 632 | forkAccountWatcher :: TVar (Map.Map Uniq24 AggregateSession) |
619 | -> Account JabberClients -> Tox JabberClients -> PresenceState -> Announcer -> IO ThreadId | 633 | -> Account JabberClients -> Tox JabberClients -> PresenceState TCPStatus -> Announcer -> IO ThreadId |
620 | forkAccountWatcher ssvar acc tox st announcer = forkIO $ do | 634 | forkAccountWatcher 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)) |