-
Notifications
You must be signed in to change notification settings - Fork 517
containers: Be able to send channel tokens to a container service #5939
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -108,15 +108,17 @@ ContainerClient::ContainerClient(capnp::ByteStreamFactory& byteStreamFactory, | |
| kj::String containerName, | ||
| kj::String imageName, | ||
| kj::TaskSet& waitUntilTasks, | ||
| kj::Function<void()> cleanupCallback) | ||
| kj::Function<void()> cleanupCallback, | ||
| ChannelTokenHandler& channelTokenHandler) | ||
| : byteStreamFactory(byteStreamFactory), | ||
| timer(timer), | ||
| network(network), | ||
| dockerPath(kj::mv(dockerPath)), | ||
| containerName(kj::encodeUriComponent(kj::mv(containerName))), | ||
| imageName(kj::mv(imageName)), | ||
| waitUntilTasks(waitUntilTasks), | ||
| cleanupCallback(kj::mv(cleanupCallback)) {} | ||
| cleanupCallback(kj::mv(cleanupCallback)), | ||
| channelTokenHandler(channelTokenHandler) {} | ||
|
|
||
| ContainerClient::~ContainerClient() noexcept(false) { | ||
| // Call the cleanup callback to remove this client from the ActorNamespace map | ||
|
|
@@ -466,6 +468,27 @@ kj::Promise<void> ContainerClient::listenTcp(ListenTcpContext context) { | |
| KJ_UNIMPLEMENTED("listenTcp not implemented for Docker containers - use port mapping instead"); | ||
| } | ||
|
|
||
| kj::Promise<void> ContainerClient::setEgressTcp(SetEgressTcpContext context) { | ||
| auto params = context.getParams(); | ||
| auto addr = kj::str(params.getAddr()); | ||
| auto tokenBytes = params.getChannelToken(); | ||
|
|
||
| // Redeem the channel token to get a SubrequestChannel | ||
| auto subrequestChannel = channelTokenHandler.decodeSubrequestChannelToken( | ||
| workerd::IoChannelFactory::ChannelTokenUsage::RPC, tokenBytes); | ||
|
|
||
| // Store the mapping | ||
| egressMappings.upsert(kj::mv(addr), kj::mv(subrequestChannel), | ||
| [](auto& existing, auto&& newValue) { existing = kj::mv(newValue); }); | ||
|
|
||
| // TODO: At some point we need to figure out how to make it so | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think we need to fully implement this for local testing now. If it's not available in local testing then nobody will be able to code against this feature.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Responding to both comments about local dev here (@danlapid):
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If you had local dev support you could iterate super fast 😄
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Independently of local-dev support being a must for this feature to be publicly available, I think it's not really equivalent the path of connectivity to workers in local dev and in prod.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't really see the benefit of rushing to prod before implementing local dev. It's not really in doubt whether or not it will work in prod. But it'll be hard to write code to test it in prod if we don't also have local dev.
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think this should be left as "at some point". |
||
| // in local development we are able to actually map to an egress mapping. | ||
| // For now, just fake it for testing purposes the decoding of the | ||
| // subrequest channel token. | ||
|
|
||
| co_return; | ||
| } | ||
|
|
||
| kj::Own<ContainerClient> ContainerClient::addRef() { | ||
| return kj::addRef(*this); | ||
| } | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm, should we call this API
setEgressHttp()considering that we're going to interpret it as HTTP?In the future when we support
connecthandlers then we could actually have an option to support raw TCP, but it would have to be a separate method since we need the app to tell us whether to try parsing the input as HTTP or not.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Another method name idea:
interceptOutboundHttpUh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a good idea. We could also instead have it be at a 'domain'/'hostname' level instead of IP port.