anacrolix / torrent

Full-featured BitTorrent client package and utilities
Mozilla Public License 2.0
5.39k stars 615 forks source link

WebRTC seed doesn't happen until client connects from same network #854

Open hayzamjs opened 11 months ago

hayzamjs commented 11 months ago

I'm using cmd/torrent by building it like this:

go build -o /tmp/torrent_cmd ./cmd/torrent

And then seeding a file like this:

/tmp/torrent_cmd serve /tmp/sintel.mp4

It starts up with a few messages :

(base) ┌─[me@pc]─[~/Projects/test]
└──╼ $/tmp/torrent_cmd serve /tmp/modded-sintel.mp4
"modded-sintel.mp4": magnet:?xt=urn:btih:237a8fecf92ce838b6706a0012e44f84a31b7232&dn=sintel.mp4&tr=wss%3A%2F%2F<my-tracker>
[2023-07-27 05:26:41 +0530  WRN] tracker client for "wss://<my-tracker>": unhandled announce response "{\"action\":\"announce\",\"complete\":1,\"incomplete\":0,\"info_hash\":\"#z\u008fìù,è8¶pj\\u0000\\u0012äO\u0084£\\u001br2\",\"interval\":120}" [github.com/anacrolix/torrent/webtorrent tracker-client.go:336]
[2023-07-27 05:27:13 +0530  WRN] tracker client for "wss://<my-tracker>": webrtc PeerConnection state changed to closed [github.com/anacrolix/torrent/webtorrent transport.go:73]

And continues to have messages like this:

[2023-07-27 05:27:13 +0530  WRN] tracker client for "wss://<my-tracker>": webrtc PeerConnection state changed to closed [github.com/anacrolix/torrent/webtorrent transport.go:73]
2023/07/27 05:27:28 context deadline exceeded
[2023-07-27 05:27:35 +0530  WRN] tracker client for "wss://<my-tracker>": webrtc PeerConnection state changed to closed [github.com/anacrolix/torrent/webtorrent transport.go:73]
2023/07/27 05:27:38 max retry time elapsed: rpc error: code = Unavailable desc = connection error: desc = "transport: Error while dialing dial tcp 127.0.0.1:4317: connect: connection refused"
[2023-07-27 05:27:47 +0530  WRN] tracker client for "wss://<my-tracker>": webrtc PeerConnection state changed to closed [github.com/anacrolix/torrent/webtorrent transport.go:73]
2023/07/27 05:27:48 max retry time elapsed: rpc error: code = Unavailable desc = connection error: desc = "transport: Error while dialing dial tcp 127.0.0.1:4317: connect: connection refused"
[2023-07-27 05:29:10 +0530  WRN] tracker client for "wss://<my-tracker>": webrtc PeerConnection state changed to closed [github.com/anacrolix/torrent/webtorrent transport.go:73]
2023/07/27 05:29:13 max retry time elapsed: rpc error: code = Unavailable desc = connection error: desc = "transport: Error while dialing dial tcp 127.0.0.1:4317: connect: connection refused"

And I'm unable to stream the video file from a remote PC using instant.io or any other webtorrent client. But the catch is.. the moment I start playing the same video (with the same magnet) on my PC (the same PC as the one that is seeding the torrent) everything is fine and all the peers get the video stream..

I have tried both the reference bittorrent-tracker as well as the openwebtorrent tracker, both of them show the same issue

EDIT: I also just tested webtorrent's desktop client and there too there's the same issue (with the same tracker), public trackers also have the same issue so I don't think it's that, is this something that is isolated to my PC/network or is it a known thing with the protocol, some pointers in the right direction would be super helpful!

anacrolix commented 11 months ago

I'm not very strong with WebRTC concepts, but it sounds very much like there's an issue with seeding over WebRTC from your network. If you are unable to seed with other WebRTC BitTorrent clients too, this seems like the logical answer.

hayzamjs commented 11 months ago

Thank you for the quick response. I tried seeding from a VPS with firewall turned off and a static IPv4/IPv6 directly attached to and I have pretty much the same results, didn't test with webtorrent desktop yet (probably have to try with webtorrent-hybrid)

Also are those connection closed messages normal?

anacrolix commented 11 months ago

I'll check when I get time. They should be normal, the logging levels might just be off.

amaghzaz-y commented 10 months ago

@hayzamjs I think you need to use WebTorrent-hybrid to make a bridge between webrtc peers and bittorrent peers, and also use the webtorrent tracker. they have a simple tool on their website called Webtorrent desktop, you can use that as a bridge to test the connectivity since it supports both protocols.

anacrolix commented 10 months ago

Thanks for the insight @AMAGHZAZ-Y. I believe anacrolix/torrent classifies as a hybrid client, but I don't know if that helps here.

anacrolix commented 8 months ago

I'm not going to have time for this. If anyone wants to take it. go for it.