summaryrefslogtreecommitdiff
path: root/examples
diff options
context:
space:
mode:
Diffstat (limited to 'examples')
-rw-r--r--examples/dhtd.hs63
1 files changed, 35 insertions, 28 deletions
diff --git a/examples/dhtd.hs b/examples/dhtd.hs
index 73ae5a57..fbfca86f 100644
--- a/examples/dhtd.hs
+++ b/examples/dhtd.hs
@@ -994,6 +994,18 @@ newXmmpSource = _todo
994newXmmpSink :: Tox.NetCryptoSession -> IO (C.Sink (Flush Tox.CryptoMessage) IO ()) 994newXmmpSink :: Tox.NetCryptoSession -> IO (C.Sink (Flush Tox.CryptoMessage) IO ())
995newXmmpSink = _todo 995newXmmpSink = _todo
996 996
997-- | TODO
998--
999-- These hooks will be invoked in order to connect to *.tox hosts in a user's
1000-- XMPP roster.
1001toxman :: Tox.Tox -> ToxManager k
1002toxman tox = ToxManager
1003 { activateAccount = \k pubname seckey -> return ()
1004 , deactivateAccount = \k pubname -> return ()
1005 , setToxConnectionPolicy = \me them policy -> return ()
1006 }
1007
1008
997announceToxXMPPClients :: TChan ((ConnectionKey,SockAddr), Tcp.ConnectionEvent XML.Event) 1009announceToxXMPPClients :: TChan ((ConnectionKey,SockAddr), Tcp.ConnectionEvent XML.Event)
998 -> SockAddr 1010 -> SockAddr
999 -> SockAddr 1011 -> SockAddr
@@ -1012,6 +1024,7 @@ announceToxXMPPClients echan laddr saddr pingflag tsrc tsnk
1012 xsnk = flushPassThrough xmppToTox =$= tsnk 1024 xsnk = flushPassThrough xmppToTox =$= tsnk
1013 1025
1014 1026
1027
1015main :: IO () 1028main :: IO ()
1016main = runResourceT $ liftBaseWith $ \resT -> do 1029main = runResourceT $ liftBaseWith $ \resT -> do
1017 args <- getArgs 1030 args <- getArgs
@@ -1027,28 +1040,6 @@ main = runResourceT $ liftBaseWith $ \resT -> do
1027 1040
1028 announcer <- forkAnnouncer 1041 announcer <- forkAnnouncer
1029 1042
1030 let toxman = ToxManager
1031 { activateAccount = \k pubkey -> return ()
1032 , deactivateAccount = \k pubkey -> return ()
1033 , setToxConnectionPolicy = \me them policy -> return ()
1034 }
1035
1036 -- XMPP initialization
1037 cw <- newConsoleWriter
1038 serverVar <- atomically $ newEmptyTMVar
1039 state <- newPresenceState cw (Just toxman) serverVar
1040
1041 -- XMPP stanza handling
1042 sv <- resT $ xmppServer (presenceHooks state (verbosity opts))
1043 -- We now have a server object but it's not ready to use until
1044 -- we put it into the 'server' field of our /state/ record.
1045
1046 conns <- xmppConnections sv
1047
1048 atomically $ do
1049 putTMVar serverVar (sv,conns) -- Okay, now it's ready. :)
1050 -- FIXME: This is error prone.
1051
1052 1043
1053 (quitBt,btdhts,btips,baddrs) <- case portbt opts of 1044 (quitBt,btdhts,btips,baddrs) <- case portbt opts of
1054 "" -> return (return (), Map.empty,return [],[]) 1045 "" -> return (return (), Map.empty,return [],[])
@@ -1145,12 +1136,6 @@ main = runResourceT $ liftBaseWith $ \resT -> do
1145 "" -> return (Nothing,return (), Map.empty, return [],[]) 1136 "" -> return (Nothing,return (), Map.empty, return [],[])
1146 toxport -> do 1137 toxport -> do
1147 addrTox <- getBindAddress toxport (ip6tox opts) 1138 addrTox <- getBindAddress toxport (ip6tox opts)
1148 atomically $ Tox.addNewSessionHook netCryptoSessionsState $ \mbNoSpam netcrypto -> do
1149 let Just pingMachine = Tox.ncPingMachine netcrypto
1150 pingflag = readTVar (pingFlag pingMachine)
1151 xmppSrc <- newXmmpSource netcrypto
1152 xmppSink <- newXmmpSink netcrypto
1153 announceToxXMPPClients (xmppEventChannel sv) addrTox (Tox.ncSockAddr netcrypto) pingflag xmppSrc xmppSink
1154 hPutStrLn stderr $ "Supplied key: " ++ show (fmap (Tox.key2id . toPublic) (dhtkey opts)) 1139 hPutStrLn stderr $ "Supplied key: " ++ show (fmap (Tox.key2id . toPublic) (dhtkey opts))
1155 tox <- Tox.newTox keysdb 1140 tox <- Tox.newTox keysdb
1156 addrTox 1141 addrTox
@@ -1321,8 +1306,30 @@ main = runResourceT $ liftBaseWith $ \resT -> do
1321 ips = readExternals Tox.nodeAddr [ Tox.routing4 $ Tox.toxRouting tox 1306 ips = readExternals Tox.nodeAddr [ Tox.routing4 $ Tox.toxRouting tox
1322 , Tox.routing6 $ Tox.toxRouting tox ] 1307 , Tox.routing6 $ Tox.toxRouting tox ]
1323 return (Just tox, quitTox, dhts, ips, [addrTox]) 1308 return (Just tox, quitTox, dhts, ips, [addrTox])
1309
1324 _ <- UPNP.requestPorts "dht-client" $ map (Datagram,) $ baddrs ++ taddrs 1310 _ <- UPNP.requestPorts "dht-client" $ map (Datagram,) $ baddrs ++ taddrs
1325 1311
1312 -- XMPP initialization
1313 cw <- newConsoleWriter
1314 serverVar <- atomically $ newEmptyTMVar
1315 state <- newPresenceState cw (toxman <$> mbtox) serverVar
1316
1317 sv <- resT $ xmppServer (presenceHooks state (verbosity opts))
1318 -- We now have a server object but it's not ready to use until
1319 -- we put it into the 'server' field of our /state/ record.
1320 conns <- xmppConnections sv
1321 atomically $ do
1322 putTMVar serverVar (sv,conns) -- Okay, now it's ready. :)
1323 -- FIXME: This is error prone.
1324
1325 forM_ (take 1 taddrs) $ \addrTox -> do
1326 atomically $ Tox.addNewSessionHook netCryptoSessionsState $ \mbNoSpam netcrypto -> do
1327 let Just pingMachine = Tox.ncPingMachine netcrypto
1328 pingflag = readTVar (pingFlag pingMachine)
1329 xmppSrc <- newXmmpSource netcrypto
1330 xmppSink <- newXmmpSink netcrypto
1331 announceToxXMPPClients (xmppEventChannel sv) addrTox (Tox.ncSockAddr netcrypto) pingflag xmppSrc xmppSink
1332
1326 let dhts = Map.union btdhts toxdhts 1333 let dhts = Map.union btdhts toxdhts
1327 1334
1328 (waitForSignal, checkQuit) <- do 1335 (waitForSignal, checkQuit) <- do