summaryrefslogtreecommitdiff
path: root/Presence/Presence.hs
diff options
context:
space:
mode:
Diffstat (limited to 'Presence/Presence.hs')
-rw-r--r--Presence/Presence.hs26
1 files changed, 21 insertions, 5 deletions
diff --git a/Presence/Presence.hs b/Presence/Presence.hs
index 77689d1e..ed1c5033 100644
--- a/Presence/Presence.hs
+++ b/Presence/Presence.hs
@@ -39,7 +39,8 @@ import Data.XML.Types (Event)
39import System.Posix.Types (UserID,CPid) 39import System.Posix.Types (UserID,CPid)
40import Control.Applicative 40import Control.Applicative
41import Crypto.Error.Types (CryptoFailable (..)) 41import Crypto.Error.Types (CryptoFailable (..))
42import Crypto.PubKey.Curve25519 (publicKey, secretKey, toPublic) 42import Crypto.PubKey.Curve25519 (SecretKey,toPublic)
43import Text.Read (readMaybe)
43 44
44import LockedChan (LockedChan) 45import LockedChan (LockedChan)
45import TraversableT 46import TraversableT
@@ -51,6 +52,8 @@ import ConsoleWriter
51import ClientState 52import ClientState
52import Util 53import Util
53import qualified Connection 54import qualified Connection
55import Network.Tox.NodeId (id2key)
56import Crypto.Tox (decodeSecret)
54 57
55isPeerKey :: ConnectionKey -> Bool 58isPeerKey :: ConnectionKey -> Bool
56isPeerKey k = case k of { PeerKey {} -> True ; _ -> False } 59isPeerKey k = case k of { PeerKey {} -> True ; _ -> False }
@@ -65,9 +68,22 @@ localJID user "." resource = do
65localJID user profile resource = 68localJID user profile resource =
66 return $ user <> "@" <> profile <> "/" <> resource 69 return $ user <> "@" <> profile <> "/" <> resource
67 70
71-- | These hooks will be invoked in order to connect to *.tox hosts in the
72-- user's roster.
73--
74-- The parameter k is a lookup key corresponding to an XMPP client. Each
75-- unique value should be able to hold a reference to the ToxID identity which
76-- should stay online until all interested keys have run 'deactivateAccount'.
68data ToxManager k = ToxManager 77data ToxManager k = ToxManager
69 { activateAccount :: k -> Text -> IO () 78 -- | Put the given ToxID online.
79 { activateAccount :: k -> Text -> SecretKey -> IO ()
80 -- | Take the given ToxID offline (assuming no other /k/ has a claim).
70 , deactivateAccount :: k -> Text -> IO () 81 , deactivateAccount :: k -> Text -> IO ()
82 -- | Try to connect to the remote peer (or not).
83 --
84 -- The arguments are our public key (in hostname format) followed by
85 -- their public key (in hostname format) and the Policy to set for this
86 -- link.
71 , setToxConnectionPolicy :: Text -> Text -> Connection.Policy -> IO () 87 , setToxConnectionPolicy :: Text -> Text -> Connection.Policy -> IO ()
72 } 88 }
73 89
@@ -196,9 +212,9 @@ chooseResourceName state k addr clientsNameForMe desired = do
196 -- TODO: Tox key profile. 212 -- TODO: Tox key profile.
197 secs <- configText ConfigFiles.getSecrets user wanted_profile 213 secs <- configText ConfigFiles.getSecrets user wanted_profile
198 case secs of 214 case secs of
199 sec:_ | CryptoPassed s <- secretKey (Text.encodeUtf8 sec) 215 sec:_ | Just s <- decodeSecret (Text.encodeUtf8 sec)
200 , CryptoPassed (toPublic s) == publicKey (Text.encodeUtf8 pub) 216 , Just (toPublic s) == fmap id2key (readMaybe $ Text.unpack pub)
201 -> do activateAccount toxman k wanted_profile 217 -> do activateAccount toxman k wanted_profile s
202 return wanted_profile 218 return wanted_profile
203 _ -> do 219 _ -> do
204 -- XXX: We should probably fail to connect when an 220 -- XXX: We should probably fail to connect when an