diff options
author | Joe Crayne <joe@jerkface.net> | 2019-10-18 06:48:47 -0400 |
---|---|---|
committer | Joe Crayne <joe@jerkface.net> | 2020-01-01 19:56:02 -0500 |
commit | 687e06b39529bef04ecd49fc5e5b1b502a41b28d (patch) | |
tree | 3bdd94d8338c11d842f9d6ae466ca4fa780998bc /dht/src/Network | |
parent | 6e618ac54384be5ef5f2590fd2a8cc2eb8399361 (diff) |
More thread cleanup.
Diffstat (limited to 'dht/src/Network')
-rw-r--r-- | dht/src/Network/BitTorrent/MainlineDHT.hs | 42 | ||||
-rw-r--r-- | dht/src/Network/Tox.hs | 8 |
2 files changed, 29 insertions, 21 deletions
diff --git a/dht/src/Network/BitTorrent/MainlineDHT.hs b/dht/src/Network/BitTorrent/MainlineDHT.hs index 89851e88..af618ba4 100644 --- a/dht/src/Network/BitTorrent/MainlineDHT.hs +++ b/dht/src/Network/BitTorrent/MainlineDHT.hs | |||
@@ -545,6 +545,7 @@ newClient :: SwarmsDatabase -> SockAddr | |||
545 | , Routing | 545 | , Routing |
546 | , [NodeInfo] -> [NodeInfo] -> IO () | 546 | , [NodeInfo] -> [NodeInfo] -> IO () |
547 | , [NodeInfo] -> [NodeInfo] -> IO () | 547 | , [NodeInfo] -> [NodeInfo] -> IO () |
548 | , IO () | ||
548 | ) | 549 | ) |
549 | newClient swarms addr = do | 550 | newClient swarms addr = do |
550 | udp <- udpTransport addr | 551 | udp <- udpTransport addr |
@@ -577,7 +578,7 @@ newClient swarms addr = do | |||
577 | (mkNodeInfo nid a) | 578 | (mkNodeInfo nid a) |
578 | (R.defaultBucketCount) | 579 | (R.defaultBucketCount) |
579 | writeTVar tblvar tbl | 580 | writeTVar tblvar tbl |
580 | writeTChan addrvar (a,map fst $ concat $ R.toList bkts) | 581 | writeTChan addrvar $ Just (a,map fst $ concat $ R.toList bkts) |
581 | Nothing -> return () | 582 | Nothing -> return () |
582 | committee4 <- newTriadCommittee $ updateIPVote tbl4 addr4 | 583 | committee4 <- newTriadCommittee $ updateIPVote tbl4 addr4 |
583 | committee6 <- newTriadCommittee $ updateIPVote tbl6 addr6 | 584 | committee6 <- newTriadCommittee $ updateIPVote tbl6 addr6 |
@@ -633,26 +634,26 @@ newClient swarms addr = do | |||
633 | , clientResponseId = return | 634 | , clientResponseId = return |
634 | } | 635 | } |
635 | 636 | ||
636 | -- TODO: Provide some means of shutting down these five auxillary threads: | ||
637 | |||
638 | fork $ fix $ \again -> do | 637 | fork $ fix $ \again -> do |
639 | myThreadId >>= flip labelThread "addr4" | 638 | myThreadId >>= flip labelThread "addr4" |
640 | (addr, ns) <- atomically $ readTChan addr4 | 639 | x <- atomically (readTChan addr4) |
641 | dput XBitTorrent $ "External IPv4: "++show (addr, length ns) | 640 | forM_ x $ \(addr, ns) -> do |
642 | forM_ ns $ \n -> do | 641 | dput XBitTorrent $ "External IPv4: "++show (addr, length ns) |
643 | dput XBitTorrent $ "Change IP, ping: "++show n | 642 | forM_ ns $ \n -> do |
644 | ping outgoingClient n | 643 | dput XBitTorrent $ "Change IP, ping: "++show n |
645 | -- TODO: trigger bootstrap ipv4 | 644 | ping outgoingClient n |
646 | again | 645 | -- TODO: trigger bootstrap ipv4 |
646 | again | ||
647 | fork $ fix $ \again -> do | 647 | fork $ fix $ \again -> do |
648 | myThreadId >>= flip labelThread "addr6" | 648 | myThreadId >>= flip labelThread "addr6" |
649 | (addr,ns) <- atomically $ readTChan addr6 | 649 | x <- atomically (readTChan addr6) |
650 | dput XBitTorrent $ "External IPv6: "++show (addr, length ns) | 650 | forM_ x $ \(addr,ns) -> do |
651 | forM_ ns $ \n -> do | 651 | dput XBitTorrent $ "External IPv6: "++show (addr, length ns) |
652 | dput XBitTorrent $ "Change IP, ping: "++show n | 652 | forM_ ns $ \n -> do |
653 | ping outgoingClient n | 653 | dput XBitTorrent $ "Change IP, ping: "++show n |
654 | -- TODO: trigger bootstrap ipv6 | 654 | ping outgoingClient n |
655 | again | 655 | -- TODO: trigger bootstrap ipv6 |
656 | again | ||
656 | 657 | ||
657 | 658 | ||
658 | refresh_thread4 <- forkPollForRefresh $ refresher4 routing | 659 | refresh_thread4 <- forkPollForRefresh $ refresher4 routing |
@@ -660,7 +661,12 @@ newClient swarms addr = do | |||
660 | 661 | ||
661 | forkAnnouncedInfohashesGC (contactInfo swarms) | 662 | forkAnnouncedInfohashesGC (contactInfo swarms) |
662 | 663 | ||
663 | return (client, routing, bootstrap (refresher4 routing), bootstrap (refresher6 routing)) | 664 | return (client, routing, bootstrap (refresher4 routing), bootstrap (refresher6 routing) |
665 | , do killThread refresh_thread4 -- TODO: Better termination mechanism. | ||
666 | killThread refresh_thread6 -- TODO: Better termination mechanism. | ||
667 | atomically $ writeTChan addr4 Nothing -- Terminate "addr4" thread. | ||
668 | atomically $ writeTChan addr6 Nothing -- Terminate "addr6" thread. | ||
669 | ) | ||
664 | 670 | ||
665 | -- Note that you should call .put() every hour for content that you want to | 671 | -- Note that you should call .put() every hour for content that you want to |
666 | -- keep alive, since nodes may discard data nodes older than 2 hours. (source: | 672 | -- keep alive, since nodes may discard data nodes older than 2 hours. (source: |
diff --git a/dht/src/Network/Tox.hs b/dht/src/Network/Tox.hs index 98c03b80..b396c2ea 100644 --- a/dht/src/Network/Tox.hs +++ b/dht/src/Network/Tox.hs | |||
@@ -414,9 +414,9 @@ forkTox tox with_avahi = do | |||
414 | quitDHT <- forkListener "toxDHT" (clientNet $ toxDHT tox) | 414 | quitDHT <- forkListener "toxDHT" (clientNet $ toxDHT tox) |
415 | quitNC <- forkListener "toxCrypto" (toxCrypto tox) | 415 | quitNC <- forkListener "toxCrypto" (toxCrypto tox) |
416 | quitTCP <- forkListener "relay-client" (clientNet $ tcpClient $ tcpKademliaClient $ toxOnionRoutes tox) | 416 | quitTCP <- forkListener "relay-client" (clientNet $ tcpClient $ tcpKademliaClient $ toxOnionRoutes tox) |
417 | refresher4 <- forkPollForRefresh (DHT.refresher4 $ toxRouting tox) | ||
418 | refresher6 <- forkPollForRefresh (DHT.refresher6 $ toxRouting tox) | ||
417 | quitAvahi <- if with_avahi then do | 419 | quitAvahi <- if with_avahi then do |
418 | forkPollForRefresh (DHT.refresher4 $ toxRouting tox) | ||
419 | forkPollForRefresh (DHT.refresher6 $ toxRouting tox) | ||
420 | dnssdIn <- forkIO $ queryToxService (dnssdDiscover tox) | 420 | dnssdIn <- forkIO $ queryToxService (dnssdDiscover tox) |
421 | dnssdOut <- forkIO $ dnssdAnnounce tox | 421 | dnssdOut <- forkIO $ dnssdAnnounce tox |
422 | labelThread dnssdIn "tox-avahi-monitor" | 422 | labelThread dnssdIn "tox-avahi-monitor" |
@@ -424,7 +424,9 @@ forkTox tox with_avahi = do | |||
424 | return $ forM_ [dnssdIn,dnssdOut] killThread | 424 | return $ forM_ [dnssdIn,dnssdOut] killThread |
425 | else return $ return () | 425 | else return $ return () |
426 | keygc <- Onion.forkAnnouncedKeysGC (toxAnnouncedKeys tox) | 426 | keygc <- Onion.forkAnnouncedKeysGC (toxAnnouncedKeys tox) |
427 | return ( do quitAvahi | 427 | return ( do killThread refresher4 |
428 | killThread refresher6 | ||
429 | quitAvahi | ||
428 | killThread keygc | 430 | killThread keygc |
429 | quitNC | 431 | quitNC |
430 | quitDHT | 432 | quitDHT |