-2

パラメータ付きの小さなテキストファイルにトレントファイルを作成しました。 client.exe abc.txt -o abc.torrent -t http://MyIpv4:9090/ -ltorrent を作成するためのコードは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 で機能しています。トレント Web サイトの 1 つから有効なトレント ファイルからファイルをダウンロードしてテストしました。

別のマシンの同じwifiネットワークで、以下のようにマグネットURIを渡してこのトレントをダウンロードしようとしています

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)

この質問から、LAN ではローカル ピア検出オプションをオンにし、NAT-PMP/UPnP を有効にする必要がある場合があること を知りました。

私が試したこと:

  • lt::settings_pack::broadcast_lsdに設定true
  • [コントロール パネル] -> [ネットワークと共有] -> [詳細設定] -> [パブリック フォルダーの共有] = [はい] で Windows ネットワーク検出を有効にします。
  • クライアント マシンのファイアウォールを完全にオフにしました
  • ポート 9090 の TCP および UDP のインバウンド規則を追加
  • http の代わりに udp を使用して torrent を作成する場合: 他のマシンからダウンロード コードを実行する An address incompatible with the requested protocol was used. と、ルーターの設定にアクセスできないため、ルーターの設定をいじることができません。

同じネットワーク上で 2 つのピアを実行し、この問題なしで受信メッセージを送信できます。

このエラーを克服する方法はありますか?

4

1 に答える 1