Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

only v6 seem not working [3.0.2 nuget] #705

Open
uponatime2019 opened this issue Nov 4, 2024 · 0 comments
Open

only v6 seem not working [3.0.2 nuget] #705

uponatime2019 opened this issue Nov 4, 2024 · 0 comments

Comments

@uponatime2019
Copy link

I have vps with both ipv4 and ipv6, but seem when set v6 only, it's still use ipv4 for download

my code

   listenEndpoints = new Dictionary<string, IPEndPoint>
                            { { "ipv6", new IPEndPoint(IPAddress.IPv6Any, MySettings.Data.TorrentPort) } };
                settingBuilder.ListenEndPoints = listenEndpoints;

count v4 and v6 connection

private int countV4 = 0;
        private int countV6 = 0;
        private readonly HashSet<string> activePeers = new HashSet<string>();

        void AddConnectionTypeCount(TorrentManager manager)
        {
            manager.PeerConnected += (o1, e1) =>
            {
                string peerAddress = e1.Peer.Uri.ToString();

                lock (activePeers)
                {
                    if (!activePeers.Contains(peerAddress))
                    {
                        activePeers.Add(peerAddress);

                        if (e1.Peer.Uri.HostNameType == UriHostNameType.IPv4)
                        {
                            countV4++;
                        }
                        else if (e1.Peer.Uri.HostNameType == UriHostNameType.IPv6)
                        {
                            countV6++;
                        }
                    }
                }
            };

            manager.PeerDisconnected += (o1, e1) =>
            {
                string peerAddress = e1.Peer.Uri.ToString();

                lock (activePeers)
                {
                    if (activePeers.Contains(peerAddress))
                    {
                        activePeers.Remove(peerAddress);

                        if (e1.Peer.Uri.HostNameType == UriHostNameType.IPv4 && countV4 > 0)
                        {
                            countV4--;
                        }
                        else if (e1.Peer.Uri.HostNameType == UriHostNameType.IPv6 && countV6 > 0)
                        {
                            countV6--;
                        }
                    }
                }
            };
        }

Result: v6 usually = 0, v4 count > 0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant