diff options
Diffstat (limited to 'dht/src/Network/BitTorrent/MainlineDHT.hs')
-rw-r--r-- | dht/src/Network/BitTorrent/MainlineDHT.hs | 42 |
1 files changed, 24 insertions, 18 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: |