arvidn / libtorrent

an efficient feature complete C++ bittorrent implementation
http://libtorrent.org
Other
5.25k stars 996 forks source link

I2P support #2530

Closed ghost closed 1 year ago

ghost commented 7 years ago

libtorrent version: 1.1.1.0 platform/architecture: Ubuntu 17.10

Hey, i am just curious what is the status of the I2P support. The documentation about this feature is a little bit light right now. In particular i am not sure where i do mistake in the following python code:

import libtorrent as lt session = lt.session(flags=0) h = session.add_torrent({'ti': lt.torrent_info('/tmp/Downloads/test.torrent'), 'save_path': '/tmp/Downloads'})

session.listen_on(6881, 6881)

proxy_settings = lt.proxy_settings() proxy_settings.hostname = '127.0.0.1' proxy_settings.port = 7656 session.set_i2p_proxy(proxy_settings)

The program doesnot download anything and cannot find peers(the i2pshark do it very fast). Please help me to figure out what is going on. Am i right that libtorrent use SAM interface, so i should use port 7656?

ivan1986 commented 2 years ago

@cathalgarvey and get funny messages from VPS provider - stop use torrents or we stop you VPS

master255 commented 2 years ago

@ivan1986

And what for we need dht requests without the download data?

The DHT query itself only returns a list of peers. It does not give out your IP address in any way. And you can use these peers as https url seeds.

This is how it usually happens now - copyright holders download the file, record all IP addresses in the swarm and then send notifications to providers.

Your ip address will not be in swarm. You just downloaded the file from url-seed. You can do it without torrents at all. With a normal https request in your browser.

@cathalgarvey

This isn't about being as fast as clearnet - it's about keeping valuable torrents alive, safely. Think investigative journalism archives or insurance files or large leaks from somewhere like Saudi, or Russia. Webseeds are not the answer to keeping this stuff safely online. i2p torrents could be.

I don't believe anyone can distribute content and never be detected. I think only an anonymous computer on the Internet can do that. As long as someone doesn't find it and turn it off. Even the i2p network will not give complete anonymity. According to research it only gives basic anonymity which helps to avoid fines for watching pirated movies. I haven't fully researched ssl torrents yet, but I think what you are looking for doesn't exist.

TomasGlgg commented 2 years ago

@master255

According to research it only gives basic anonymity which helps to avoid fines for watching pirated movies.

Show the research, please

master255 commented 2 years ago

@TomasGlgg https://xakep.ru/2014/09/04/i2p-secrets/

TomasGlgg commented 2 years ago

@master255

https://xakep.ru/2014/09/04/i2p-secrets/

Lol, this article was written by the developer of I2Pd, all the problems mentioned in it have been fixed for a long time.

TomasGlgg commented 2 years ago

@master255 I advise you to read more relevant information: https://habr.com/ru/post/554062/ And as a bonus: https://habr.com/ru/post/570128/

master255 commented 2 years ago

@TomasGlgg @cathalgarvey Torrents are decentralized. If everyone distributes content and it cannot be traced and blocked (as in Url-seeds), that would mean complete anonymity for the source? Otherwise, if you want to distribute content anonymously alone, there are many more ways to do it without torrents. The main question is, if you are alone, why do you need torrents? After all, torrents are needed to distribute the load when downloading data.

TomasGlgg commented 2 years ago

@master255

The main question is, if you are alone, why do you need torrents?

Are we alone? Have you seen the statistics of the local tracker in I2P?

arvidn commented 2 years ago

it seems this thread is drifting a bit off-topic.

libtorrent (used to) support i2p via its SAM bridge (which on the libtorrent side is configured as a kind of proxy). There are no tests for this unfortunately, so it's possible it has bit rotted a bit.

If the SAM protocol has changed in the last 10 years, that would also explain it.

absolutep commented 2 years ago

If the SAM protocol has changed in the last 10 years, that would also explain it.

Yes, It has changed. https://geti2p.net/en/docs/api/samv3

Also, I2P is updated to newer version - https://geti2p.net/en/blog/post/2022/2/21/1.7.0-Release

Update - https://geti2p.net/en/docs/applications/bittorrent

Here's the reason, with screenshots, why I am asking for this specific request - https://github.com/qbittorrent/qBittorrent/issues/16257

Superfly-Johnson commented 2 years ago

It may be possible to design unit tests using libi2pd. Unfortunately the process is totally undocumented...

absolutep commented 2 years ago

UPDATE AS OF JUNE 2022

SAM version 3 = https://geti2p.net/en/docs/api/samv3

Also, I2P is updated to newer version - https://geti2p.net/en/blog/post/2022/5/23/1.8.0-Release

Update - https://geti2p.net/en/docs/applications/bittorrent

