diff options
-rw-r--r-- | Presence/Presence.hs | 13 | ||||
-rw-r--r-- | ToxManager.hs | 34 | ||||
-rw-r--r-- | examples/dhtd.hs | 4 |
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 |
1008 | addToRosterFile man doit whose profile to addrs = | 1008 | addToRosterFile 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 | ||
1011 | removeFromRosterFile :: | 1011 | removeFromRosterFile :: |
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 |
1021 | removeFromRosterFile man doit whose profile to addrs = | 1021 | removeFromRosterFile 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 |
1049 | modifyRosterFile man doit whose profile to addrs bAdd = do | 1050 | modifyRosterFile 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 | |||
9 | import Announcer | 9 | import Announcer |
10 | import Announcer.Tox | 10 | import Announcer.Tox |
11 | import ClientState | 11 | import ClientState |
12 | import ConfigFiles | ||
12 | import Control.Arrow | 13 | import Control.Arrow |
13 | import Control.Concurrent.STM | 14 | import Control.Concurrent.STM |
14 | import Control.Monad | 15 | import Control.Monad |
15 | import Crypto.Tox | 16 | import Crypto.Tox |
16 | import qualified Data.ByteArray as BA | ||
17 | import Data.Bits | 17 | import Data.Bits |
18 | import qualified Data.ByteArray as BA | ||
18 | import Data.Function | 19 | import Data.Function |
19 | import qualified Data.HashMap.Strict as HashMap | 20 | import qualified Data.HashMap.Strict as HashMap |
21 | import Data.List | ||
20 | import qualified Data.Map as Map | 22 | import qualified Data.Map as Map |
21 | import Data.Maybe | 23 | import Data.Maybe |
24 | import Data.Ord | ||
22 | import qualified Data.Set as Set | 25 | import qualified Data.Set as Set |
23 | import qualified Data.Text as T | 26 | import qualified Data.Text as T |
24 | ;import Data.Text (Text) | 27 | ;import Data.Text (Text) |
@@ -56,9 +59,9 @@ import Control.Concurrent.Lifted.Instrument | |||
56 | import Control.Concurrent.Lifted | 59 | import Control.Concurrent.Lifted |
57 | import GHC.Conc (labelThread) | 60 | import GHC.Conc (labelThread) |
58 | #endif | 61 | #endif |
59 | import GHC.Conc (unsafeIOToSTM) | ||
60 | import Connection | 62 | import Connection |
61 | import Connection.Tcp (TCPStatus) | 63 | import Connection.Tcp (TCPStatus) |
64 | import GHC.Conc (unsafeIOToSTM) | ||
62 | 65 | ||
63 | 66 | ||
64 | toxAnnounceSendData :: Tox.Tox JabberClients | 67 | toxAnnounceSendData :: Tox.Tox JabberClients |
@@ -476,7 +479,8 @@ realShakeHands myseckey theirpubkey theirDhtKey allsessions saddr cookie = do | |||
476 | 479 | ||
477 | 480 | ||
478 | dispatch :: ToxToXMPP -> ContactEvent -> IO () | 481 | dispatch :: ToxToXMPP -> ContactEvent -> IO () |
479 | dispatch tx (SessionEstablished theirKey) = stopConnecting tx theirKey "established" | 482 | dispatch tx (SessionEstablished theirKey) = do stopConnecting tx theirKey "established" |
483 | updateRoster tx theirKey | ||
480 | dispatch tx (SessionTerminated theirKey) = startConnecting tx theirKey "terminated" | 484 | dispatch tx (SessionTerminated theirKey) = startConnecting tx theirKey "terminated" |
481 | dispatch tx (AddrChange theirKey saddr) = gotAddr saddr tx theirKey | 485 | dispatch tx (AddrChange theirKey saddr) = gotAddr saddr tx theirKey |
482 | dispatch tx (PolicyChange theirkey TryingToConnect ) = startConnecting tx theirkey "policy" | 486 | dispatch 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. | ||
531 | updateRoster :: ToxToXMPP -> PublicKey -> IO () | ||
532 | updateRoster 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 |