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

Initialize state machine on handlerAdded #43

Merged
merged 1 commit into from
Sep 7, 2020
Merged

Initialize state machine on handlerAdded #43

merged 1 commit into from
Sep 7, 2020

Conversation

artemredkin
Copy link
Contributor

Motivation:
Sometimes we already have an established channel, for example,
one returned by establishing a tunneled connection. If this
is the case, then we cannot use it to start key exchange, since
it's only started when channel becomes active. In order to
support more use cases we should handle starting key exchange
when handler is added as well.

Modifications:

  1. Extract key exchange initialization to separate function
  2. Call it from handlerAdded if channel is active
  3. Guard againts calling it twice

Result:
Fixes #42

@swift-server-bot
Copy link

Can one of the admins verify this patch?

3 similar comments
@swift-server-bot
Copy link

Can one of the admins verify this patch?

@swift-server-bot
Copy link

Can one of the admins verify this patch?

@swift-server-bot
Copy link

Can one of the admins verify this patch?

@Lukasa Lukasa added the patch-version-bump-only For PRs that when merged will only cause a bump of the patch version, ie. 1.0.x -> 1.0.(x+1) label Aug 28, 2020
Copy link
Collaborator

@Lukasa Lukasa left a comment

Choose a reason for hiding this comment

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

One minor note about the implementation but it otherwise looks good. I'd love to see a test as well here.

@@ -48,6 +48,9 @@ public final class NIOSSHHandler {
// Whether we're expecting a channelReadComplete.
private var expectingChannelReadComplete: Bool = false

// Whether the state machine execution started.
private var initialized: Bool = false
Copy link
Collaborator

Choose a reason for hiding this comment

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

I don't think we need this: we can just remove the crash from SSHConnectionStateMachine.start() and have that method return nil instead.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

👍

Copy link
Collaborator

@Lukasa Lukasa left a comment

Choose a reason for hiding this comment

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

Cool, approach looks good. If we get our tests we're good to go.

Motivation:
Sometimes we already have an established channel, for example,
one returned by establishing a tunneled connection. If this
is the case, then we cannot use it to start key exchange, since
it's only started when channel becomes active. In order to
support more use cases we should handle starting key exchange
when handler is added as well.

Modifications:
1. Extract key exchange initialization to separate function
2. Call it from handlerAdded if channel is active
3. Guard againts calling it twice

Result:
Fixes #42
@artemredkin
Copy link
Contributor Author

@Lukasa done, btw, could you whitelist me so I can start tests?

@Lukasa
Copy link
Collaborator

Lukasa commented Sep 7, 2020

@swift-server-bot add to whitelist

Copy link
Collaborator

@Lukasa Lukasa left a comment

Choose a reason for hiding this comment

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

Great, looks good!

@Lukasa Lukasa merged commit 5129806 into apple:main Sep 7, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
patch-version-bump-only For PRs that when merged will only cause a bump of the patch version, ie. 1.0.x -> 1.0.(x+1)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Key exchange should be initialized on handlerAdded as well
3 participants