【问题标题】:Libtorrent:Download-Connection could not be made because the target machine actively refused itLibtorrent:Download-Connection could not be made because the target machine主动拒绝它
【发布时间】:2019-12-07 05:01:21
【问题描述】:

我在一个带有参数的小文本文件上创建了 torrent 文件。 client.exe abc.txt -o abc.torrent -t http://MyIpv4:9090/ -l 创建种子的代码与libtorrent-tutorial-make_torrent 相同,然后在启动客户端时我将lt::settings_pack::broadcast_lsd 设置为true,如下所示

void t_client_class::start_client(string torrent_file_name)
{
    lt::settings_pack sp;
    sp.set_bool(lt::settings_pack::broadcast_lsd, true);
    lt::session s(sp);

    lt::add_torrent_params p;
    p.save_path = "./";
    p.ti = std::make_shared<lt::torrent_info>(torrent_file_name);
    s.add_torrent(p);

}

下载种子代码:

bool t_client_class::download_torrent(string magnet_uri)
{
    lt::settings_pack p;
    p.set_int(lt::settings_pack::alert_mask, lt::alert::status_notification
              | lt::alert::error_notification  );
    p.set_bool(lt::settings_pack::broadcast_lsd, true);
    lt::session ses(p);



    lt::add_torrent_params atp = lt::parse_magnet_uri(magnet_uri);
    atp.save_path = "."; // save in current dir
    lt::torrent_handle h = ses.add_torrent(std::move(atp));

    for (;;)
    {
        std::vector<lt::alert*> alerts;
        ses.pop_alerts(&alerts);

        for (lt::alert const* a : alerts)
        {
            std::cout << a->message() << std::endl;
            // if we receive the finished alert or an error, we're done
            if (lt::alert_cast<lt::torrent_finished_alert>(a))
            {
                goto done;
            }
            if (lt::alert_cast<lt::torrent_error_alert>(a))
            {
                goto done;
            }
        }
        std::this_thread::sleep_for(std::chrono::milliseconds(200));
    }
done:
    std::cout << "done, shutting down" << std::endl;
    return true;
}

此代码适用于公共种子。我已经通过从其中一个 torrent 网站下载有效 torrent 文件中的文件对其进行了测试。

在另一台机器上的同一个 wifi 网络上,我试图通过传递下面的磁铁 URI 来下载这个 torrent

magnet:?xt=urn:btih:<magnet_link_address>=abc.txt&tr=http%3a%2f%2f<IP_where_clinet_started>%3a9090%2f

下载日志

successfully listening on [TCP] 0.0.0.0:6881
successfully listening on [UDP] 0.0.0.0:6881
successfully listening on [TCP] [current_device_mac]:6881
successfully listening on [UDP] [current_device_mac]:6881
successfully listening on [TCP] [current_device_mac_2]:6881
successfully listening on [UDP] [current_device_mac_2]:6881
added torrent: abc.txt
abc.txt: state changed to: dl metadata
abc.txt resumed
abc.txt (http://MyIpv4:9090/)[[current_device_mac]:6881] Unknown error "" (1)
abc.txt (http://MyIpv4:9090/)[[current_device_mac_2]:6881] Unknown error "" (1)
abc.txt (http://MyIpv4:9090/)[0.0.0.0:6881] No connection could be made because the target machine actively refused it "" (1)
abc.txt (http://MyIpv4:9090/)[[current_device_mac]:6881] Unknown error "" (2)
abc.txt (http://MyIpv4:9090/)[[current_device_mac_2]:6881] Unknown error "" (2)
abc.txt (http://MyIpv4:9090/)[0.0.0.0:6881] No connection could be made because the target machine actively refused it "" (2)

I got to know from this question 在局域网中我可能必须打开本地对等点发现选项并启用 NAT-PMP/UPnP

我尝试过的事情:

  • lt::settings_pack::broadcast_lsd 设置为true
  • 在控制面板->网络和共享->高级设置-->公用文件夹共享中启用windows网络发现=是
  • 完全关闭客户端计算机上的防火墙
  • 为端口 9090 添加了 TCP 和 UDP 的入站规则
  • 如果使用 udp 而不是 http 创建 torrent:在从其他机器运行下载代码时,我得到 An address incompatible with the requested protocol was used. 我无法修改路由器设置,因为我无权访问它。

我能够在同一网络上运行 2 个对等点并发送接收消息而不会出现此问题。

有没有办法克服这个错误?

【问题讨论】:

    标签: c++ c++17 libtorrent libtorrent-rasterbar


    【解决方案1】:

    我没有设置跟踪器。添加了一个使用opentracker 的跟踪器并关闭了防火墙以允许连接。这样就解决了问题。

    【讨论】:

      猜你喜欢
      • 2020-07-05
      • 2016-07-25
      • 1970-01-01
      • 2018-01-22
      • 2022-01-23
      • 2019-02-01
      • 2018-12-16
      • 2018-11-02
      • 2020-12-11
      相关资源
      最近更新 更多