diff options
Diffstat (limited to 'examples/dhtd.hs')
-rw-r--r-- | examples/dhtd.hs | 29 |
1 files changed, 21 insertions, 8 deletions
diff --git a/examples/dhtd.hs b/examples/dhtd.hs index 4b38a7ea..d5310f57 100644 --- a/examples/dhtd.hs +++ b/examples/dhtd.hs | |||
@@ -92,6 +92,7 @@ import qualified Network.Tox.Crypto.Handlers as Tox | |||
92 | import Data.Typeable | 92 | import Data.Typeable |
93 | import Roster | 93 | import Roster |
94 | import OnionRouter | 94 | import OnionRouter |
95 | import PingMachine | ||
95 | 96 | ||
96 | -- Presence imports. | 97 | -- Presence imports. |
97 | import ConsoleWriter | 98 | import ConsoleWriter |
@@ -99,7 +100,7 @@ import Presence | |||
99 | import XMPPServer | 100 | import XMPPServer |
100 | import Connection | 101 | import Connection |
101 | import ToxToXMPP | 102 | import ToxToXMPP |
102 | import qualified Connection.Tcp (ConnectionEvent(..)) | 103 | import qualified Connection.Tcp as Tcp (ConnectionEvent(..)) |
103 | 104 | ||
104 | 105 | ||
105 | showReport :: [(String,String)] -> String | 106 | showReport :: [(String,String)] -> String |
@@ -987,17 +988,25 @@ noArgPing :: (x -> IO (Maybe r)) -> [String] -> x -> IO (Maybe r) | |||
987 | noArgPing f [] x = f x | 988 | noArgPing f [] x = f x |
988 | noArgPing _ _ _ = return Nothing | 989 | noArgPing _ _ _ = return Nothing |
989 | 990 | ||
990 | announceToxConnection :: TChan ((ConnectionKey,SockAddr), Connection.Tcp.ConnectionEvent XML.Event) | 991 | newXmmpSource :: Tox.NetCryptoSession -> IO (C.Source IO Tox.CryptoMessage) |
992 | newXmmpSource = _todo | ||
993 | |||
994 | newXmmpSink :: Tox.NetCryptoSession -> IO (C.Sink (Flush Tox.CryptoMessage) IO ()) | ||
995 | newXmmpSink = _todo | ||
996 | |||
997 | announceToxXMPPClients :: TChan ((ConnectionKey,SockAddr), Tcp.ConnectionEvent XML.Event) | ||
991 | -> SockAddr | 998 | -> SockAddr |
992 | -> SockAddr | 999 | -> SockAddr |
993 | -> STM Bool | 1000 | -> STM Bool |
994 | -> C.Source IO Tox.CryptoMessage | 1001 | -> C.Source IO Tox.CryptoMessage |
995 | -> C.Sink (Flush Tox.CryptoMessage) IO () | 1002 | -> C.Sink (Flush Tox.CryptoMessage) IO () |
996 | -> IO () | 1003 | -> IO (Maybe (Tox.NetCryptoSession -> Tox.NetCryptoSession)) |
997 | announceToxConnection echan laddr saddr pingflag tsrc tsnk | 1004 | announceToxXMPPClients echan laddr saddr pingflag tsrc tsnk |
998 | = atomically $ writeTChan echan | 1005 | = do |
1006 | atomically $ writeTChan echan | ||
999 | ( (PeerKey saddr, laddr ) | 1007 | ( (PeerKey saddr, laddr ) |
1000 | , Connection.Tcp.Connection pingflag xsrc xsnk ) | 1008 | , Tcp.Connection pingflag xsrc xsnk ) |
1009 | return Nothing | ||
1001 | where | 1010 | where |
1002 | xsrc = tsrc =$= toxToXmpp | 1011 | xsrc = tsrc =$= toxToXmpp |
1003 | xsnk = flushPassThrough xmppToTox =$= tsnk | 1012 | xsnk = flushPassThrough xmppToTox =$= tsnk |
@@ -1126,17 +1135,21 @@ main = runResourceT $ liftBaseWith $ \resT -> do | |||
1126 | 1135 | ||
1127 | crypto <- Tox.newCrypto | 1136 | crypto <- Tox.newCrypto |
1128 | netCryptoSessionsState <- Tox.newSessionsState crypto Tox.defaultUnRecHook Tox.defaultCryptoDataHooks | 1137 | netCryptoSessionsState <- Tox.newSessionsState crypto Tox.defaultUnRecHook Tox.defaultCryptoDataHooks |
1129 | |||
1130 | (mbtox,quitTox,toxdhts,toxips,taddrs) <- case porttox opts of | 1138 | (mbtox,quitTox,toxdhts,toxips,taddrs) <- case porttox opts of |
1131 | "" -> return (Nothing,return (), Map.empty, return [],[]) | 1139 | "" -> return (Nothing,return (), Map.empty, return [],[]) |
1132 | toxport -> do | 1140 | toxport -> do |
1133 | addrTox <- getBindAddress toxport (ip6tox opts) | 1141 | addrTox <- getBindAddress toxport (ip6tox opts) |
1142 | atomically $ Tox.addNewSessionHook netCryptoSessionsState $ \mbNoSpam netcrypto -> do | ||
1143 | let Just pingMachine = Tox.ncPingMachine netcrypto | ||
1144 | pingflag = readTVar (pingFlag pingMachine) | ||
1145 | xmppSrc <- newXmmpSource netcrypto | ||
1146 | xmppSink <- newXmmpSink netcrypto | ||
1147 | announceToxXMPPClients (xmppEventChannel sv) addrTox (Tox.ncSockAddr netcrypto) pingflag xmppSrc xmppSink | ||
1134 | hPutStrLn stderr $ "Supplied key: " ++ show (fmap (Tox.key2id . toPublic) (dhtkey opts)) | 1148 | hPutStrLn stderr $ "Supplied key: " ++ show (fmap (Tox.key2id . toPublic) (dhtkey opts)) |
1135 | tox <- Tox.newTox keysdb | 1149 | tox <- Tox.newTox keysdb |
1136 | addrTox | 1150 | addrTox |
1137 | (Just netCryptoSessionsState) | 1151 | (Just netCryptoSessionsState) |
1138 | (dhtkey opts) | 1152 | (dhtkey opts) |
1139 | (announceToxConnection (xmppEventChannel sv) addrTox) | ||
1140 | (quitTox, toxStrap4, toxStrap6) <- Tox.forkTox tox | 1153 | (quitTox, toxStrap4, toxStrap6) <- Tox.forkTox tox |
1141 | 1154 | ||
1142 | toxSearches <- atomically $ newTVar Map.empty | 1155 | toxSearches <- atomically $ newTVar Map.empty |