diff options
author | Joe Crayne <joe@jerkface.net> | 2019-12-19 17:27:57 -0500 |
---|---|---|
committer | Joe Crayne <joe@jerkface.net> | 2020-01-01 23:27:24 -0500 |
commit | 3a03ba64a8d60708a43959cb0a5d97056afe056e (patch) | |
tree | b61beaf0255a94cdd0582aa2c8adcdb0ec5bd97e /dht | |
parent | 89c516018e51c4f15ace02d974a7a959f8c219a9 (diff) |
ToxManager simplification.
Diffstat (limited to 'dht')
-rw-r--r-- | dht/ToxManager.hs | 33 | ||||
-rw-r--r-- | dht/examples/dhtd.hs | 12 |
2 files changed, 13 insertions, 32 deletions
diff --git a/dht/ToxManager.hs b/dht/ToxManager.hs index 34cdcb6f..403167c2 100644 --- a/dht/ToxManager.hs +++ b/dht/ToxManager.hs | |||
@@ -100,11 +100,10 @@ stringToKey_ s = let (xs,ys) = break (==':') s | |||
100 | -- XMPP roster. | 100 | -- XMPP roster. |
101 | toxman :: TVar (Map.Map Uniq24 AggregateSession) | 101 | toxman :: TVar (Map.Map Uniq24 AggregateSession) |
102 | -> Announcer | 102 | -> Announcer |
103 | -> [(String,TVar (BucketList Tox.NodeInfo))] | ||
104 | -> Tox.Tox JabberClients | 103 | -> Tox.Tox JabberClients |
105 | -> PresenceState Pending | 104 | -> PresenceState Pending |
106 | -> ToxManager ClientAddress | 105 | -> ToxManager ClientAddress |
107 | toxman ssvar announcer toxbkts tox presence = ToxManager | 106 | toxman ssvar announcer tox presence = ToxManager |
108 | { activateAccount = \k pubname seckey -> do | 107 | { activateAccount = \k pubname seckey -> do |
109 | dput XMan $ "toxman ACTIVATE " ++ show (Tox.key2id $ toPublic seckey) | 108 | dput XMan $ "toxman ACTIVATE " ++ show (Tox.key2id $ toPublic seckey) |
110 | let ContactInfo{ accounts } = Tox.toxContactInfo tox | 109 | let ContactInfo{ accounts } = Tox.toxContactInfo tox |
@@ -119,12 +118,7 @@ toxman ssvar announcer toxbkts tox presence = ToxManager | |||
119 | modifyTVar accounts (HashMap.insert pubid acnt) | 118 | modifyTVar accounts (HashMap.insert pubid acnt) |
120 | if not (Map.null rs) | 119 | if not (Map.null rs) |
121 | then return (acnt,Nothing) | 120 | then return (acnt,Nothing) |
122 | else return (acnt,Just $ \nid -> foldr interweave [] | 121 | else return (acnt,Just $ \nid -> nearNodes tox nid) |
123 | . map (R.kclosest (searchSpace $ toxQSearch tox) | ||
124 | (searchK $ toxQSearch tox) | ||
125 | nid) | ||
126 | <$> mapM (readTVar . snd) toxbkts) | ||
127 | |||
128 | forM_ newlyActive $ \nearNodes -> do | 122 | forM_ newlyActive $ \nearNodes -> do |
129 | -- Schedule recurring announce. | 123 | -- Schedule recurring announce. |
130 | -- | 124 | -- |
@@ -160,19 +154,18 @@ toxman ssvar announcer toxbkts tox presence = ToxManager | |||
160 | -- account active. | 154 | -- account active. |
161 | modifyTVar' (accountExtra acnt) $ Map.delete k | 155 | modifyTVar' (accountExtra acnt) $ Map.delete k |
162 | return rs | 156 | return rs |
163 | if (Map.null $ Map.delete k refs) then do | 157 | return $ |
164 | let akey = akeyAccountActive announcer pubid | 158 | if (Map.null $ Map.delete k refs) then |
165 | fmap Just $ forM toxbkts $ \(nm,bkts) -> do | 159 | let akey = akeyAccountActive announcer pubid |
166 | return (akey,bkts) | 160 | in Just akey |
167 | else return Nothing | 161 | else Nothing |
168 | forM_ bStopped $ \kbkts -> do | 162 | forM_ bStopped $ \akey -> do |
169 | let Just pubid = mpubid | 163 | let Just pubid = mpubid |
170 | pub = Tox.id2key pubid | 164 | pub = Tox.id2key pubid |
171 | -- Stop the announce-toxid task for this account. Note that other | 165 | -- Stop the announce-toxid task for this account. Note that other |
172 | -- announced tasks will be stopped by the forkAccountWatcher thread | 166 | -- announced tasks will be stopped by the forkAccountWatcher thread |
173 | -- when it terminates. | 167 | -- when it terminates. |
174 | forM_ kbkts $ \(akey,bkts) -> do | 168 | cancel announcer akey |
175 | cancel announcer akey | ||
176 | 169 | ||
177 | , toxConnections = Manager | 170 | , toxConnections = Manager |
178 | { setPolicy = \(ToxContact meid themid) p -> do | 171 | { setPolicy = \(ToxContact meid themid) p -> do |
@@ -615,12 +608,6 @@ startConnecting0 tx them contact reason = do | |||
615 | let ToxToXMPP { txTox = tox | 608 | let ToxToXMPP { txTox = tox |
616 | , txAnnouncer = announcer | 609 | , txAnnouncer = announcer |
617 | , txAccount = acnt } = tx | 610 | , txAccount = acnt } = tx |
618 | let nearNodes nid = do | ||
619 | bkts4 <- readTVar $ routing4 $ toxRouting tox | ||
620 | bkts6 <- readTVar $ routing6 $ toxRouting tox | ||
621 | let nss = map (R.kclosest (searchSpace $ toxQSearch tox) (searchK $ toxQSearch tox) nid) | ||
622 | [bkts4,bkts6] | ||
623 | return $ foldr interweave [] nss | ||
624 | wanted <- atomically $ (==Just TryingToConnect) <$> readTVar (contactPolicy contact) | 611 | wanted <- atomically $ (==Just TryingToConnect) <$> readTVar (contactPolicy contact) |
625 | let mypub = toPublic $ userSecret acnt | 612 | let mypub = toPublic $ userSecret acnt |
626 | me = key2id mypub | 613 | me = key2id mypub |
@@ -641,7 +628,7 @@ startConnecting0 tx them contact reason = do | |||
641 | -- likelihood of failure as the chances of packet loss | 628 | -- likelihood of failure as the chances of packet loss |
642 | -- happening to all (up to to 8) packets sent is low. | 629 | -- happening to all (up to to 8) packets sent is low. |
643 | -- | 630 | -- |
644 | let meth = SearchMethod (toxQSearch tox) onResult nearNodes (key2id them) 30 | 631 | let meth = SearchMethod (toxQSearch tox) onResult (nearNodes tox) (key2id them) 30 |
645 | where | 632 | where |
646 | onResult theirkey rendezvous = do | 633 | onResult theirkey rendezvous = do |
647 | dkey <- Tox.getContactInfo tox | 634 | dkey <- Tox.getContactInfo tox |
diff --git a/dht/examples/dhtd.hs b/dht/examples/dhtd.hs index 96f0cb72..35b0d07b 100644 --- a/dht/examples/dhtd.hs +++ b/dht/examples/dhtd.hs | |||
@@ -1660,14 +1660,13 @@ initJabber :: Options | |||
1660 | -> TVar (Map.Map Uniq24 AggregateSession) | 1660 | -> TVar (Map.Map Uniq24 AggregateSession) |
1661 | -> Announcer | 1661 | -> Announcer |
1662 | -> Maybe (Tox.Tox JabberClients) | 1662 | -> Maybe (Tox.Tox JabberClients) |
1663 | -> Map.Map String DHT | ||
1664 | -> MUC | 1663 | -> MUC |
1665 | -> IO ( Maybe XMPPServer | 1664 | -> IO ( Maybe XMPPServer |
1666 | , Maybe ConnectionManager -- (Manager (Either Pending TCPStatus) (Either T.Text T.Text)) | 1665 | , Maybe ConnectionManager -- (Manager (Either Pending TCPStatus) (Either T.Text T.Text)) |
1667 | , Maybe (PresenceState Pending) | 1666 | , Maybe (PresenceState Pending) |
1668 | , IO () -- quit chat thread | 1667 | , IO () -- quit chat thread |
1669 | ) | 1668 | ) |
1670 | initJabber opts ssvar announcer mbtox toxdhts toxchat = case portxmpp opts of | 1669 | initJabber opts ssvar announcer mbtox toxchat = case portxmpp opts of |
1671 | "" -> return (Nothing,Nothing,Nothing,return()) | 1670 | "" -> return (Nothing,Nothing,Nothing,return()) |
1672 | p -> do | 1671 | p -> do |
1673 | cport <- getBindAddress p True{-IPv6 supported-} | 1672 | cport <- getBindAddress p True{-IPv6 supported-} |
@@ -1681,14 +1680,9 @@ initJabber opts ssvar announcer mbtox toxdhts toxchat = case portxmpp opts of | |||
1681 | lookupBkts name m = case Map.lookup name m of | 1680 | lookupBkts name m = case Map.lookup name m of |
1682 | Nothing -> Nothing | 1681 | Nothing -> Nothing |
1683 | Just DHT{dhtBuckets} -> cast (name, dhtBuckets) | 1682 | Just DHT{dhtBuckets} -> cast (name, dhtBuckets) |
1684 | let toxbkts = catMaybes | ||
1685 | [ lookupBkts "tox4" toxdhts | ||
1686 | , lookupBkts "tox6" toxdhts | ||
1687 | ] | ||
1688 | |||
1689 | sv <- xmppServer Tcp.noCleanUp (Just sport) | 1683 | sv <- xmppServer Tcp.noCleanUp (Just sport) |
1690 | tcp <- xmppConnections sv -- :: IO ( Manager TCPStatus T.Text ) | 1684 | tcp <- xmppConnections sv -- :: IO ( Manager TCPStatus T.Text ) |
1691 | let tman = toxman ssvar announcer toxbkts <$> mbtox | 1685 | let tman = toxman ssvar announcer <$> mbtox |
1692 | state <- newPresenceState cw tman sv (selectManager tman tcp) | 1686 | state <- newPresenceState cw tman sv (selectManager tman tcp) |
1693 | chat <- atomically newMUC | 1687 | chat <- atomically newMUC |
1694 | quitChatService <- forkLocalChat chat | 1688 | quitChatService <- forkLocalChat chat |
@@ -1823,7 +1817,7 @@ main = do | |||
1823 | 1817 | ||
1824 | (mbtox,quitTox,toxdhts,toxips,(taddrs::[SockAddr])) <- initTox opts ssvar keysdb msv invc | 1818 | (mbtox,quitTox,toxdhts,toxips,(taddrs::[SockAddr])) <- initTox opts ssvar keysdb msv invc |
1825 | 1819 | ||
1826 | (msv,mconns,mstate,quitChat) <- initJabber opts ssvar announcer mbtox toxdhts toxchat | 1820 | (msv,mconns,mstate,quitChat) <- initJabber opts ssvar announcer mbtox toxchat |
1827 | 1821 | ||
1828 | return (mbtox,quitTox >> quitChat,toxdhts,toxips,(taddrs::[SockAddr]),msv,mconns,mstate) | 1822 | return (mbtox,quitTox >> quitChat,toxdhts,toxips,(taddrs::[SockAddr]),msv,mconns,mstate) |
1829 | 1823 | ||