summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Presence/Presence.hs13
-rw-r--r--ToxManager.hs34
-rw-r--r--examples/dhtd.hs4
3 files changed, 40 insertions, 11 deletions
diff --git a/Presence/Presence.hs b/Presence/Presence.hs
index c3e60239..2086133d 100644
--- a/Presence/Presence.hs
+++ b/Presence/Presence.hs
@@ -1006,7 +1006,7 @@ addToRosterFile ::
1006 -> Text -- profile 1006 -> Text -- profile
1007 -> Text -> [PeerAddress] -> t1 1007 -> Text -> [PeerAddress] -> t1
1008addToRosterFile man doit whose profile to addrs = 1008addToRosterFile man doit whose profile to addrs =
1009 modifyRosterFile man doit whose profile to addrs True 1009 modifyRosterFile man doit whose profile to addrs True False
1010 1010
1011removeFromRosterFile :: 1011removeFromRosterFile ::
1012 Connection.Manager s Text 1012 Connection.Manager s Text
@@ -1019,7 +1019,7 @@ removeFromRosterFile ::
1019 -> Text -- profile 1019 -> Text -- profile
1020 -> Text -> [PeerAddress] -> t1 1020 -> Text -> [PeerAddress] -> t1
1021removeFromRosterFile man doit whose profile to addrs = 1021removeFromRosterFile man doit whose profile to addrs =
1022 modifyRosterFile man doit whose profile to addrs False 1022 modifyRosterFile man doit whose profile to addrs False False
1023 1023
1024-- | Sanity-checked roster file manipulation. Primarily, this function handles 1024-- | Sanity-checked roster file manipulation. Primarily, this function handles
1025-- hostname aliases. 1025-- hostname aliases.
@@ -1045,8 +1045,9 @@ modifyRosterFile ::
1045 -> Text -- ^ JID that will be added or removed a hostname 1045 -> Text -- ^ JID that will be added or removed a hostname
1046 -> [PeerAddress] -- ^ Alias addresses for hostname in the JID. 1046 -> [PeerAddress] -- ^ Alias addresses for hostname in the JID.
1047 -> Bool -- ^ True if adding, otherwise False 1047 -> Bool -- ^ True if adding, otherwise False
1048 -> Bool -- ^ True to allow deleting all users at a host.
1048 -> t1 1049 -> t1
1049modifyRosterFile man doit whose profile to addrs bAdd = do 1050modifyRosterFile man doit whose profile to addrs bAdd bWildCard = do
1050 let (mu,_,_) = splitJID to 1051 let (mu,_,_) = splitJID to
1051 -- For each jid in the file, this function will decide whether to keep 1052 -- For each jid in the file, this function will decide whether to keep
1052 -- it (possibly modified) which is indicated by Just _ or to remove the 1053 -- it (possibly modified) which is indicated by Just _ or to remove the
@@ -1066,9 +1067,9 @@ modifyRosterFile man doit whose profile to addrs bAdd = do
1066 guard $ isNothing mr -- delete if resource specified in file. 1067 guard $ isNothing mr -- delete if resource specified in file.
1067 stored_u <- msu -- delete if user not specified in file. 1068 stored_u <- msu -- delete if user not specified in file.
1068 case mu of 1069 case mu of
1069 Nothing -> Just keep -- do not delete if /to/ has no user field 1070 Nothing | not bWildCard -> Just keep -- do not delete if /to/ has no user field
1070 Just u | u /= stored_u -> Just keep -- do not delete if users don't match 1071 Just u | u /= stored_u -> Just keep -- do not delete if users don't match
1071 Just _ -> Just iocheck -- do not delete unless hostname alias 1072 _ -> Just iocheck -- do not delete unless hostname alias
1072 doit (textToLazyByteString whose) (Text.unpack profile) 1073 doit (textToLazyByteString whose) (Text.unpack profile)
1073 cmp 1074 cmp
1074 (guard bAdd >> Just (textToLazyByteString to)) 1075 (guard bAdd >> Just (textToLazyByteString to))
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.
diff --git a/examples/dhtd.hs b/examples/dhtd.hs
index d5428f93..481129b3 100644
--- a/examples/dhtd.hs
+++ b/examples/dhtd.hs
@@ -1652,8 +1652,8 @@ onNewToxSession sv ssvar ContactInfo{accounts} addrTox netcrypto = do
1652 where 1652 where
1653 toxSrc :: ConduitT () (Int, CryptoMessage) IO () 1653 toxSrc :: ConduitT () (Int, CryptoMessage) IO ()
1654 toxSnk :: ConduitT (Maybe Int, CryptoMessage) Void IO () 1654 toxSnk :: ConduitT (Maybe Int, CryptoMessage) Void IO ()
1655 xmppSrc :: ConduitT () XML.Event IO () 1655 xmppSrc :: ConduitT () XML.Event IO ()
1656 xmppSnk :: ConduitT (Flush XML.Event) Void IO () 1656 xmppSnk :: ConduitT (Flush XML.Event) Void IO ()
1657 1657
1658 toxSrc = ioToSource (atomically $ orElse (awaitAny c) 1658 toxSrc = ioToSource (atomically $ orElse (awaitAny c)
1659 $ aggregateStatus c >>= \case 1659 $ aggregateStatus c >>= \case