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

Allow relay selector to filter daita enabled relays #6590

Merged

Conversation

rablador
Copy link
Contributor

@rablador rablador commented Aug 9, 2024

When DAITA is enabled, the relay selector should only match DAITA enabled relays for the entry location when using multihop. If no DAITA relays can be matched, the packet tunnel should enter the blocked state - ideally with an error message displayed to the user that makes it obvious that no relays were matched due to none of the eligible ones allowing DAITA.

When using single-hop and DAITA is enabled only DAITA enabled relays should be considered first - the best suitable DAITA relay should be picked if at all possible. Otherwise, if the exit constraints do not match any DAITA enabled relay, the relay selector should use multihop to select a valid DAITA relay for the entry.


This change is Reviewable

@rablador rablador added the iOS Issues related to iOS label Aug 9, 2024
@rablador rablador self-assigned this Aug 9, 2024
Copy link

linear bot commented Aug 9, 2024

@rablador rablador changed the title Allow relay selector to filter daita enabled relays ios 772 Allow relay selector to filter daita enabled relays Aug 9, 2024
@rablador rablador force-pushed the allow-relay-selector-to-filter-daita-enabled-relays-ios-772 branch 2 times, most recently from 603515b to c65edb4 Compare August 9, 2024 12:31
@rablador rablador force-pushed the allow-relay-selector-to-filter-daita-enabled-relays-ios-772 branch 11 times, most recently from adf5fe4 to a4c4cbe Compare August 15, 2024 12:09
@rablador rablador marked this pull request as ready for review August 15, 2024 12:09
Copy link
Contributor

@acb-mv acb-mv left a comment

Choose a reason for hiding this comment

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

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


ios/MullvadREST/ApiHandlers/ServerRelaysResponse.swift line 37 at r1 (raw file):

        public let weight: UInt64
        public let includeInCountry: Bool
        public var daita: Bool?

Wouldn't a statement such as hasDAITA be a clearer name?


ios/MullvadREST/Relay/AnyRelay.swift line 20 at r1 (raw file):

    var active: Bool { get }
    var includeInCountry: Bool { get }
    var daita: Bool? { get }

Wouldn't a statement such as hasDAITA be a clearer name?

Copy link
Contributor Author

@rablador rablador 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 26 files reviewed, 2 unresolved discussions (waiting on @acb-mv)


ios/MullvadREST/ApiHandlers/ServerRelaysResponse.swift line 37 at r1 (raw file):

Previously, acb-mv wrote…

Wouldn't a statement such as hasDAITA be a clearer name?

I agree, but that's the name we get from the servers. We could have custom coding keys, but it feels like more work than it's worth.

Copy link
Contributor

@acb-mv acb-mv left a comment

Choose a reason for hiding this comment

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

:lgtm:

Reviewable status: 1 of 26 files reviewed, all discussions resolved

Copy link
Contributor

@buggmagnet buggmagnet left a comment

Choose a reason for hiding this comment

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

Reviewed 26 of 26 files at r1, all commit messages.
Reviewable status: all files reviewed, 5 unresolved discussions (waiting on @rablador)


ios/MullvadREST/Relay/NoRelaysSatisfyingConstraintsError.swift line 15 at r1 (raw file):

    case invalidPort
    case multihopEntryEqualsExit
    case multihopOther

Can we find a better name for this ? Maybe multihopInvalidFlow ?


ios/MullvadREST/Relay/NoRelaysSatisfyingConstraintsError.swift line 25 at r1 (raw file):

    public var errorDescription: String? {
        "No relays satisfying constraints."

Since we log this, it would be interesting to improve this error message and see why we threw the error.

    public var errorDescription: String? {
        switch reason {
        case .filterConstraintNotMatching:
            "No relays satisfying constraints."
        case .invalidPort:
            "Invalid port selected by RelaySelector"
        case .multihopEntryEqualsExit:
            "Entry hop and Exit hop are the same"
        case .multihopOther:
            "Invalid multihop decision flow"
        case .noActiveRelaysFound:
            "No active relays found"
        case .noDaitaRelaysFound:
            "No Daita relays found"
        case .relayConstraintNotMatching:
            "Invalid constraint created to pick a relay"
        }
    }

ios/MullvadVPN/Notifications/Notification Providers/TunnelStatusNotificationProvider.swift line 242 at r1 (raw file):

            errorString = "No servers match your location filter. Try changing filter settings."
        case .multihopEntryEqualsExit:
            errorString = "The entry and exit server cannot be the same. Try changing one to a new server or location."

The entry and exit servers cannot be the same.


ios/MullvadVPN/SimulatorTunnelProvider/SimulatorTunnelProviderManager.swift line 175 at r1 (raw file):

    override func isEqual(_ object: Any?) -> Bool {
        guard let multihopOther = object as? Self else { return false }
        return self.identifier == multihopOther.identifier

Did you accidentally rename this ?


ios/MullvadVPNTests/MullvadREST/Relay/RelayPickingTests.swift line 76 at r1 (raw file):

            XCTAssertEqual(error?.reason, .multihopEntryEqualsExit)
        }
    }

Shouldn't we have a test for the noDaitaRelaysFound single picker case ?

