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

refactor: combined ForwardProxy and ReverseProxy into Proxy #361

Merged
merged 1 commit into from
Mar 23, 2022

Conversation

tegefaulkes
Copy link
Contributor

@tegefaulkes tegefaulkes commented Mar 23, 2022

Description

ForwardProxy and ReverseProxy has been conbined into a single Proxy. the core part of this change is that both the proxies now share the same UTP socket. This allows us to get information about the reverse proxy's port when handling an incoming connection. This is critical for NAT punch-through procedure.

I can just merge the branch manually but I want to do a proper review quickly and leave a paper trail. SO it's best to have this as a proper PR.

Issues Fixed

Tasks

  1. review

Final checklist

  • Domain specific tests
  • Full tests
  • Updated inline-comment documentation
  • Lint fixed
  • Squash and rebased
  • Sanity check the final build

@tegefaulkes tegefaulkes added the development Standard development label Mar 23, 2022
@tegefaulkes tegefaulkes self-assigned this Mar 23, 2022
@CMCDragonkai
Copy link
Member

CMCDragonkai commented Mar 23, 2022

New naming of all ports and hosts:

┌────────────┐ clientHost forwardHost                               forwardHost clientHost┌────────────┐
│            │ clientPort forwardPort                               forwardPort clientPort│            │
│ GRPCClient ├────────────────┐                                            ┌──────────────┤ GRPCClient │
│            │                │      ┌───────┐             ┌───────┐       │              │            │
└────────────┘                └──────►       │             │       ◄───────┘              └────────────┘
                                     │ Proxy ◄─────────────► Proxy │
┌────────────┐                ┌──────┤       │  proxyHost  │       ├───────┐              ┌────────────┐
│            │                │      └───────┘  proxyPort  └───────┘       │              │            │
│ GRPCServer ◄────────────────┘                                            └──────────────► GRPCServer │
│            │ serverHost reverseHost                               reverseHost serverHost│            │
└────────────┘ serverPort reversePort                               reversePort serverPort└────────────┘

@CMCDragonkai
Copy link
Member

CMCDragonkai commented Mar 23, 2022

Now you can do things like:

getConnectionInfoByProxy - get connection info by the remote proxy host and port
getConnectionInfoByClient - get connection info by the GRPC client host and port
getConnectionInfoByReverse - get connection info by the reverse host and port used by GRPC server handlers
       getConnectionInfoByClient
                   │
                   │
                   │
                   │
                   ▼
┌────────────┐ clientHost forwardHost                               forwardHost clientHost┌────────────┐
│            │ clientPort forwardPort                               forwardPort clientPort│            │
│ GRPCClient ├────────────────┐                                            ┌──────────────┤ GRPCClient │
│            │                │      ┌───────┐             ┌───────┐       │              │            │
└────────────┘                └──────►       │             │       ◄───────┘              └────────────┘
                                     │ Proxy ◄─────────────► Proxy │
┌────────────┐                ┌──────┤       │  proxyHost  │       ├───────┐              ┌────────────┐
│            │                │      └───────┘  proxyPort  └───────┘       │              │            │
│ GRPCServer ◄────────────────┘                     ▲                      └──────────────► GRPCServer │
│            │ serverHost reverseHost               │               reverseHost serverHost│            │
└────────────┘ serverPort reversePort               │               reversePort serverPort└────────────┘
                                                    │                    ▲
                                                    │                    │
                                        getConnectionInfoByProxy         │
                                                                         │
                                                                         │
                                                             getConnectionInfoByReverse

src/network/Proxy.ts Outdated Show resolved Hide resolved
Copy link
Contributor Author

@tegefaulkes tegefaulkes left a comment

Choose a reason for hiding this comment

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

Just some general stuff to fix.

src/network/ConnectionReverse.ts Outdated Show resolved Hide resolved
src/network/Proxy.ts Outdated Show resolved Hide resolved
tests/bin/agent/start.test.ts Outdated Show resolved Hide resolved
tests/nodes/NodeConnectionManager.termination.test.ts Outdated Show resolved Hide resolved
tests/nodes/NodeManager.test.ts Outdated Show resolved Hide resolved
@CMCDragonkai
Copy link
Member

I can see you're new commit standard, are you following the https://www.conventionalcommits.org/en/v1.0.0/#summary standard now? I haven't had the time to bring in the commit linting into the CI/CD at this point.

src/network/errors.ts Outdated Show resolved Hide resolved
@CMCDragonkai
Copy link
Member

I can see you're new commit standard, are you following the https://www.conventionalcommits.org/en/v1.0.0/#summary standard now? I haven't had the time to bring in the commit linting into the CI/CD at this point.

Looking at the conventional commits PRs https://github.com/conventional-commits/conventionalcommits.org/pulls, it seems that the title of the PR can be in the conventional commit structure as well, but it doesn't need to match the commit name if there are multiple commits, it can be its own message. This is because the PR title might become the merge commit message or part of it. So if you have 2 commits, then the PR title might synthesise a title from both.

src/network/Proxy.ts Outdated Show resolved Hide resolved
@tegefaulkes
Copy link
Contributor Author

CI/CD is passing now. I'll start squashing.

@tegefaulkes tegefaulkes force-pushed the Single_proxy_socket branch from a0aaa9d to a056b3a Compare March 23, 2022 04:40
@CMCDragonkai
Copy link
Member

@emmacasolin note that now when running pk agent start, you'd use --proxy-host and --proxy-port in place of --ingress-host and --ingress-port.

LGTM, so we can merge once CI/CD.

@CMCDragonkai
Copy link
Member

Commit message typos, just need to fix that up.

`ForwardProxy` and `ReverseProxy` has been combined into a single `Proxy`. The core part of this change is that both the proxies now share the same `UTP` socket. This allows us to get information about the reverse proxy's port when handling an incoming connection. This is critical for `NAT` punch-through procedure.

Fixes #360
@emmacasolin
Copy link
Contributor

I've just noticed something that was missed here. The constructor for the new Proxy takes

connConnectTime?: number;
connKeepAliveTimeoutTime?: number;
connEndTime?: number;
connPunchIntervalTime?: number;
connKeepAliveIntervalTime?: number;

However the proxyConfig object in both config.ts and PolykeyAgent.ts takes

connConnectTime?: number;
connTimeoutTime?: number;
connPingIntervalTime?: number;

So setting any values for connTimeoutTime or connPingIntervalTime when creating a new polykey agent doesn't actually do anything since these are no longer parameters for the Proxy constructor.

Also related to this issue (but not brought in by this PR) is that the --connection-timeout option for pk agent start doesn't work at the moment. This is because we're attempting to access the value of that option inside CommandStart.ts using options.connTimeoutTime, however commander actually stores the value in options.connectionTimeout.

@CMCDragonkai
Copy link
Member

Keep in mind with combine forward and reverse any timeout and interval settings is duplicated for both forward and reverse. This is fine, forward and reverse should have similar times for both timeout and interval. At least until we see a problem with it.

@CMCDragonkai
Copy link
Member

@tegefaulkes can you push hotpatch to master regarding @emmacasolin report above. That way #357 can just directly rebase on top of master now instead of #326.

@tegefaulkes
Copy link
Contributor Author

I'll do that. I'll fix both things that were mentioned here?

@CMCDragonkai
Copy link
Member

Yep.

@tegefaulkes
Copy link
Contributor Author

Pushed up the fix to master.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
development Standard development
Development

Successfully merging this pull request may close these issues.

Refactor proxies to use the same UTP socket for external connections
3 participants