summaryrefslogtreecommitdiff
path: root/examples/dhtd.hs
diff options
context:
space:
mode:
authorJames Crayne <jim.crayne@gmail.com>2017-11-21 01:27:45 +0000
committerJames Crayne <jim.crayne@gmail.com>2017-11-21 01:27:45 +0000
commitc1d033886f9d0b7038bc453795f043d1e97f94b2 (patch)
tree5fa1ca88fc3be0aaaca9af6f2d8a3bfdfae223ec /examples/dhtd.hs
parent1b0d23964cc86a29f60f96346a359ef4e31c1b5c (diff)
Use the addNewSessionHook, rename announceToxConnection
Diffstat (limited to 'examples/dhtd.hs')
-rw-r--r--examples/dhtd.hs29
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
92import Data.Typeable 92import Data.Typeable
93import Roster 93import Roster
94import OnionRouter 94import OnionRouter
95import PingMachine
95 96
96-- Presence imports. 97-- Presence imports.
97import ConsoleWriter 98import ConsoleWriter
@@ -99,7 +100,7 @@ import Presence
99import XMPPServer 100import XMPPServer
100import Connection 101import Connection
101import ToxToXMPP 102import ToxToXMPP
102import qualified Connection.Tcp (ConnectionEvent(..)) 103import qualified Connection.Tcp as Tcp (ConnectionEvent(..))
103 104
104 105
105showReport :: [(String,String)] -> String 106showReport :: [(String,String)] -> String
@@ -987,17 +988,25 @@ noArgPing :: (x -> IO (Maybe r)) -> [String] -> x -> IO (Maybe r)
987noArgPing f [] x = f x 988noArgPing f [] x = f x
988noArgPing _ _ _ = return Nothing 989noArgPing _ _ _ = return Nothing
989 990
990announceToxConnection :: TChan ((ConnectionKey,SockAddr), Connection.Tcp.ConnectionEvent XML.Event) 991newXmmpSource :: Tox.NetCryptoSession -> IO (C.Source IO Tox.CryptoMessage)
992newXmmpSource = _todo
993
994newXmmpSink :: Tox.NetCryptoSession -> IO (C.Sink (Flush Tox.CryptoMessage) IO ())
995newXmmpSink = _todo
996
997announceToxXMPPClients :: 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))
997announceToxConnection echan laddr saddr pingflag tsrc tsnk 1004announceToxXMPPClients 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