New UDP protocol introduced in i2p 1.8.0 called SSU = https://geti2p.net/en/docs/transport/ssu

Specs of the proposal = https://geti2p.net/spec/proposals/159-ssu2

more information on this is present in release data of 1.8.0 (provided above)

Here's the reason, with screenshots, why I am asking for this specific request - qbittorrent/qBittorrent#16257

ghost commented 2 years ago

A seedbox is just a VPS with bittorrent on it. There are services providing these as a servuce.

There are many data centres in the world and not all care about bittorrent. If you buy budget, they are often underpricing traffic so they get annoyed if you actually use the traffic. Other datacentres or products will care less, unless your torrenting lands them in legal hot water. (that is, copyright - the branch of law that most frequently causes them headaches)

All the more reason to support properly anonymous torrenting, then.

That's not to say it would be wholly benign - it's good that ISPs and datacentres and VPNs can come after you if you are sharing actually evil content. But the motivation for i2p is about avoiding mass surveillance and tyrrany, and webseeds have literally no serious role there.

master255 commented 2 years ago

@cathalgarvey I was recently in USA. They sell any sim cards without a passport. Torrents work great in them. So which countries have problems?

Mexico sells any sim cards without a passport too. Directly from official stores.

ri-gilfanov commented 2 years ago

@master255, buying a SIM card without person identification is already difficult in China, Germany, Poland, Russia, Spain and other countries. This can create problems with the law for the seller.

Besides. Mobile devices usually transfer their serial number to mobile operators. Therefore the simple replacement of the SIM card does not give anonymity.

You might think that there is a workaround. For example, you buy a new device, and then persuade a homeless person to buy you a SIM card in his name. Homeless people usually do not refuse money and alcohol. But there is another problem.

The location of the mobile device can be found using triangulation. This is usually enough to find a pirate or a dissident. If the city recognition system has been introduced in the city, then calculating the senders and recipients of Internet traffic is even easier.

Sorry for my google translate.

master255 commented 2 years ago

@ri-gilfanov There's a firewall in China. In Russia, anonymous SIM cards are sold and torrents are not banned by ISPs. That only leaves some European countries.

It is possible, at best, to calculate the location of base stations with the accuracy of the house. But not to the apartment where you live.

Imei can be changed with full rights on the device (super user).

That is why torrents are still anonymous everywhere except in some European countries and China.

ivan1986 commented 2 years ago

Guys, just add support with the option to turn it on and off, you don’t need to decide legal and other issues for the user, who needs to turn it on, who doesn’t need to turn it off

ri-gilfanov commented 2 years ago

I have to agree with @ivan1986. Talking about the legal risks of users is beyond the scope of the topic.

@master255, I will point out one thing. The Bittorrent protocol works best with a static IP address.

The anonymous I2P network provide an anonymous alternative to the static IP address in the clearnet.

jiigen commented 1 year ago

any progress on this topic? I2P has gained more attention lately and would be great to be able to use libtorrent with it. Libtorrent would be the perfect companion for i2pd ( the c++ i2p router implementation) since so far the only way for torrenting on i2p for i2pd users is using a java client like Vuze, BiglyBT or the standalone i2psnark. There's a golang client too but doesn't seem to be in active development. Fixing libtorrent i2p support would let very popular clients like qbittorrent and deluge to use i2p.

absolutep commented 1 year ago

Update on I2P side as of December 2022.

SAM has been upgraded.

SSU2 has been launched.

I2P itself upgraded to 2.0

I2P router upgraded to 0.9.56

only way for torrenting on i2p for i2pd users is using a java client like Vuze, BiglyBT

Very soon Vuze won't work cause approximately 50% of all I2P network is upgrading to 2.0 & 0.9.56. I suggest BiglyBT because it is regularly maintained.

Fixing libtorrent i2p support would let very popular clients like qbittorrent and deluge to use i2p.

100%. I want qBittorrent to work flawlessly with I2P or atleast have an inbuilt router just like BiglyBT has.

Vort commented 1 year ago

I tested I2P support today.

Versions:

Settings: Proxy type I2P, address 127.0.0.1, port 7656

Result: Torrent client establishes connection to 127.0.0.1:7656, then following conversation happens:

HELLO VERSION MIN=3.0 MAX=3.0
HELLO REPLY RESULT=OK VERSION=3.0

Then torrent client closes connection and writes i2p_alert: i2p_error: [i2p error] parse failed error into log file.

I don't know how it is possible to fail parsing of such simple message, but library fails to do this.

Vort commented 1 year ago

I decided to test with libtorrent directly and to use latest version.

Build command is something like that: g++ -I../libtorrent/include libtorrent_test.cpp -L../libtorrent/build -ltorrent-rasterbar -lws2_32 -static-libgcc -static-libstdc++ -Wl,-Bstatic -lpthread -Wl,-Bdynamic -o libtorrent_test.exe Execute command is like that: ./libtorrent_test.exe Source code is combination of

