summaryrefslogtreecommitdiff
path: root/ToxManager.hs
diff options
context:
space:
mode:
Diffstat (limited to 'ToxManager.hs')
-rw-r--r--ToxManager.hs34
1 files changed, 31 insertions, 3 deletions
diff --git a/ToxManager.hs b/ToxManager.hs
index 14b2070c..793a3b8a 100644
--- a/ToxManager.hs
+++ b/ToxManager.hs
@@ -9,16 +9,19 @@ module ToxManager where
9import Announcer 9import Announcer
10import Announcer.Tox 10import Announcer.Tox
11import ClientState 11import ClientState
12import ConfigFiles
12import Control.Arrow 13import Control.Arrow
13import Control.Concurrent.STM 14import Control.Concurrent.STM
14import Control.Monad 15import Control.Monad
15import Crypto.Tox 16import Crypto.Tox
16import qualified Data.ByteArray as BA
17import Data.Bits 17import Data.Bits
18import qualified Data.ByteArray as BA
18import Data.Function 19import Data.Function
19import qualified Data.HashMap.Strict as HashMap 20import qualified Data.HashMap.Strict as HashMap
21import Data.List
20import qualified Data.Map as Map 22import qualified Data.Map as Map
21import Data.Maybe 23import Data.Maybe
24import Data.Ord
22import qualified Data.Set as Set 25import qualified Data.Set as Set
23import qualified Data.Text as T 26import qualified Data.Text as T
24 ;import Data.Text (Text) 27 ;import Data.Text (Text)
@@ -56,9 +59,9 @@ import Control.Concurrent.Lifted.Instrument
56import Control.Concurrent.Lifted 59import Control.Concurrent.Lifted
57import GHC.Conc (labelThread) 60import GHC.Conc (labelThread)
58#endif 61#endif
59import GHC.Conc (unsafeIOToSTM)
60import Connection 62import Connection
61import Connection.Tcp (TCPStatus) 63import Connection.Tcp (TCPStatus)
64import GHC.Conc (unsafeIOToSTM)
62 65
63 66
64toxAnnounceSendData :: Tox.Tox JabberClients 67toxAnnounceSendData :: Tox.Tox JabberClients
@@ -476,7 +479,8 @@ realShakeHands myseckey theirpubkey theirDhtKey allsessions saddr cookie = do
476 479
477 480
478dispatch :: ToxToXMPP -> ContactEvent -> IO () 481dispatch :: ToxToXMPP -> ContactEvent -> IO ()
479dispatch tx (SessionEstablished theirKey) = stopConnecting tx theirKey "established" 482dispatch tx (SessionEstablished theirKey) = do stopConnecting tx theirKey "established"
483 updateRoster tx theirKey
480dispatch tx (SessionTerminated theirKey) = startConnecting tx theirKey "terminated" 484dispatch tx (SessionTerminated theirKey) = startConnecting tx theirKey "terminated"
481dispatch tx (AddrChange theirKey saddr) = gotAddr saddr tx theirKey 485dispatch tx (AddrChange theirKey saddr) = gotAddr saddr tx theirKey
482dispatch tx (PolicyChange theirkey TryingToConnect ) = startConnecting tx theirkey "policy" 486dispatch tx (PolicyChange theirkey TryingToConnect ) = startConnecting tx theirkey "policy"
@@ -521,6 +525,30 @@ akeyConnect announcer me them =
521 packAnnounceKey announcer $ "connect(" ++ (take 8 $ show me) ++ ")" ++ show (key2id them) 525 packAnnounceKey announcer $ "connect(" ++ (take 8 $ show me) ++ ")" ++ show (key2id them)
522 526
523 527
528
529-- | Because Tox does not have a friend-request response, we consider an
530-- established connection to be an implicit two-way subscription.
531updateRoster :: ToxToXMPP -> PublicKey -> IO ()
532updateRoster tx them = do
533 let me = toPublic $ userSecret $ txAccount tx
534 profile = T.pack $ show (key2id me) ++ ".tox"
535 jid = T.pack $ show (key2id them) ++ ".tox"
536 man = manager (txPresence tx) profile
537 addr <- do
538 u <- xor24 <$> hash24 me <*> hash24 them
539 return [ addrToPeerKey . Remote . peerAddress . uniqueAsKey $ u ]
540 mp <- atomically $ Map.lookup profile <$> readTVar (clientsByProfile $ txPresence tx)
541 forM_ mp $ \LocalPresence{networkClients} -> do
542 let css = groupBy ((==) `on` clientUser) -- We treat all clients from a single user as one.
543 $ sortBy (comparing clientUser)
544 $ Map.elems networkClients
545 forM_ css $ \(c:_) -> do
546 let user = clientUser c
547 addToRosterFile man modifyBuddies user profile jid addr
548 addToRosterFile man modifySubscribers user profile jid addr
549 -- Cancel friend-request sending.
550 modifyRosterFile man modifySolicited user profile jid addr False True
551
524-- | Returns a list of nospam values to use for friend requests to send to a 552-- | Returns a list of nospam values to use for friend requests to send to a
525-- remote peer. This list is non-empty only when it is desirable to send 553-- remote peer. This list is non-empty only when it is desirable to send
526-- friend requests. 554-- friend requests.