diff options
Diffstat (limited to 'dht/examples/dhtd.hs')
-rw-r--r-- | dht/examples/dhtd.hs | 19 |
1 files changed, 13 insertions, 6 deletions
diff --git a/dht/examples/dhtd.hs b/dht/examples/dhtd.hs index f4d04761..de315e35 100644 --- a/dht/examples/dhtd.hs +++ b/dht/examples/dhtd.hs | |||
@@ -1326,17 +1326,24 @@ onNewToxSession :: (IO () -> STM ()) | |||
1326 | -> Tox.Session | 1326 | -> Tox.Session |
1327 | -> IO () | 1327 | -> IO () |
1328 | onNewToxSession runio sv ssvar invc ContactInfo{accounts} addrTox netcrypto = do | 1328 | onNewToxSession runio sv ssvar invc ContactInfo{accounts} addrTox netcrypto = do |
1329 | dput XMan "onNewToxSession" | ||
1329 | let them s = Tox.longTermKey $ runIdentity cookie -- remote tox key | 1330 | let them s = Tox.longTermKey $ runIdentity cookie -- remote tox key |
1330 | where Tox.Cookie _ cookie = Tox.handshakeCookie (sReceivedHandshake s) | 1331 | where Tox.Cookie _ cookie = Tox.handshakeCookie (sReceivedHandshake s) |
1331 | 1332 | ||
1332 | me s = toPublic $ sOurKey s | 1333 | me s = toPublic $ sOurKey s |
1333 | 1334 | ||
1334 | onStatusChange :: (Tox.Session -> Tcp.ConnectionEvent XML.Event -> STM ()) | 1335 | uniqkey <- xor24 <$> hash24 (them netcrypto) <*> hash24 (me netcrypto) |
1336 | |||
1337 | let onStatusChange :: (Tox.Session -> Tcp.ConnectionEvent XML.Event -> STM ()) | ||
1335 | -> AggregateSession -> Tox.Session -> Status Tox.ToxProgress -> STM () | 1338 | -> AggregateSession -> Tox.Session -> Status Tox.ToxProgress -> STM () |
1336 | onStatusChange announce c s Established = onConnect announce c s | 1339 | onStatusChange announce c s Established = onConnect announce c s |
1337 | onStatusChange announce _ s status = onEOF announce s status | 1340 | onStatusChange announce _ s status = onEOF announce s status |
1338 | 1341 | ||
1339 | onEOF announce s status = do | 1342 | onEOF announce s status = do |
1343 | case status of | ||
1344 | Dormant -> -- Dormant AggregateSession is useless, so discard it. | ||
1345 | modifyTVar' ssvar $ Map.delete uniqkey | ||
1346 | _ -> return () | ||
1340 | runio $ dput XMan $ "EOF(" ++ take 16 (showKey256 $ them s) ++ "): " ++ show status | 1347 | runio $ dput XMan $ "EOF(" ++ take 16 (showKey256 $ them s) ++ "): " ++ show status |
1341 | HashMap.lookup (Tox.key2id $ me s) <$> readTVar accounts | 1348 | HashMap.lookup (Tox.key2id $ me s) <$> readTVar accounts |
1342 | >>= mapM_ (setTerminated $ them s) | 1349 | >>= mapM_ (setTerminated $ them s) |
@@ -1364,12 +1371,10 @@ onNewToxSession runio sv ssvar invc ContactInfo{accounts} addrTox netcrypto = do | |||
1364 | Chunk x -> Just (Nothing,x)) | 1371 | Chunk x -> Just (Nothing,x)) |
1365 | .| toxSnk | 1372 | .| toxSnk |
1366 | 1373 | ||
1367 | uniqkey <- xor24 <$> hash24 (them netcrypto) <*> hash24 (me netcrypto) | ||
1368 | |||
1369 | let me_dot_tox = xmppHostname $ me netcrypto | 1374 | let me_dot_tox = xmppHostname $ me netcrypto |
1370 | them_dot_tox = xmppHostname $ them netcrypto | 1375 | them_dot_tox = xmppHostname $ them netcrypto |
1371 | 1376 | ||
1372 | c <- atomically $ do | 1377 | c <- join $ atomically $ do |
1373 | mc <- Map.lookup uniqkey <$> readTVar ssvar | 1378 | mc <- Map.lookup uniqkey <$> readTVar ssvar |
1374 | case mc of | 1379 | case mc of |
1375 | Nothing -> do | 1380 | Nothing -> do |
@@ -1387,8 +1392,10 @@ onNewToxSession runio sv ssvar invc ContactInfo{accounts} addrTox netcrypto = do | |||
1387 | return $ \s e -> writeTChan (xmppEventChannel sv) ( (ck, condta s), e) | 1392 | return $ \s e -> writeTChan (xmppEventChannel sv) ( (ck, condta s), e) |
1388 | c <- newAggregateSession $ onStatusChange announce | 1393 | c <- newAggregateSession $ onStatusChange announce |
1389 | modifyTVar' ssvar $ Map.insert uniqkey c | 1394 | modifyTVar' ssvar $ Map.insert uniqkey c |
1390 | return c | 1395 | return $ do |
1391 | Just c -> return c | 1396 | dput XMan $ "New AggregateSession!" |
1397 | return c | ||
1398 | Just c -> return $ return c | ||
1392 | 1399 | ||
1393 | addSession c netcrypto | 1400 | addSession c netcrypto |
1394 | 1401 | ||