Copy link
Collaborator

@mojganii mojganii 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, 7 unresolved discussions (waiting on @buggmagnet and @rablador)


ios/MullvadREST/Relay/NoRelaysSatisfyingConstraintsError.swift line 14 at r1 (raw file):

    case filterConstraintNotMatching
    case invalidPort
    case multihopEntryEqualsExit

I suggest to eliminate multihop keyword, what do you think about relaysAreEqual.


ios/MullvadVPNTests/MullvadREST/Relay/RelayPickingTests.swift line 27 at r1 (raw file):

        let picker = SinglehopPicker(
            constraints: constraints,
            daitaSettings: DAITASettings(state: .off),

let's call them with the default value when the test isn't around DaitaSettings. if we set default value to on in the future, we will need to update these tests either.

Code snippet:

 daitaSettings: DAITASettings()

ios/MullvadVPNTests/MullvadREST/Relay/RelayPickingTests.swift line 76 at r1 (raw file):

Previously, buggmagnet wrote…

Shouldn't we have a test for the noDaitaRelaysFound single picker case ?

+1

@rablador rablador force-pushed the allow-relay-selector-to-filter-daita-enabled-relays-ios-772 branch from a4c4cbe to 039c2ef Compare August 19, 2024 09:19
Copy link
Contributor Author

@rablador rablador 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: 20 of 26 files reviewed, 7 unresolved discussions (waiting on @buggmagnet and @mojganii)


ios/MullvadREST/Relay/NoRelaysSatisfyingConstraintsError.swift line 14 at r1 (raw file):

Previously, mojganii wrote…

I suggest to eliminate multihop keyword, what do you think about relaysAreEqual.

Opting to keep entry and exit in the wording to more clearly convey what's going on.


ios/MullvadREST/Relay/NoRelaysSatisfyingConstraintsError.swift line 15 at r1 (raw file):

Previously, buggmagnet wrote…

Can we find a better name for this ? Maybe multihopInvalidFlow ?

Done.


ios/MullvadREST/Relay/NoRelaysSatisfyingConstraintsError.swift line 25 at r1 (raw file):

Previously, buggmagnet wrote…

Since we log this, it would be interesting to improve this error message and see why we threw the error.

    public var errorDescription: String? {
        switch reason {
        case .filterConstraintNotMatching:
            "No relays satisfying constraints."
        case .invalidPort:
            "Invalid port selected by RelaySelector"
        case .multihopEntryEqualsExit:
            "Entry hop and Exit hop are the same"
        case .multihopOther:
            "Invalid multihop decision flow"
        case .noActiveRelaysFound:
            "No active relays found"
        case .noDaitaRelaysFound:
            "No Daita relays found"
        case .relayConstraintNotMatching:
            "Invalid constraint created to pick a relay"
        }
    }

Done.


ios/MullvadVPN/Notifications/Notification Providers/TunnelStatusNotificationProvider.swift line 242 at r1 (raw file):

Previously, buggmagnet wrote…

The entry and exit servers cannot be the same.

Done.


ios/MullvadVPNTests/MullvadREST/Relay/RelayPickingTests.swift line 27 at r1 (raw file):

Previously, mojganii wrote…

let's call them with the default value when the test isn't around DaitaSettings. if we set default value to on in the future, we will need to update these tests either.

With the current test setup (and sample relays) we will get a .noDaitaRelaysFound error instead. I specifically want DAITA to be off here so that we test only entry and exit error and don't involve DAITA at all, even if it's default in the app or not.


ios/MullvadVPNTests/MullvadREST/Relay/RelayPickingTests.swift line 76 at r1 (raw file):

Previously, mojganii wrote…

+1

RelayPicking protocol is concerned with multihop and makes sure the picking of one-one, one-many, many-many relationsships work correctly. A DAITA specific test already exists in RelaySelectorTests.testRelayWithDaita.


ios/MullvadVPN/SimulatorTunnelProvider/SimulatorTunnelProviderManager.swift line 175 at r1 (raw file):

Previously, buggmagnet wrote…

Did you accidentally rename this ?

Yes, fixed.

@rablador rablador force-pushed the allow-relay-selector-to-filter-daita-enabled-relays-ios-772 branch 2 times, most recently from 5cd5d21 to 5d337df Compare August 19, 2024 09:26
Copy link
Contributor

@buggmagnet buggmagnet 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 6 of 6 files at r2, all commit messages.
Reviewable status: all files reviewed, 3 unresolved discussions (waiting on @mojganii)

Copy link
Collaborator

@mojganii mojganii 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, 1 unresolved discussion (waiting on @buggmagnet)

@buggmagnet buggmagnet force-pushed the allow-relay-selector-to-filter-daita-enabled-relays-ios-772 branch from 5d337df to b5baa95 Compare August 21, 2024 09:34
@buggmagnet buggmagnet merged commit 6b0bb52 into main Aug 21, 2024
7 of 9 checks passed
@buggmagnet buggmagnet deleted the allow-relay-selector-to-filter-daita-enabled-relays-ios-772 branch August 21, 2024 09:37
Copy link

🚨 End to end tests failed. Please check the failed workflow run.

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

Successfully merging this pull request may close these issues.

4 participants