summaryrefslogtreecommitdiff
path: root/examples
diff options
context:
space:
mode:
Diffstat (limited to 'examples')
-rw-r--r--examples/dhtd.hs38
1 files changed, 37 insertions, 1 deletions
diff --git a/examples/dhtd.hs b/examples/dhtd.hs
index 92af259c..d5428f93 100644
--- a/examples/dhtd.hs
+++ b/examples/dhtd.hs
@@ -1690,6 +1690,42 @@ onNewToxSession sv ssvar ContactInfo{accounts} addrTox netcrypto = do
1690 1690
1691 return () 1691 return ()
1692 1692
1693selectManager :: Maybe (t -> ToxManager k) -> Manager status T.Text -> T.Text -> Manager status T.Text
1694selectManager (Just tman) tcp profile = case T.splitAt 43 profile of
1695 (k,".tox") -> let _ = _
1696 tox = toxConnections $ tman $ error "PresenseState"
1697 in Manager
1698 { resolvePeer = \themhost -> do
1699 r <- fromMaybe (return []) $ do
1700 (themT,".tox") <- Just $ T.splitAt 43 themhost
1701 them <- readMaybe $ T.unpack themT
1702 me <- readMaybe $ T.unpack k
1703 let contact = Tox.ToxContact me them
1704 Just $ resolvePeer tox contact
1705 dput XMan $ "resolvePeer(tox) " ++ show (T.take 8 $ k,T.take 8 $ themhost,r)
1706 return r
1707 , reverseAddress = \paddr -> do
1708 r <- fromMaybe (return []) $ do
1709 me <- readMaybe $ T.unpack k
1710 Just $ do
1711 reverseAddress tox paddr
1712 <&> mapMaybe (\case
1713 Tox.ToxContact a k | a == me -> Just $ T.pack (show k) `T.append` ".tox"
1714 _ -> Nothing)
1715 dput XMan $ "reverseAddress(tox)" ++ show (T.take 8 k,paddr) ++ ": " ++ show r
1716 return r
1717 }
1718 _ -> tcp
1719selectManager _ tcp profile = tcp
1720 { resolvePeer = \themhost -> do
1721 dput XMan $ "resolvePeer(tcp) " ++ show (profile,themhost)
1722 resolvePeer tcp themhost
1723 , reverseAddress = \paddr -> do
1724 dput XMan $ "reverseAddress(tcp) " ++ show (profile,paddr)
1725 reverseAddress tcp paddr
1726 }
1727
1728
1693main :: IO () 1729main :: IO ()
1694main = do 1730main = do
1695 args <- getArgs 1731 args <- getArgs
@@ -2022,7 +2058,7 @@ main = do
2022 sv <- xmppServer Tcp.noCleanUp (Just sport) 2058 sv <- xmppServer Tcp.noCleanUp (Just sport)
2023 tcp <- xmppConnections sv -- :: IO ( Manager TCPStatus T.Text ) 2059 tcp <- xmppConnections sv -- :: IO ( Manager TCPStatus T.Text )
2024 let tman = toxman ssvar announcer toxbkts <$> mbtox 2060 let tman = toxman ssvar announcer toxbkts <$> mbtox
2025 state <- newPresenceState cw tman sv (const tcp) 2061 state <- newPresenceState cw tman sv (selectManager tman tcp)
2026 forkXmpp sv (presenceHooks state (verbosity opts) (Just cport) (Just sport)) 2062 forkXmpp sv (presenceHooks state (verbosity opts) (Just cport) (Just sport))
2027 conns <- xmppConnections sv 2063 conns <- xmppConnections sv
2028 return (Just sv, Just conns, Just state) 2064 return (Just sv, Just conns, Just state)