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

Add entropy source to the containers http client #3599

Merged
merged 1 commit into from
Feb 25, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 11 additions & 4 deletions src/workerd/api/container.c++
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,11 @@ void Container::signal(jsg::Lock& js, int signo) {
class Container::TcpPortWorkerInterface final: public WorkerInterface {
public:
TcpPortWorkerInterface(capnp::ByteStreamFactory& byteStreamFactory,
kj::EntropySource& entropySource,
const kj::HttpHeaderTable& headerTable,
rpc::Container::Port::Client port)
: byteStreamFactory(byteStreamFactory),
entropySource(entropySource),
headerTable(headerTable),
port(kj::mv(port)) {}

Expand Down Expand Up @@ -120,7 +122,7 @@ class Container::TcpPortWorkerInterface final: public WorkerInterface {
connectImpl(*pipe.ends[1]).then([]() -> kj::Promise<void> { return kj::NEVER_DONE; });

// ... and then stack an HttpClient on it ...
auto client = kj::newHttpClient(headerTable, *pipe.ends[0]);
auto client = kj::newHttpClient(headerTable, *pipe.ends[0], {.entropySource = entropySource});

// ... and then adapt that to an HttpService ...
auto service = kj::newHttpService(*client);
Expand Down Expand Up @@ -167,6 +169,7 @@ class Container::TcpPortWorkerInterface final: public WorkerInterface {

private:
capnp::ByteStreamFactory& byteStreamFactory;
kj::EntropySource& entropySource;
const kj::HttpHeaderTable& headerTable;
rpc::Container::Port::Client port;

Expand Down Expand Up @@ -209,19 +212,22 @@ class Container::TcpPortWorkerInterface final: public WorkerInterface {
class Container::TcpPortOutgoingFactory final: public Fetcher::OutgoingFactory {
public:
TcpPortOutgoingFactory(capnp::ByteStreamFactory& byteStreamFactory,
kj::EntropySource& entropySource,
const kj::HttpHeaderTable& headerTable,
rpc::Container::Port::Client port)
: byteStreamFactory(byteStreamFactory),
entropySource(entropySource),
headerTable(headerTable),
port(kj::mv(port)) {}

kj::Own<WorkerInterface> newSingleUseClient(kj::Maybe<kj::String> cfStr) override {
// At present we have no use for `cfStr`.
return kj::heap<TcpPortWorkerInterface>(byteStreamFactory, headerTable, port);
return kj::heap<TcpPortWorkerInterface>(byteStreamFactory, entropySource, headerTable, port);
}

private:
capnp::ByteStreamFactory& byteStreamFactory;
kj::EntropySource& entropySource;
const kj::HttpHeaderTable& headerTable;
rpc::Container::Port::Client port;
};
Expand All @@ -234,8 +240,9 @@ jsg::Ref<Fetcher> Container::getTcpPort(jsg::Lock& js, int port) {

auto& ioctx = IoContext::current();

kj::Own<Fetcher::OutgoingFactory> factory = kj::heap<TcpPortOutgoingFactory>(
ioctx.getByteStreamFactory(), ioctx.getHeaderTable(), req.send().getPort());
kj::Own<Fetcher::OutgoingFactory> factory =
kj::heap<TcpPortOutgoingFactory>(ioctx.getByteStreamFactory(), ioctx.getEntropySource(),
ioctx.getHeaderTable(), req.send().getPort());

return jsg::alloc<Fetcher>(
ioctx.addObject(kj::mv(factory)), Fetcher::RequiresHostAndProtocol::YES, true);
Expand Down
Loading