alanmcgovern / monotorrent

The official repository for MonoTorrent, a bittorrent library for .NET

Home Page:https://github.com/alanmcgovern/monotorrent

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

How to enable Ipv6 connections?

ycy1164656 opened this issue · comments

commented

Could you please tell me if there is a switch setting to enable ipv6 connections?

commented

I assume that

uri = new Uri ($"{(socket.AddressFamily == AddressFamily.InterNetwork ? "ipv4" : "ipv6") }://{endpoint.Address}{':'}{endpoint.Port}");
in src/MonoTorrent.Connections/MonoTorrent.Connections.Peer/SocketPeerConnection.cs

should be like this

uri = socket.AddressFamily == AddressFamily.InterNetwork ? new Uri($"ipv4://{endpoint.Address}{':'}{endpoint.Port}") : new Uri ($"ipv6://[{endpoint.Address}]{':'}{endpoint.Port}");
maybe?

commented

also in monotorrent/src/MonoTorrent/MonoTorrent.Client.Connections/IPV6Connection.cs

Uri = new Uri ($"ipv6://{endpoint.Address}{':'}{endpoint.Port}");

should add a []

Yeah, that sounds about right. Urgh!

I'll see if I can fix this up properly, and validate ipv6 actually works end-to-end using an IPV6 enabled EC2 instance or something, before shipping 3.0.0 stable.

Unfortunately I'm still ipv4 only with my home connection.

commented

After I changed

public static IPeerListener CreateTcp (int port) { return CreateTcp (IPAddress.Any, port); }
to
public static IPeerListener CreateTcp (int port) { return CreateTcp (IPAddress.IPv6Any, port); }
in PeerListenerFactory.cs

and

var connectionUri = new Uri ($"ipv4://{dict["ip"]}:{dict["port"]}");

to

var connectionUri = new Uri ($"ipv6://[{dict["ip"]}]:{dict["port"]}");

in Peer.cs ,line 189

now I can find other ipv6 peers and attempt to connect,

but all the ipv6 peers connection end with handshakefailed,

I can download from other ipv6 peer, but can not upload data to other ipv6 peer

Could you please tell me if I'm missing some key codes for connection?

Thanks a lot

Can you disable encryption by setting EngineSettings.AllowedEncryption to a list/array which contains EncryptionType.PlainText?

If that doesn't work, can you add a logger right at the start, before you begin using MonoTorrents apis, and share the logs created by it?

LoggerFactory.Register (className => new TextLogger (Console.Out, className));

It might make it easier to see what's happening.

ipv6_working

I tested things on my local network and MonoTorrent can establish an IPv6 connection to qBittorrent (which uses libtorrent under the hood).

If you want to submit a PR containing the changes you've suggested i'd be happy to merge it in. Otherwise I'll try to integrate those suggestions, and find other places where ipv6 addresses are improperly handled, and then merge the changes. So far it looks like the only change I need to make in order to have things work is to use the fully qualifyed IPV6 address (with square brackets).

My simple test was to just do this:

await manager.StartAsync ();
await Task.Delay (1000);
await Engine.Torrents[0].AddPeerAsync (new PeerInfo (new Uri ("ipv6://[fe80::46dc:9b3d:bc61:79a7%7]:9253"), ""));

This allowed monotorrent to establish an IPV6 connection to the client listening at that address.

There are a few things I need to update to fully support ipv6. I'll track those here: #588

This support will be added to the 3.x branch, but won't be backported to the 2.x stable release as 3.x is pretty close to done and I'd rather implement and test these changes once. It'll be awkward to test without having an actual ipv6 connection.

If you'd like to test out these capabilities as they're implemented, just let me know by saying it in the issue #588 and i can ping when things are ready! Thanks for highlighting that this support is incomplete.