include <libtorrent/session.hpp>

include <libtorrent/session_params.hpp>

include <libtorrent/add_torrent_params.hpp>

include <libtorrent/torrent_handle.hpp>

include <libtorrent/alert_types.hpp>

include <libtorrent/magnet_uri.hpp>

int main(int argc, char const argv[]) try { const char magnet = "magnet:?xt=urn:btih:cb18974db461c640c0d938710203bb263a746694" "&dn=I2P%2B+Universal+Installer+2.0.0%2B" "&tr=http://tracker2.postman.i2p/announce.php"; lt::settings_pack p;

p.set_str(lt::settings_pack::listen_interfaces, "0.0.0.0:6881"); p.set_int(lt::settings_pack::proxy_type, lt::settings_pack::i2p_proxy); p.set_int(lt::settings_pack::i2p_port, 7656); p.set_str(lt::settings_pack::i2p_hostname, "127.0.0.1"); p.set_bool(lt::settings_pack::enable_upnp, false); p.set_bool(lt::settings_pack::enable_natpmp, false); p.set_bool(lt::settings_pack::enable_dht, false);

p.set_int(lt::settings_pack::alert_mask, lt::alert_category::status | lt::alert_category::error); lt::session ses(p);

lt::add_torrent_params atp = lt::parse_magnet_uri(magnet); 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; } catch (std::exception& e) { std::cerr << "Error: " << e.what() << std::endl; }


