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

Fix vpn client #901

Merged
merged 19 commits into from
Oct 6, 2021
Merged

Fix vpn client #901

merged 19 commits into from
Oct 6, 2021

Conversation

ersonp
Copy link
Contributor

@ersonp ersonp commented Sep 30, 2021

Did you run make format && make check?
yes

Fixes #783
Fixes #900

Changes:

  • Vpn retirer only trys 3 times
  • Added errors from server hello to retire whitelist
  • Removed conSummarry check in AppStates()
  • Added new app state AppStatusErrored : "status": 2 which gives the error inside detailed_status
  • Added a transport check before dailing routes adapted from here
  • Added RPCErr to preserve the type of the error we return via RPC (as suggested by @alexadhy)

How to test this PR:
Test #783

  1. Run visorA with VPN server and passcode
  2. Run visorB create a transport to vpn-server and connect to Vpn-server of visor A with the wrong passcode.
  3. Visor won't retry after the first try.
  4. Check http://localhost:8000/api/visors/<pk>/summary and see if vpn-client has
{
  "name": "vpn-client",
  "args": [
    "-srv",
    "02d27b250feea1fc2fca518baff5eb30df0d77d43fd2cc323d1a25be6ce3abc7be"
  ],
  "auto_start": false,
  "port": 43,
  "status": 2,
  "detailed_status": "Password didn't match"
}

Test #900

  1. Run visorB without creating a transport to vpn-server and connect to Vpn-server of visor A.
  2. Visor won't retry after the first try.
  3. Check http://localhost:8000/api/visors/<pk>/summary and see if vpn-client has
{
  "name": "vpn-client",
  "args": [
    "-srv",
    "02d27b250feea1fc2fca518baff5eb30df0d77d43fd2cc323d1a25be6ce3abc7be"
  ],
  "auto_start": false,
  "port": 43,
  "status": 2,
  "detailed_status": "transport not found"
}

We update the retirer to not retry till success anymore. We only retry three times.
We whitelist errors sent from server hello as it's pointless to retry.
The commit contains changes to the logic of AppStates(). We are removing the connection summary check as whenever a vpn-client gets an error it closes all the connections to retry again. Because of this even when the vpn-client is still running AppStates() gives the app status for vpn-client as stopped. Insted depending on ProcByName() is sufficient.
The commit contains additions to the proc and rpc code. The addition is of the app status AppStatusErrored that is set if there is an entry in statusErr which is set if the app encounters an error and stops. A . The commit only makes required changes in vpn-client to set the error.
This commit contains updates to MockRPCIngressClient after the changes to RPCIngressClient in previous commit. The code was auto generated via mockery.
This commit contains nolint:errcheck wherever the return value from a func was not checked to suppress warnings.
This commit removes log that was used for testing.
@ersonp ersonp marked this pull request as ready for review October 4, 2021 10:33
@alexadhy
Copy link
Contributor

alexadhy commented Oct 4, 2021

CMIIW, I actually think that the DetailedStatus can be better with it being a struct containing the actual status of the running application (the enums like the current one in develop, as well as the current error description like the one you have). Can be beneficial also for tests.

So we can eliminate SetDetailedStatusError and instead just use the SetDetailedStatus for everything.

@ersonp
Copy link
Contributor Author

ersonp commented Oct 4, 2021

SetDetailedStatusError and SetDetailedStatus are separate because both of them are stored and fetched from different places, i.e. detailed_status is fetched from proc whereas the error is fetched from procManager as the proc is deleted when the app stops after an error. But I think it would be better to just have SetDetailedStatus just like you have suggested.

The commit changes SetDetailedStatusError to SetError as it was confusing and SetError is nore consise and accurate.
@ersonp
Copy link
Contributor Author

ersonp commented Oct 4, 2021

@alexadhy I went through the code again and removing SetDetailedStatusError would make the code needlessly complex so instead renamed all instances of SetDetailedStatusError to SetError which is more precise and easy to understand.

Copy link
Member

@jdknives jdknives left a comment

Choose a reason for hiding this comment

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

Just a few questions from my end. It seems like there may be a better way to handle processes so we do not need to set status and errors separately but its not the task of the PR to rewrite the whole library. So apart from the questions this looks good.

internal/vpn/client.go Show resolved Hide resolved
internal/vpn/client.go Outdated Show resolved Hide resolved
internal/vpn/client.go Outdated Show resolved Hide resolved
internal/vpn/handshake_status.go Outdated Show resolved Hide resolved
internal/vpn/handshake_status.go Show resolved Hide resolved
pkg/visor/api.go Outdated Show resolved Hide resolved
The commit contains a transport check in vpn-client. Before dialing the routes the available transports to the server are checked. If there is none then we send a ErrTransportNotFound. ErrTransportNotFound is whitelisted in the dail retrier.
The commit contains updated error for unknown code, aErr changed to appErr, removed switch statements and whitelisted ErrTransportNotFound in main retrier.
@ersonp
Copy link
Contributor Author

ersonp commented Oct 5, 2021

Should I add a max no of retries to the retrier of dialServer too?

The commit removes the retrier in dialServer as it's redundant and the same job can be done by the main retrier.
The commit adds RPCErr struct that is used to preserve the type of the error from RPC. Currelty only the err of Dial() is wrapped with it.
Copy link
Contributor

@mrpalide mrpalide left a comment

Choose a reason for hiding this comment

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

Functionality work as well as possible, and code was clear, and just one little comment.

internal/vpn/client.go Outdated Show resolved Hide resolved
pkg/router/router.go Outdated Show resolved Hide resolved
The commit updates the checkIfTransportAvalailable to check if any transports are established for the visor and not if there is a transport between local and remote visor. checkIfTransportAvalailable also sends a new error ErrNoTransportFound if no transports are established for the visor.

Both ErrTransportNotFound and ErrNoTransportFound are whitelisted as ErrTransportNotFound is received from router whenever it is unsuccessful at creating a route to the remote visor..
The commit changes the lock in SetError() from RLock to Lock.
@jdknives jdknives merged commit 63b29ae into skycoin:develop Oct 6, 2021
@ersonp ersonp deleted the fix/vpn-client branch April 11, 2022 15:39
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.

4 participants