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

Put app in blocked state on tunnel start if relay constraints cannot be satisfied #5300

Conversation

rablador
Copy link
Contributor

@rablador rablador commented Oct 16, 2023

On tunnel start, if no valid relay can be selected app-side we let the packet tunnel take care of it instead. This will put the app in blocked state.

This PR takes care of issue the following issue as well:
https://linear.app/mullvad/issue/IOS-351/removing-relay-filters-does-not-exit-blocked-state


This change is Reviewable

@linear
Copy link

linear bot commented Oct 16, 2023

IOS-351 Removing Relay filters does not exit blocked state

See the attached slack discussion for the repro steps

@rablador rablador force-pushed the update-relay-list-view-to-allow-filtering-by-provider-ios-180 branch from 6f239a4 to eb69f11 Compare October 16, 2023 11:35
@rablador rablador force-pushed the removing-relay-filters-does-not-exit-blocked-state-ios-351 branch 2 times, most recently from 5594fc0 to 38931c5 Compare October 16, 2023 11:38
Copy link
Contributor

@pronebird pronebird 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 3 files at r1.
Reviewable status: 1 of 3 files reviewed, 2 unresolved discussions (waiting on @rablador)


ios/MullvadVPN/TunnelManager/StartTunnelOperation.swift line 69 at r1 (raw file):

            self.dispatchQueue.async {
                do {
                    try self.startTunnel(tunnel: try result.get())

Nit: AFAIK one try in front is enough as it implies try result.get() too.


ios/PacketTunnelCore/IPC/PacketTunnelOptions.swift line 43 at r1 (raw file):

    }

    public mutating func setSelectedRelay(_ value: SelectedRelay?) throws {

getSelectedRelay() will probably break because it decodes SelectedRelay.self. Instead you could omit encoding nil values altogether. Do not pass nil to indicate absence of value, instead avoid passing nil altogether.

Copy link
Contributor

@pronebird pronebird 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 3 files at r1.
Reviewable status: 2 of 3 files reviewed, 3 unresolved discussions (waiting on @rablador)


ios/MullvadVPN/TunnelManager/TunnelManager.swift line 213 at r1 (raw file):

            dispatchQueue: internalQueue,
            interactor: TunnelInteractorProxy(self),
            selectedRelay: try? selectRelay(),

Prefer to keep the actual work inside of operation body (main) and not outside to avoid working with stale data. For example relay constraints could be changed before StartTunnelOperation begins execution.

Copy link
Contributor

@pronebird pronebird 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 3 files at r1.
Reviewable status: all files reviewed, 3 unresolved discussions (waiting on @rablador)

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: all files reviewed, 2 unresolved discussions (waiting on @pronebird)


ios/MullvadVPN/TunnelManager/TunnelManager.swift line 213 at r1 (raw file):

Previously, pronebird (Andrej Mihajlov) wrote…

Prefer to keep the actual work inside of operation body (main) and not outside to avoid working with stale data. For example relay constraints could be changed before StartTunnelOperation begins execution.

Sounds right, on it.


ios/PacketTunnelCore/IPC/PacketTunnelOptions.swift line 43 at r1 (raw file):

Previously, pronebird (Andrej Mihajlov) wrote…

getSelectedRelay() will probably break because it decodes SelectedRelay.self. Instead you could omit encoding nil values altogether. Do not pass nil to indicate absence of value, instead avoid passing nil altogether.

Ah, yes, my bad. However, we do want to remove the value if there's no selected relay, right?

@rablador rablador force-pushed the removing-relay-filters-does-not-exit-blocked-state-ios-351 branch from 38931c5 to 5026c3c Compare October 16, 2023 13:51
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 3 files reviewed, 2 unresolved discussions (waiting on @pronebird)


ios/PacketTunnelCore/IPC/PacketTunnelOptions.swift line 43 at r1 (raw file):

Previously, rablador (Jon Petersson) wrote…

Ah, yes, my bad. However, we do want to remove the value if there's no selected relay, right?

My bad again. I just realised we creatre new PacketTunnelOptions before this call, so simply setting nothing is the way to go.

@rablador rablador force-pushed the removing-relay-filters-does-not-exit-blocked-state-ios-351 branch from 5026c3c to 00ae7c2 Compare October 16, 2023 13:59
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 all commit messages.
Reviewable status: 0 of 3 files reviewed, 3 unresolved discussions (waiting on @pronebird and @rablador)


ios/MullvadVPN/TunnelManager/StartTunnelOperation.swift line 76 at r2 (raw file):

    private func startTunnel(tunnel: Tunnel) throws {
        let selectedRelay = try? interactor.selectRelay()

Was there any reason to not use a more straightforward approach ?

    private func startTunnel(tunnel: Tunnel) throws {
        let selectedRelay = try interactor.selectRelay()
        var tunnelOptions = PacketTunnelOptions()

        try tunnelOptions.setSelectedRelay(selectedRelay)
        interactor.setTunnel(tunnel, shouldRefreshTunnelState: false)

        interactor.updateTunnelStatus { tunnelStatus in
            tunnelStatus = TunnelStatus()
            tunnelStatus.packetTunnelStatus.tunnelRelay = selectedRelay.packetTunnelRelay
            tunnelStatus.state = .connecting(selectedRelay.packetTunnelRelay)
        }

        try tunnel.start(options: tunnelOptions.rawOptions())
    }

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: 0 of 3 files reviewed, 2 unresolved discussions (waiting on @pronebird)


ios/MullvadVPN/TunnelManager/StartTunnelOperation.swift line 76 at r2 (raw file):

Previously, buggmagnet wrote…

Was there any reason to not use a more straightforward approach ?

    private func startTunnel(tunnel: Tunnel) throws {
        let selectedRelay = try interactor.selectRelay()
        var tunnelOptions = PacketTunnelOptions()

        try tunnelOptions.setSelectedRelay(selectedRelay)
        interactor.setTunnel(tunnel, shouldRefreshTunnelState: false)

        interactor.updateTunnelStatus { tunnelStatus in
            tunnelStatus = TunnelStatus()
            tunnelStatus.packetTunnelStatus.tunnelRelay = selectedRelay.packetTunnelRelay
            tunnelStatus.state = .connecting(selectedRelay.packetTunnelRelay)
        }

        try tunnel.start(options: tunnelOptions.rawOptions())
    }

As far as I understand, if interactor.selectRelay() throws we won't set up a tunnel and start it, which means we cannot enter a blocked state.

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.

Reviewable status: 0 of 3 files reviewed, 2 unresolved discussions (waiting on @pronebird)


ios/MullvadVPN/TunnelManager/StartTunnelOperation.swift line 76 at r2 (raw file):

Previously, rablador (Jon Petersson) wrote…

As far as I understand, if interactor.selectRelay() throws we won't set up a tunnel and start it, which means we cannot enter a blocked state.

Yeah I quickly realized what I wrote wouldn't work, so I deleted the comment... Too late !

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: 0 of 3 files reviewed, 2 unresolved discussions (waiting on @pronebird)


ios/MullvadVPN/TunnelManager/StartTunnelOperation.swift line 76 at r2 (raw file):

Previously, buggmagnet wrote…

Yeah I quickly realized what I wrote wouldn't work, so I deleted the comment... Too late !

It can never be unseen!

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 3 of 3 files at r2.
Reviewable status: all files reviewed, 2 unresolved discussions (waiting on @pronebird)

Copy link
Contributor

@pronebird pronebird 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 3 files at r2.
Reviewable status: :shipit: complete! all files reviewed, all discussions resolved


ios/PacketTunnelCore/IPC/PacketTunnelOptions.swift line 43 at r1 (raw file):

Previously, rablador (Jon Petersson) wrote…

My bad again. I just realised we creatre new PacketTunnelOptions before this call, so simply setting nothing is the way to go.

Correct.

Copy link
Contributor

@pronebird pronebird 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 2 of 3 files at r2.
Reviewable status: :shipit: complete! all files reviewed, all discussions resolved

@pronebird pronebird added the iOS Issues related to iOS label Oct 17, 2023
@buggmagnet buggmagnet merged commit 00ae7c2 into update-relay-list-view-to-allow-filtering-by-provider-ios-180 Oct 17, 2023
@buggmagnet buggmagnet deleted the removing-relay-filters-does-not-exit-blocked-state-ios-351 branch October 17, 2023 07:37
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.

3 participants