Result is the same `[I2P] parse failed` error along with many others:
```text
successfully listening on [uTP] 0.0.0.0:6881
I2P+ Universal Installer 2.0.0+ added
I2P+ Universal Installer 2.0.0+: state changed to: dl metadata
added torrent: I2P+ Universal Installer 2.0.0+
i2p_error: [i2p error] parse failed
i2p_error: [system] Подключение к сети было разорвано локальной системой
i2p_error: [system] Предоставленный дескриптор файла неверен
i2p_error: [system] Предоставленный дескриптор файла неверен
i2p_error: [system] Предоставленный дескриптор файла неверен
i2p_error: [system] Предоставленный дескриптор файла неверен
i2p_error: [system] Предоставленный дескриптор файла неверен
i2p_error: [system] Предоставленный дескриптор файла неверен
i2p_error: [system] Предоставленный дескриптор файла неверен
i2p_error: [system] Предоставленный дескриптор файла неверен
i2p_error: [system] Предоставленный дескриптор файла неверен
i2p_error: [system] Предоставленный дескриптор файла неверен
i2p_error: [system] Предоставленный дескриптор файла неверен
i2p_error: [system] Предоставленный дескриптор файла неверен
i2p_error: [system] Предоставленный дескриптор файла неверен
i2p_error: [system] Предоставленный дескриптор файла неверен
i2p_error: [system] Предоставленный дескриптор файла неверен
i2p_error: [system] Предоставленный дескриптор файла неверен
i2p_error: [system] Предоставленный дескриптор файла неверен
i2p_error: [system] Предоставленный дескриптор файла неверен
i2p_error: [system] Предоставленный дескриптор файла неверен
listening on 0.0.0.0:0 (device: i2p) failed: [sock_accept] [I2P] parse failed
listening on 0.0.0.0:0 (device: i2p) failed: [sock_accept] [I2P] Подключение к сети было разорвано локальной системой
listening on 0.0.0.0:0 (device: i2p) failed: [sock_accept] [I2P] Предоставленный дескриптор файла неверен
listening on 0.0.0.0:0 (device: i2p) failed: [sock_accept] [I2P] Предоставленный дескриптор файла неверен
listening on 0.0.0.0:0 (device: i2p) failed: [sock_accept] [I2P] Предоставленный дескриптор файла неверен
listening on 0.0.0.0:0 (device: i2p) failed: [sock_accept] [I2P] Предоставленный дескриптор файла неверен
listening on 0.0.0.0:0 (device: i2p) failed: [sock_accept] [I2P] Предоставленный дескриптор файла неверен
listening on 0.0.0.0:0 (device: i2p) failed: [sock_accept] [I2P] Предоставленный дескриптор файла неверен
listening on 0.0.0.0:0 (device: i2p) failed: [sock_accept] [I2P] Предоставленный дескриптор файла неверен
listening on 0.0.0.0:0 (device: i2p) failed: [sock_accept] [I2P] Предоставленный дескриптор файла неверен
listening on 0.0.0.0:0 (device: i2p) failed: [sock_accept] [I2P] Предоставленный дескриптор файла неверен
listening on 0.0.0.0:0 (device: i2p) failed: [sock_accept] [I2P] Предоставленный дескриптор файла неверен
listening on 0.0.0.0:0 (device: i2p) failed: [sock_accept] [I2P] Предоставленный дескриптор файла неверен
listening on 0.0.0.0:0 (device: i2p) failed: [sock_accept] [I2P] Предоставленный дескриптор файла неверен
listening on 0.0.0.0:0 (device: i2p) failed: [sock_accept] [I2P] Предоставленный дескриптор файла неверен
listening on 0.0.0.0:0 (device: i2p) failed: [sock_accept] [I2P] Предоставленный дескриптор файла неверен
listening on 0.0.0.0:0 (device: i2p) failed: [sock_accept] [I2P] Предоставленный дескриптор файла неверен
listening on 0.0.0.0:0 (device: i2p) failed: [sock_accept] [I2P] Предоставленный дескриптор файла неверен
listening on 0.0.0.0:0 (device: i2p) failed: [sock_accept] [I2P] Предоставленный дескриптор файла неверен
listening on 0.0.0.0:0 (device: i2p) failed: [sock_accept] [I2P] Предоставленный дескриптор файла неверен
listening on 0.0.0.0:0 (device: i2p) failed: [sock_accept] [I2P] Предоставленный дескриптор файла неверен
I2P+ Universal Installer 2.0.0+ resumed
I2P+ Universal Installer 2.0.0+ (http://tracker2.postman.i2p/announce.php)[0.0.0.0:6881] v1  "Waiting for i2p acceptor from SAM bridge" (1)
I2P+ Universal Installer 2.0.0+ (http://tracker2.postman.i2p/announce.php)[0.0.0.0:6881] v1  "Waiting for i2p acceptor from SAM bridge" (2)
I2P+ Universal Installer 2.0.0+ (http://tracker2.postman.i2p/announce.php)[0.0.0.0:6881] v1  "Waiting for i2p acceptor from SAM bridge" (3)
Vort commented 1 year ago

Looks like something wrong happened in 2019. In commit 23730776adc078c9b9f4b7b14672fcbfad4e966f i2p_stream::read_line function was moved from i2p_stream.cpp to i2p_stream.hpp and during that process extra block of code was added. When I removed it: https://github.com/arvidn/libtorrent/blob/690881fec9cc069976cd3d909254a87c22f43ce0/include/libtorrent/i2p_stream.hpp#L235-L238 SAM connection process went further and SAM session was created. It still failed at the end (when tested with i2pd 2.45.0):

$ ./libtorrent_test.exe
successfully listening on [uTP] 0.0.0.0:6881
I2P+ Universal Installer 2.0.0+ added
I2P+ Universal Installer 2.0.0+: state changed to: dl metadata
added torrent: I2P+ Universal Installer 2.0.0+
I2P+ Universal Installer 2.0.0+ resumed
I2P+ Universal Installer 2.0.0+ (http://tracker2.postman.i2p/announce.php)[0.0.0.0:6881] v1  "Waiting for i2p acceptor from SAM bridge" (1)
I2P+ Universal Installer 2.0.0+ (http://tracker2.postman.i2p/announce.php)[0.0.0.0:6881] v1  "Waiting for i2p acceptor from SAM bridge" (2)
listening on 0.0.0.0:0 (device: i2p) failed: [sock_accept] [I2P] unknown error
I2P+ Universal Installer 2.0.0+ (http://tracker2.postman.i2p/announce.php)[0.0.0.0:6881] v1 Этот хост неизвестен "" (3)
I2P+ Universal Installer 2.0.0+ (http://tracker2.postman.i2p/announce.php)[0.0.0.0:6881] v1 Этот хост неизвестен "" (4)
I2P+ Universal Installer 2.0.0+ (http://tracker2.postman.i2p/announce.php)[0.0.0.0:6881] v1 Этот хост неизвестен "" (5)

But I think it is still important to fix support at least partially. @arvidn please check mentioned commit and look if that code block is really needed there.


upd. listening on 0.0.0.0:0 (device: i2p) failed: [sock_accept] [I2P] unknown error happens because remaining variable includes null character here: https://github.com/arvidn/libtorrent/blob/690881fec9cc069976cd3d909254a87c22f43ce0/include/libtorrent/i2p_stream.hpp#L285 And sometimes this check fails because "OK" != "OK\0" here: https://github.com/arvidn/libtorrent/blob/690881fec9cc069976cd3d909254a87c22f43ce0/include/libtorrent/i2p_stream.hpp#L309 So that line, probably, should look like: string_view remaining(m_buffer.data(), m_buffer.size() - 1);

Vort commented 1 year ago

Most likely, #7272 solved problems described in this bugreport. I think that now it is better to create new reports with freshly found problems than putting all information in single issue.

arvidn commented 1 year ago

addressed here: https://github.com/arvidn/libtorrent/pull/7356