summaryrefslogtreecommitdiff
path: root/src/Network/Tox.hs
diff options
context:
space:
mode:
Diffstat (limited to 'src/Network/Tox.hs')
-rw-r--r--src/Network/Tox.hs22
1 files changed, 19 insertions, 3 deletions
diff --git a/src/Network/Tox.hs b/src/Network/Tox.hs
index cebbebfb..26488657 100644
--- a/src/Network/Tox.hs
+++ b/src/Network/Tox.hs
@@ -354,6 +354,18 @@ getOnionAlias crypto dhtself remoteNode = atomically $ do
354 _ -> ni { nodeId = key2id (onionAliasPublic crypto) } 354 _ -> ni { nodeId = key2id (onionAliasPublic crypto) }
355 return $ Onion.OnionDestination Onion.SearchingAlias alias Nothing 355 return $ Onion.OnionDestination Onion.SearchingAlias alias Nothing
356 356
357mkDefaultDestroyHook :: ContactInfo extra -> NetCryptoSession -> IO ()
358mkDefaultDestroyHook roster = \session -> do
359 now <- getPOSIXTime
360 r <- atomically $ do
361 accounts <- readTVar (accounts roster) -- :: STM (HashMap NodeId (Account extra)
362 let mbAccount = HashMap.lookup (key2id $ ncMyPublicKey session) accounts -- :: STM (Maybe (Account extra)
363 case mbAccount of
364 Just account -> Right <$> setTerminated now (ncTheirPublicKey session) account
365 Nothing -> return . Left $ "(defaultDestroyHook) their is no account! pubkey=" ++ show (key2id (ncTheirPublicKey session))
366 case r of
367 Left msg -> dput XMan msg
368 _ -> return ()
357 369
358newTox :: TVar Onion.AnnouncedKeys -- ^ Store of announced keys we are a rendezvous for. 370newTox :: TVar Onion.AnnouncedKeys -- ^ Store of announced keys we are a rendezvous for.
359 -> SockAddr -- ^ Bind-address to listen on. 371 -> SockAddr -- ^ Bind-address to listen on.
@@ -362,14 +374,18 @@ newTox :: TVar Onion.AnnouncedKeys -- ^ Store of announced keys we are a rende
362 -> IO (Tox extra) 374 -> IO (Tox extra)
363newTox keydb addr mbSessionsState suppliedDHTKey = do 375newTox keydb addr mbSessionsState suppliedDHTKey = do
364 (udp,sock) <- {- addVerbosity <$> -} udpTransport' addr 376 (udp,sock) <- {- addVerbosity <$> -} udpTransport' addr
377 roster <- newContactInfo
365 (crypto0,sessionsState0) <- case mbSessionsState of 378 (crypto0,sessionsState0) <- case mbSessionsState of
366 Nothing -> do 379 Nothing -> do
367 crypto <- newCrypto 380 crypto <- newCrypto
368 sessionsState <- newSessionsState crypto defaultUnRecHook defaultCryptoDataHooks 381 sessionsState <- newSessionsState crypto (mkDefaultDestroyHook roster) defaultUnRecHook defaultCryptoDataHooks
369 return (crypto,sessionsState) 382 return (crypto,sessionsState)
370 Just s -> return (transportCrypto s, s) 383 Just s -> do
384 let oldhook = defaultDestroyHook s
385 oldhook' = filter ((==0) . fst) oldhook
386 newhook = (0,mkDefaultDestroyHook roster):oldhook'
387 return (transportCrypto s, s { defaultDestroyHook = newhook})
371 388
372 roster <- newContactInfo
373 let -- patch in supplied DHT key 389 let -- patch in supplied DHT key
374 crypto1 = fromMaybe crypto0 $do 390 crypto1 = fromMaybe crypto0 $do
375 k <- suppliedDHTKey 391 k <- suppliedDHTKey