diff options
Diffstat (limited to 'Presence/Presence.hs')
-rw-r--r-- | Presence/Presence.hs | 26 |
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) | |||
39 | import System.Posix.Types (UserID,CPid) | 39 | import System.Posix.Types (UserID,CPid) |
40 | import Control.Applicative | 40 | import Control.Applicative |
41 | import Crypto.Error.Types (CryptoFailable (..)) | 41 | import Crypto.Error.Types (CryptoFailable (..)) |
42 | import Crypto.PubKey.Curve25519 (publicKey, secretKey, toPublic) | 42 | import Crypto.PubKey.Curve25519 (SecretKey,toPublic) |
43 | import Text.Read (readMaybe) | ||
43 | 44 | ||
44 | import LockedChan (LockedChan) | 45 | import LockedChan (LockedChan) |
45 | import TraversableT | 46 | import TraversableT |
@@ -51,6 +52,8 @@ import ConsoleWriter | |||
51 | import ClientState | 52 | import ClientState |
52 | import Util | 53 | import Util |
53 | import qualified Connection | 54 | import qualified Connection |
55 | import Network.Tox.NodeId (id2key) | ||
56 | import Crypto.Tox (decodeSecret) | ||
54 | 57 | ||
55 | isPeerKey :: ConnectionKey -> Bool | 58 | isPeerKey :: ConnectionKey -> Bool |
56 | isPeerKey k = case k of { PeerKey {} -> True ; _ -> False } | 59 | isPeerKey k = case k of { PeerKey {} -> True ; _ -> False } |
@@ -65,9 +68,22 @@ localJID user "." resource = do | |||
65 | localJID user profile resource = | 68 | localJID 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'. | ||
68 | data ToxManager k = ToxManager | 77 | data 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 |