diff options
Diffstat (limited to 'examples/dhtd.hs')
-rw-r--r-- | examples/dhtd.hs | 39 |
1 files changed, 33 insertions, 6 deletions
diff --git a/examples/dhtd.hs b/examples/dhtd.hs index 481129b3..892fc88c 100644 --- a/examples/dhtd.hs +++ b/examples/dhtd.hs | |||
@@ -122,7 +122,7 @@ import XMPPServer | |||
122 | import Connection | 122 | import Connection |
123 | import ToxToXMPP | 123 | import ToxToXMPP |
124 | import XMPPToTox | 124 | import XMPPToTox |
125 | import qualified Connection.Tcp as Tcp (ConnectionEvent(..),noCleanUp) | 125 | import qualified Connection.Tcp as Tcp (ConnectionEvent(..),noCleanUp,TCPStatus) |
126 | import Control.Concurrent.Supply | 126 | import Control.Concurrent.Supply |
127 | import qualified Data.CyclicBuffer as CB | 127 | import qualified Data.CyclicBuffer as CB |
128 | import DPut | 128 | import DPut |
@@ -1690,10 +1690,19 @@ onNewToxSession sv ssvar ContactInfo{accounts} addrTox netcrypto = do | |||
1690 | 1690 | ||
1691 | return () | 1691 | return () |
1692 | 1692 | ||
1693 | selectManager :: Maybe (t -> ToxManager k) -> Manager status T.Text -> T.Text -> Manager status T.Text | 1693 | selectManager :: Maybe (t -> ToxManager clientAddress) -> Manager Tcp.TCPStatus T.Text -> T.Text -> Manager Pending T.Text |
1694 | selectManager (Just tman) tcp profile = case T.splitAt 43 profile of | 1694 | selectManager mtman tcp profile = case T.splitAt 43 profile of |
1695 | (k,".tox") -> let _ = _ | 1695 | (k,".tox") | Just tman <- mtman |
1696 | -> let _ = _ | ||
1697 | -- The following error call is safe because the toxConnections field | ||
1698 | -- does not make use of the PresenceState passed to tman. | ||
1696 | tox = toxConnections $ tman $ error "PresenseState" | 1699 | tox = toxConnections $ tman $ error "PresenseState" |
1700 | tkey them = do | ||
1701 | me <- readMaybe (T.unpack k) | ||
1702 | them <- case T.splitAt 43 them of | ||
1703 | (them0,".tox") -> readMaybe (T.unpack them0) | ||
1704 | _ -> Nothing | ||
1705 | return (Tox.ToxContact me them) | ||
1697 | in Manager | 1706 | in Manager |
1698 | { resolvePeer = \themhost -> do | 1707 | { resolvePeer = \themhost -> do |
1699 | r <- fromMaybe (return []) $ do | 1708 | r <- fromMaybe (return []) $ do |
@@ -1714,15 +1723,33 @@ selectManager (Just tman) tcp profile = case T.splitAt 43 profile of | |||
1714 | _ -> Nothing) | 1723 | _ -> Nothing) |
1715 | dput XMan $ "reverseAddress(tox)" ++ show (T.take 8 k,paddr) ++ ": " ++ show r | 1724 | dput XMan $ "reverseAddress(tox)" ++ show (T.take 8 k,paddr) ++ ": " ++ show r |
1716 | return r | 1725 | return r |
1726 | |||
1727 | , setPolicy = \them -> case tkey them of | ||
1728 | Just tk -> \p -> setPolicy tox tk p | ||
1729 | Nothing -> \p -> return () | ||
1730 | , status = \them -> case tkey them of | ||
1731 | Just tk -> fmap ToxStatus <$> status tox tk | ||
1732 | Nothing -> return $ Connection Dormant RefusingToConnect | ||
1733 | , connections = let valid (Tox.ToxContact local them) = do | ||
1734 | guard $ T.pack (show local) == k | ||
1735 | return $ T.pack (show them ++ ".tox") | ||
1736 | in fmap (mapMaybe valid) $ connections tox | ||
1737 | , stringToKey = \s -> Just $ T.pack (s ++ ".tox") | ||
1738 | , showProgress = \(ToxStatus stat) -> showProgress tox stat | ||
1717 | } | 1739 | } |
1718 | _ -> tcp | 1740 | _ -> Manager |
1719 | selectManager _ tcp profile = tcp | ||
1720 | { resolvePeer = \themhost -> do | 1741 | { resolvePeer = \themhost -> do |
1721 | dput XMan $ "resolvePeer(tcp) " ++ show (profile,themhost) | 1742 | dput XMan $ "resolvePeer(tcp) " ++ show (profile,themhost) |
1722 | resolvePeer tcp themhost | 1743 | resolvePeer tcp themhost |
1723 | , reverseAddress = \paddr -> do | 1744 | , reverseAddress = \paddr -> do |
1724 | dput XMan $ "reverseAddress(tcp) " ++ show (profile,paddr) | 1745 | dput XMan $ "reverseAddress(tcp) " ++ show (profile,paddr) |
1725 | reverseAddress tcp paddr | 1746 | reverseAddress tcp paddr |
1747 | |||
1748 | , setPolicy = setPolicy tcp | ||
1749 | , status = \k -> fmap XMPPStatus <$> status tcp k | ||
1750 | , connections = connections tcp | ||
1751 | , stringToKey = stringToKey tcp | ||
1752 | , showProgress = \(XMPPStatus stat) -> showProgress tcp stat | ||
1726 | } | 1753 | } |
1727 | 1754 | ||
1728 | 1755 | ||