diff options
author | Joe Crayne <joe@jerkface.net> | 2019-11-29 16:34:27 -0500 |
---|---|---|
committer | Joe Crayne <joe@jerkface.net> | 2020-01-01 22:57:44 -0500 |
commit | 0d75b2bd2f6002629bbeb9d6e43a19c0fcb6ac5f (patch) | |
tree | 275869d864b09b6d031da1c9578306ac3df0d71d /dht/Presence | |
parent | ae914e1189a4f601388ad4b83be35e45bbc68d83 (diff) |
Refactoring.
Diffstat (limited to 'dht/Presence')
-rw-r--r-- | dht/Presence/Presence.hs | 36 |
1 files changed, 18 insertions, 18 deletions
diff --git a/dht/Presence/Presence.hs b/dht/Presence/Presence.hs index dcc76c5b..926ee3c2 100644 --- a/dht/Presence/Presence.hs +++ b/dht/Presence/Presence.hs | |||
@@ -54,6 +54,7 @@ import Network.Tox.NodeId (key2id,parseNoSpamId,nospam64,NoSpamId(..),ToxProgres | |||
54 | import Crypto.Tox (decodeSecret) | 54 | import Crypto.Tox (decodeSecret) |
55 | import DPut | 55 | import DPut |
56 | import DebugTag | 56 | import DebugTag |
57 | import Codec.AsciiKey256 | ||
57 | 58 | ||
58 | {- | 59 | {- |
59 | isPeerKey :: ClientAddress -> Bool | 60 | isPeerKey :: ClientAddress -> Bool |
@@ -251,12 +252,12 @@ chooseResourceName state k (Remote addr) clientsNameForMe desired = do | |||
251 | flgs <- atomically $ newTVar 0 | 252 | flgs <- atomically $ newTVar 0 |
252 | profile <- fmap (fromMaybe ".") | 253 | profile <- fmap (fromMaybe ".") |
253 | $ forM ((,) <$> clientsNameForMe <*> toxManager state) $ \(wanted_profile0,toxman) -> | 254 | $ forM ((,) <$> clientsNameForMe <*> toxManager state) $ \(wanted_profile0,toxman) -> |
254 | case splitLast4 wanted_profile0 of | 255 | case stripSuffix ".tox" wanted_profile0 of |
255 | ("*",".tox") -> do | 256 | Just "*" -> do |
256 | dput XMisc $ "TODO: Match single tox key profile or generate first." | 257 | dput XMisc $ "TODO: Match single tox key profile or generate first." |
257 | -- TODO: Match single tox key profile or generate first. | 258 | -- TODO: Match single tox key profile or generate first. |
258 | _todo | 259 | _todo |
259 | (pub,".tox") -> do | 260 | Just pub -> do |
260 | cdir <- ConfigFiles.configPath (L.fromChunks [Text.encodeUtf8 user]) "." "" | 261 | cdir <- ConfigFiles.configPath (L.fromChunks [Text.encodeUtf8 user]) "." "" |
261 | #if !MIN_VERSION_directory(1,2,5) | 262 | #if !MIN_VERSION_directory(1,2,5) |
262 | let listDirectory path = filter (`notElem` [".",".."]) <$> getDirectoryContents path | 263 | let listDirectory path = filter (`notElem` [".",".."]) <$> getDirectoryContents path |
@@ -361,7 +362,7 @@ rosterGetStuff what state k = forClient state k (return []) | |||
361 | PresenceState { server = sv } -> do | 362 | PresenceState { server = sv } -> do |
362 | let conns = manager state $ clientProfile client | 363 | let conns = manager state $ clientProfile client |
363 | -- Grok peers to associate with from the roster: | 364 | -- Grok peers to associate with from the roster: |
364 | let isTox = do (me , ".tox") <- Just $ splitLast4 (clientProfile client) | 365 | let isTox = do me <- stripSuffix ".tox" (clientProfile client) |
365 | return me | 366 | return me |
366 | noToxUsers (u,h,r) | 367 | noToxUsers (u,h,r) |
367 | | Text.isSuffixOf ".tox" h = unsplitJID (Nothing,h,r) | 368 | | Text.isSuffixOf ".tox" h = unsplitJID (Nothing,h,r) |
@@ -373,8 +374,9 @@ rosterGetStuff what state k = forClient state k (return []) | |||
373 | let policySetter = fromMaybe (Connection.setPolicy conns host) $ do | 374 | let policySetter = fromMaybe (Connection.setPolicy conns host) $ do |
374 | isTox | 375 | isTox |
375 | toxman <- toxManager state | 376 | toxman <- toxManager state |
376 | (them, ".tox") <- Just $ splitLast4 host | 377 | them <- stripSuffix ".tox" host |
377 | meid <- readMaybe $ Text.unpack $ Text.dropEnd 4 (clientProfile client) | 378 | prof <- stripSuffix ".tox" (clientProfile client) |
379 | meid <- readMaybe $ Text.unpack prof | ||
378 | themid <- readMaybe $ Text.unpack them | 380 | themid <- readMaybe $ Text.unpack them |
379 | return $ Connection.setPolicy (toxConnections toxman) | 381 | return $ Connection.setPolicy (toxConnections toxman) |
380 | (ToxContact meid themid) | 382 | (ToxContact meid themid) |
@@ -547,9 +549,9 @@ eofConn state saddr cdta = do | |||
547 | Right (k,_) -> do | 549 | Right (k,_) -> do |
548 | forClient state k (return ()) $ \client -> do | 550 | forClient state k (return ()) $ \client -> do |
549 | forM_ (toxManager state) $ \toxman -> do | 551 | forM_ (toxManager state) $ \toxman -> do |
550 | case splitLast4 (clientProfile client) of | 552 | case stripSuffix ".tox" (clientProfile client) of |
551 | (pub,".tox") -> deactivateAccount toxman k (clientProfile client) | 553 | Just pub -> deactivateAccount toxman k (clientProfile client) |
552 | _ -> return () | 554 | _ -> return () |
553 | stanza <- makePresenceStanza "jabber:server" Nothing Offline | 555 | stanza <- makePresenceStanza "jabber:server" Nothing Offline |
554 | informClientPresence state k stanza | 556 | informClientPresence state k stanza |
555 | atomically $ do | 557 | atomically $ do |
@@ -665,12 +667,12 @@ deliverMessage state fail msg = | |||
665 | -- In case the client sends us a lower-cased version of the base64 | 667 | -- In case the client sends us a lower-cased version of the base64 |
666 | -- tox key hostname, we resolve it by comparing it with roster entries. | 668 | -- tox key hostname, we resolve it by comparing it with roster entries. |
667 | xs <- getBuddiesAndSolicited state (clientProfile client) $ \case | 669 | xs <- getBuddiesAndSolicited state (clientProfile client) $ \case |
668 | rh | (_,".tox") <- splitLast4 rh | 670 | rh | Just _ <- stripSuffix ".tox" rh |
669 | , Text.toLower rh == Text.toLower th | 671 | , Text.toLower rh == Text.toLower th |
670 | -> return True | 672 | -> return True |
671 | _ -> return False | 673 | _ -> return False |
672 | fmap join $ forM (listToMaybe xs) $ \(_,rmu,_,h) -> do | 674 | fmap join $ forM (listToMaybe xs) $ \(_,rmu,_,h) -> do |
673 | let (them,_) = splitLast4 h | 675 | let them = fromMaybe h $ stripSuffix ".tox" h |
674 | maddr <- resolveToxPeer toxman me them | 676 | maddr <- resolveToxPeer toxman me them |
675 | let to' = unsplitJID (mu,h,rsc) | 677 | let to' = unsplitJID (mu,h,rsc) |
676 | return $ fmap (to',) maddr | 678 | return $ fmap (to',) maddr |
@@ -1168,21 +1170,19 @@ clientSubscriptionRequest state fail k stanza chan = do | |||
1168 | (connChan con) | 1170 | (connChan con) |
1169 | let policySetter = fromMaybe (Connection.setPolicy conns h) $ do | 1171 | let policySetter = fromMaybe (Connection.setPolicy conns h) $ do |
1170 | (toxman,_,_) <- weAreTox state client h | 1172 | (toxman,_,_) <- weAreTox state client h |
1171 | meid <- readMaybe $ Text.unpack $ case splitLast4 (clientProfile client) of | 1173 | meid <- readMaybe $ Text.unpack $ case stripSuffix ".tox" (clientProfile client) of |
1172 | (h,".tox") -> h | 1174 | Just h -> h |
1173 | _ -> clientProfile client | 1175 | _ -> clientProfile client |
1174 | themid <- readMaybe $ Text.unpack h | 1176 | themid <- readMaybe $ Text.unpack h |
1175 | Just $ Connection.setPolicy (toxConnections toxman) (ToxContact meid themid) | 1177 | Just $ Connection.setPolicy (toxConnections toxman) (ToxContact meid themid) |
1176 | -- Add peer if we are not already associated ... | 1178 | -- Add peer if we are not already associated ... |
1177 | policySetter Connection.TryingToConnect | 1179 | policySetter Connection.TryingToConnect |
1178 | 1180 | ||
1179 | splitLast4 h = Text.splitAt (Text.length h - 4) h | ||
1180 | |||
1181 | weAreTox :: PresenceState stat -> ClientState -> Text -> Maybe (ToxManager ClientAddress,Text{- me -},Text{- them -}) | 1181 | weAreTox :: PresenceState stat -> ClientState -> Text -> Maybe (ToxManager ClientAddress,Text{- me -},Text{- them -}) |
1182 | weAreTox state client h = do | 1182 | weAreTox state client h = do |
1183 | toxman <- toxManager state | 1183 | toxman <- toxManager state |
1184 | (me , ".tox") <- Just $ splitLast4 (clientProfile client) | 1184 | me <- stripSuffix ".tox" (clientProfile client) |
1185 | (them, ".tox") <- Just $ splitLast4 h | 1185 | them <- stripSuffix ".tox" h |
1186 | return (toxman,me,them) | 1186 | return (toxman,me,them) |
1187 | 1187 | ||
1188 | resolvedFromRoster | 1188 | resolvedFromRoster |