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

Ios deliver newest hack method #629

Merged
merged 2 commits into from
Jan 7, 2024
Merged
Show file tree
Hide file tree
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
21 changes: 15 additions & 6 deletions src/content_server.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -220,12 +220,6 @@ class ContentServer {
work_guard_.reset();
return;
}
// FIXME should we handle it more gracefully?
if (connection_map_.size() >= absl::GetFlag(FLAGS_worker_connections)) {
socket.close(ec);
accept(listen_ctx_num);
return;
}
tlsext_ctx_t* tlsext_ctx = nullptr;
if (enable_tls_) {
tlsext_ctx = new tlsext_ctx_t{this, next_connection_id_, listen_ctx_num};
Expand All @@ -238,6 +232,14 @@ class ContentServer {
enable_upstream_tls_, enable_tls_,
&upstream_ssl_ctx_, &ssl_ctx_);
on_accept(conn, std::move(socket), listen_ctx_num, tlsext_ctx);
if (in_shutdown_) {
return;
}
if (connection_map_.size() >= absl::GetFlag(FLAGS_worker_connections)) {
LOG(INFO) << "Disabling accepting new connection: " << listen_ctxs_[listen_ctx_num].endpoint;
pending_next_listen_ctxes_.push_back(listen_ctx_num);
return;
}
accept(listen_ctx_num);
});
}
Expand Down Expand Up @@ -288,6 +290,7 @@ class ContentServer {
}
// reset guard to quit io loop if in shutdown
if (in_shutdown_) {
pending_next_listen_ctxes_.clear();
if (connection_map_.empty()) {
LOG(WARNING) << "No more connections alive... ready to stop";
work_guard_.reset();
Expand All @@ -296,6 +299,11 @@ class ContentServer {
LOG(WARNING) << "Waiting for remaining connects: " << connection_map_.size();
}
}
auto listen_ctxes = std::move(pending_next_listen_ctxes_);
for (int listen_ctx_num : listen_ctxes) {
LOG(INFO) << "Resuming accepting new connection: " << listen_ctxs_[listen_ctx_num].endpoint;
accept(listen_ctx_num);
}
}

void setup_ssl_ctx(asio::error_code &ec) {
Expand Down Expand Up @@ -575,6 +583,7 @@ class ContentServer {
};
std::array<ListenCtx, MAX_LISTEN_ADDRESSES> listen_ctxs_;
int next_listen_ctx_ = 0;
std::vector<int> pending_next_listen_ctxes_;
bool in_shutdown_ = false;

absl::flat_hash_map<int, scoped_refptr<ConnectionType>> connection_map_;
Expand Down
8 changes: 7 additions & 1 deletion src/ios/extensions/YassPacketTunnelProvider.mm
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,16 @@ - (void)startTunnelWithOptions:(NSDictionary *)options completionHandler:(void (
absl::SetFlag(&FLAGS_stderrthreshold, LOGGING_VERBOSE);
#endif

#if 0
RateFlag rate(10u << 20);
NSLog(@"tunnel: rate limit: %04.2lfm/s", rate.rate / 1024.0 / 1024.0);
NSLog(@"tunnel: applying rate limit: %04.2lfm/s", rate.rate / 1024.0 / 1024.0);
absl::SetFlag(&FLAGS_limit_rate, rate);

int worker_limit = 12;
NSLog(@"tunnel: applying concurrent limit: %d", worker_limit);
absl::SetFlag(&FLAGS_worker_connections, worker_limit);
#endif

NETunnelProviderProtocol *protocolConfiguration = (NETunnelProviderProtocol*)self.protocolConfiguration;
NSDictionary* dict = protocolConfiguration.providerConfiguration;
auto server_host = gurl_base::SysNSStringToUTF8(dict[@"server_host"]);
Expand Down
20 changes: 20 additions & 0 deletions src/stream.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,26 @@ class stream : public RefCountedThreadSafe<stream> {
}
}

#if BUILDFLAG(IS_IOS)
if (yield) {
scoped_refptr<stream> self(this);
// Every full mtu 1500 bytes packet arrives in every 100us
// the maximum traffer rate is 1500 b / 100 us = 14.3 MB/s
read_delay_timer_.expires_after(std::chrono::microseconds(100));
wait_read_callback_ = std::move(callback);
read_delay_timer_.async_wait([this, self](asio::error_code ec) {
auto callback = std::move(wait_read_callback_);
DCHECK(!wait_read_callback_);
// Cancelled, safe to ignore
if (UNLIKELY(ec == asio::error::operation_aborted)) {
return;
}
wait_read(std::move(callback), false);
});
return;
}
#endif

read_inprogress_ = true;
wait_read_callback_ = std::move(callback);
scoped_refptr<stream> self(this);
Expand Down
Loading