Skip to content

Add an OrderedDictionary implementation for algorithm priorities #1611

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

Merged
merged 3 commits into from
Mar 25, 2025

Conversation

Rob-Hague
Copy link
Collaborator

During the key exchange, the algorithms to be used are chosen based on the order that the client sends: first algorithm is most desirable. Currently, the algorithm collections in ConnectionInfo are defined as IDictionary<,> and backed by Dictionary<,>, which does not have any guarantees on the order of enumeration (in practice, when only adding and not removing items it does enumerate in the order that items were added as an implementation detail, but it's not great to rely on it).

This change adds IOrderedDictionary<,> and uses it in ConnectionInfo. On .NET 9, this is backed by System.Collections.Generic.OrderedDictionary<,> and on lower targets, it uses a relatively simple implementation backed by a List and a Dictionary.

For example, to prioritise zlib compression over the default "none" compression:

using SshClient client = new(...);

client.ConnectionInfo.CompressionAlgorithms.SetPosition("[email protected]", 0);

closes #683
closes #719

During the key exchange, the algorithms to be used are chosen based on the order that
the client sends: first algorithm is most desirable. Currently, the algorithm
collections in ConnectionInfo are defined as IDictionary<,> and backed by
Dictionary<,>, which does not have any guarantees on the order of enumeration
(in practice, when only adding and not removing items it does enumerate in the order
that items were added as an implementation detail, but it's not great to rely on it).

This change adds IOrderedDictionary<,> and uses it in ConnectionInfo. On .NET 9,
this is backed by System.Collections.Generic.OrderedDictionary<,> and on lower
targets, it uses a relatively simple implementation backed by a List and a
Dictionary.
@Rob-Hague Rob-Hague merged commit 153b47d into sshnet:develop Mar 25, 2025
4 checks passed
@Rob-Hague Rob-Hague deleted the ordereddictionary branch March 25, 2025 13:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants