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

Clarify naming of variables in Socks5Local datastructures #5368

Merged
merged 2 commits into from
Nov 6, 2023

Conversation

MarkusPettersson98
Copy link
Contributor

@MarkusPettersson98 MarkusPettersson98 commented Oct 26, 2023

This change aims to make the intent of the different fields of the Socks5Local datastructures more clear


This change is Reviewable

Copy link
Member

@dlon dlon left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed 2 of 2 files at r1, all commit messages.
Reviewable status: all files reviewed, 1 unresolved discussion (waiting on @dlon)

@MarkusPettersson98 MarkusPettersson98 force-pushed the fix/rename-ip-and-port-socks5local branch from 06899ec to 7c24dfc Compare October 26, 2023 14:36
@MarkusPettersson98 MarkusPettersson98 changed the title Prefix ip and port with remote_ in Socks5Local protobuf message Prefix ip and port with remote_ in Socks5Local Oct 26, 2023
@MarkusPettersson98 MarkusPettersson98 changed the title Prefix ip and port with remote_ in Socks5Local Prefix ip and port with remote_ in Socks5Local datastructures Oct 26, 2023
Copy link
Contributor Author

@MarkusPettersson98 MarkusPettersson98 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewable status: 1 of 6 files reviewed, 1 unresolved discussion (waiting on @dlon and @faern)


mullvad-management-interface/src/types/conversions/access_method.rs line 223 at r1 (raw file):

Previously, faern (Linus Färnstrand) wrote…

I think peer here should also be renamed remote_peer. It's otherwise extremely easy to think that's where you connect to talk to the socks5, which is not actually the case. And port -> local_port, since we use that in other places. As soon as you have two of anything, you need to describe which one is for what. If Socks5Local only described how to connect to the socks5 server it would be fine to call the field port. But since it also has to contain more data, also containing ports, we should try to be more explicit IMO

I've attempted an exhaustive search+replace where Socks5Local pop up in order to apply the <remote|local>_-prefix naming scheme consistently. Please have a look 😊

@MarkusPettersson98 MarkusPettersson98 changed the title Prefix ip and port with remote_ in Socks5Local datastructures Clarify naming of variables in Socks5Local datastructures Oct 26, 2023
@dlon dlon requested a review from faern October 26, 2023 14:59
Copy link
Member

@dlon dlon left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed 5 of 5 files at r2, all commit messages.
Reviewable status: all files reviewed, 2 unresolved discussions (waiting on @faern and @MarkusPettersson98)


mullvad-types/src/access_method.rs line 271 at r2 (raw file):

    /// [`std::net::SocketAddr`] for you. If `remote_ip` or `remote_port` are
    /// valid [`Some(Socks5Local)`] is returned, otherwise [`None`].
    pub fn from_args(remote_ip: String, remote_port: u16, local_port: u16) -> Option<Self> {

Nit: I actually think this parsing doesn't belong here. This probably belongs in mullvad-management-interface

Copy link
Contributor Author

@MarkusPettersson98 MarkusPettersson98 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewable status: all files reviewed, 2 unresolved discussions (waiting on @dlon and @faern)


mullvad-types/src/access_method.rs line 271 at r2 (raw file):

Previously, dlon (David Lönnhager) wrote…

Nit: I actually think this parsing doesn't belong here. This probably belongs in mullvad-management-interface

I'll challenge this Nit by saying that this pattern shows up elsewhere, for example in talpid-core

pub struct Firewall {
pf: pfctl::PfCtl,
pf_was_enabled: Option<bool>,
rule_logging: RuleLogging,
}
impl Firewall {
pub fn from_args(_args: FirewallArguments) -> Result<Self> {
Self::new()
}
pub fn new() -> Result<Self> {
// Allows controlling whether firewall rules should log to pflog0. Useful for debugging the
// rules.
let firewall_debugging = env::var("TALPID_FIREWALL_DEBUG");
let rule_logging = match firewall_debugging.as_ref().map(String::as_str) {
Ok("pass") => RuleLogging::Pass,
Ok("drop") => RuleLogging::Drop,
Ok("all") => RuleLogging::All,
Ok(_) | Err(_) => RuleLogging::None,
};
log::trace!("Firewall debug log policy: {:?}", rule_logging);
Ok(Firewall {
pf: pfctl::PfCtl::new()?,
pf_was_enabled: None,
rule_logging,
})
}

Except that in the example, the semantics of new and from_args are swapped. In general, I think it is natural to keep constructors of types close to the type definition itself 😊

In the case of Socks5Local::from_args we are constructing the type Socks5Local from its parts, whereas I see it as conversions between equivalent (but different) types belong in mullvad-management-interface.

@MarkusPettersson98 MarkusPettersson98 force-pushed the fix/rename-ip-and-port-socks5local branch from efe1196 to 013b7a5 Compare October 27, 2023 13:05
Copy link
Member

@dlon dlon left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:lgtm:

Reviewed 3 of 3 files at r3, all commit messages.
Reviewable status: all files reviewed, 1 unresolved discussion (waiting on @faern)

@MarkusPettersson98 MarkusPettersson98 force-pushed the fix/rename-ip-and-port-socks5local branch from 013b7a5 to 6b831e2 Compare October 30, 2023 09:58
In particular, `access_methods::Socks5Local`,
`access_methods::Socks5Remote` & `access_methods::Shadowsocks` have got
new constructors which are all infallible.
@MarkusPettersson98 MarkusPettersson98 force-pushed the fix/rename-ip-and-port-socks5local branch from 6b831e2 to d1ac9a5 Compare November 6, 2023 08:01
Copy link
Member

@dlon dlon left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed 2 of 2 files at r4, all commit messages.
Reviewable status: all files reviewed, 1 unresolved discussion (waiting on @faern)

@MarkusPettersson98 MarkusPettersson98 merged commit bcca2f4 into main Nov 6, 2023
31 checks passed
@MarkusPettersson98 MarkusPettersson98 deleted the fix/rename-ip-and-port-socks5local branch November 6, 2023 08:31
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

Successfully merging this pull request may close these issues.

3 participants