summaryrefslogtreecommitdiff
path: root/dht
diff options
context:
space:
mode:
Diffstat (limited to 'dht')
-rw-r--r--dht/examples/dhtd.hs4
-rw-r--r--dht/src/Network/BitTorrent/MainlineDHT.hs42
-rw-r--r--dht/src/Network/Tox.hs8
3 files changed, 31 insertions, 23 deletions
diff --git a/dht/examples/dhtd.hs b/dht/examples/dhtd.hs
index c7fd4f06..da73159d 100644
--- a/dht/examples/dhtd.hs
+++ b/dht/examples/dhtd.hs
@@ -1667,7 +1667,7 @@ main = do
1667 "" -> return (return (), Map.empty,return [],[]) 1667 "" -> return (return (), Map.empty,return [],[])
1668 p -> do 1668 p -> do
1669 addr <- getBindAddress p (ip6bt opts) 1669 addr <- getBindAddress p (ip6bt opts)
1670 (bt,btR,btBootstrap4, btBootstrap6) <- Mainline.newClient swarms addr 1670 (bt,btR,btBootstrap4, btBootstrap6,quitBtClient) <- Mainline.newClient swarms addr
1671 quitBt <- forkListener "bt" (clientNet bt) 1671 quitBt <- forkListener "bt" (clientNet bt)
1672 mainlineSearches <- atomically $ newTVar Map.empty 1672 mainlineSearches <- atomically $ newTVar Map.empty
1673 peerPort <- atomically $ newTVar 6881 -- BitTorrent client TCP port. 1673 peerPort <- atomically $ newTVar 6881 -- BitTorrent client TCP port.
@@ -1748,7 +1748,7 @@ main = do
1748 [ Mainline.routing4 btR 1748 [ Mainline.routing4 btR
1749 , Mainline.routing6 btR 1749 , Mainline.routing6 btR
1750 ] 1750 ]
1751 return (quitBt,dhts,ips, [addr]) 1751 return (quitBt >> quitBtClient,dhts,ips, [addr])
1752 1752
1753 keysdb <- Tox.newKeysDatabase 1753 keysdb <- Tox.newKeysDatabase
1754 1754
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 )
549newClient swarms addr = do 550newClient 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