summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--examples/dhtd.hs33
1 files changed, 19 insertions, 14 deletions
diff --git a/examples/dhtd.hs b/examples/dhtd.hs
index 8fc986a5..a921fea6 100644
--- a/examples/dhtd.hs
+++ b/examples/dhtd.hs
@@ -1,3 +1,4 @@
1{-# LANGUAGE BangPatterns #-}
1{-# LANGUAGE CPP #-} 2{-# LANGUAGE CPP #-}
2{-# LANGUAGE ExistentialQuantification #-} 3{-# LANGUAGE ExistentialQuantification #-}
3{-# LANGUAGE FlexibleContexts #-} 4{-# LANGUAGE FlexibleContexts #-}
@@ -1020,11 +1021,11 @@ noArgPing f [] x = f x
1020noArgPing _ _ _ = return Nothing 1021noArgPing _ _ _ = return Nothing
1021 1022
1022-- | Create a Conduit Source by repeatedly calling an IO action. 1023-- | Create a Conduit Source by repeatedly calling an IO action.
1023ioToSource :: IO (Maybe x) -> C.Source IO x 1024ioToSource :: IO (Maybe x) -> IO () -> C.Source IO x
1024ioToSource action = liftIO action >>= \case 1025ioToSource !action !onEOF = liftIO action >>= \case
1025 Nothing -> return () -- EOF. 1026 Nothing -> liftIO onEOF
1026 Just item -> do C.yield item 1027 Just item -> do C.yield item
1027 ioToSource action 1028 ioToSource action onEOF
1028 1029
1029newXmmpSink :: Tox.NetCryptoSession -> C.Sink (Flush Tox.CryptoMessage) IO () 1030newXmmpSink :: Tox.NetCryptoSession -> C.Sink (Flush Tox.CryptoMessage) IO ()
1030newXmmpSink session@(Tox.NCrypto { ncOutgoingQueue, ncPacketQueue }) = C.awaitForever $ \flush_cyptomessage -> do 1031newXmmpSink session@(Tox.NCrypto { ncOutgoingQueue, ncPacketQueue }) = C.awaitForever $ \flush_cyptomessage -> do
@@ -1096,14 +1097,16 @@ toxman tox = ToxManager
1096 1097
1097#ifdef XMPP 1098#ifdef XMPP
1098 1099
1099announceToxXMPPClients :: TChan ((ConnectionKey,SockAddr), Tcp.ConnectionEvent XML.Event) 1100-- | Called upon a new Tox friend-connection session with a remote peer in
1100 -> SockAddr 1101-- order to set up translating conduits that simulate a remote XMPP server.
1101 -> SockAddr 1102announceToxJabberPeer :: TChan ((ConnectionKey,SockAddr), Tcp.ConnectionEvent XML.Event)
1103 -> SockAddr -- ^ Local bind address for incoming Tox packets.
1104 -> SockAddr -- ^ Remote address for this connection.
1102 -> STM Bool 1105 -> STM Bool
1103 -> C.Source IO Tox.CryptoMessage 1106 -> C.Source IO Tox.CryptoMessage
1104 -> C.Sink (Flush Tox.CryptoMessage) IO () 1107 -> C.Sink (Flush Tox.CryptoMessage) IO ()
1105 -> IO (Maybe (Tox.NetCryptoSession -> Tox.NetCryptoSession)) 1108 -> IO (Maybe (Tox.NetCryptoSession -> Tox.NetCryptoSession))
1106announceToxXMPPClients echan laddr saddr pingflag tsrc tsnk 1109announceToxJabberPeer echan laddr saddr pingflag tsrc tsnk
1107 = do 1110 = do
1108 atomically $ writeTChan echan 1111 atomically $ writeTChan echan
1109 ( (PeerKey saddr, laddr ) 1112 ( (PeerKey saddr, laddr )
@@ -1430,18 +1433,20 @@ main = runResourceT $ liftBaseWith $ \resT -> do
1430 let Just pingMachine = Tox.ncPingMachine netcrypto 1433 let Just pingMachine = Tox.ncPingMachine netcrypto
1431 pingflag = readTVar (pingFlag pingMachine) 1434 pingflag = readTVar (pingFlag pingMachine)
1432 receiveCrypto = atomically $ readTMChan tmchan 1435 receiveCrypto = atomically $ readTMChan tmchan
1433 handleIncoming typ session cd | any ($ typ) [Tox.isKillPacket, Tox.isOFFLINE] = atomically $ do 1436#ifdef XMPP
1437 onEOF = return () -- TODO: Update toxContactInfo, not connected.
1438 xmppSrc = ioToSource receiveCrypto onEOF
1439 xmppSink = newXmmpSink netcrypto
1440 announceToxJabberPeer (xmppEventChannel sv) addrTox (Tox.ncSockAddr netcrypto) pingflag xmppSrc xmppSink
1441 -- TODO: Update toxContactInfo, connected.
1442#endif
1443 let handleIncoming typ session cd | any ($ typ) [Tox.isKillPacket, Tox.isOFFLINE] = atomically $ do
1434 closeTMChan tmchan 1444 closeTMChan tmchan
1435 Tox.forgetCrypto crypto netCryptoSessionsState netcrypto 1445 Tox.forgetCrypto crypto netCryptoSessionsState netcrypto
1436 return Nothing 1446 return Nothing
1437 handleIncoming mTyp session cd = do 1447 handleIncoming mTyp session cd = do
1438 atomically $ writeTMChan tmchan (Tox.bufferData cd) 1448 atomically $ writeTMChan tmchan (Tox.bufferData cd)
1439 return Nothing 1449 return Nothing
1440#ifdef XMPP
1441 xmppSrc = ioToSource receiveCrypto
1442 xmppSink = newXmmpSink netcrypto
1443 announceToxXMPPClients (xmppEventChannel sv) addrTox (Tox.ncSockAddr netcrypto) pingflag xmppSrc xmppSink
1444#endif
1445 atomically $ writeTVar (Tox.ncUnrecognizedHook netcrypto) handleIncoming 1450 atomically $ writeTVar (Tox.ncUnrecognizedHook netcrypto) handleIncoming
1446 return Nothing 1451 return Nothing
1447 1452