I have created torrent file on a small text file with parameters.
client.exe abc.txt -o abc.torrent -t http://MyIpv4:9090/ -l The code for creating torrent is same as in libtorrent-tutorial-make_torrent and then while starting the client I have set lt::settings_pack::broadcast_lsd to true as below
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);
}
Download torrent code:
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;
}
This code is working for public torrents. I have tested it by downloading a file from valid torrent file from one of the torrent websites.
On the same wifi network on another machine I am trying to download this torrent by passing magnet URI as below
magnet:?xt=urn:btih:<magnet_link_address>=abc.txt&tr=http%3a%2f%2f<IP_where_clinet_started>%3a9090%2f
Log for download
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 that in LAN I may have to turn on local peer discovery option and enable NAT-PMP/UPnP
Things I tried:
- set
lt::settings_pack::broadcast_lsdtotrue - Enable windows network discovery in Control Panel -> Network and Sharing -> Advanced Settings --> Public folder sharing = Yes
- Turned off firewall on the client machine completely
- added inbound rule for TCP and UDP for port 9090
- If create torrent with udp instead of http : On running download code from other machine I get
An address incompatible with the requested protocol was used.I can not fiddle with router settings as I dont have access to it.
I am able to run 2 peers on same network and send receive messages without this issue .
Is there a way I can overcome this error?
I did not have tracker set up. Added a tracker using opentracker and turned off firewall to allow connections. That solved the issue.