Skip to content

Commit

Permalink
Roollback the uds implementation code, this increase in the upstream …
Browse files Browse the repository at this point in the history
…and downstream traffic direction automatic reversal function is weak and counterproductive, can not leave this black sheep function option.
  • Loading branch information
liulilittle committed Jan 5, 2023
1 parent 46491dc commit b0b1bfa
Show file tree
Hide file tree
Showing 14 changed files with 7 additions and 91 deletions.
1 change: 0 additions & 1 deletion uds/samples/encryptor/udss.ini
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ inbound-port=10000
outbound-ip=::
outbound-port=20000
turbo=true
inversion=true
backlog=511
fast-open=true
keep-alived=true
Expand Down
1 change: 0 additions & 1 deletion uds/samples/ssl/udss.ini
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ inbound-port=10000
outbound-ip=::
outbound-port=20000
turbo=true
inversion=true
backlog=511
fast-open=true
keep-alived=true
Expand Down
1 change: 0 additions & 1 deletion uds/samples/tcp/udss.ini
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ inbound-port=10000
outbound-ip=::
outbound-port=20000
turbo=true
inversion=true
backlog=511
fast-open=true
keep-alived=true
Expand Down
1 change: 0 additions & 1 deletion uds/samples/tls/udss.ini
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ inbound-port=10000
outbound-ip=::
outbound-port=20000
turbo=true
inversion=true
backlog=511
fast-open=true
keep-alived=true
Expand Down
1 change: 0 additions & 1 deletion uds/samples/websocket+ssl/udss.ini
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ inbound-port=10000
outbound-ip=::
outbound-port=20000
turbo=true
inversion=true
backlog=511
fast-open=true
keep-alived=true
Expand Down
1 change: 0 additions & 1 deletion uds/samples/websocket+tls/udss.ini
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ inbound-port=10000
outbound-ip=::
outbound-port=20000
turbo=true
inversion=true
backlog=511
fast-open=true
keep-alived=true
Expand Down
1 change: 0 additions & 1 deletion uds/samples/websocket/udss.ini
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ inbound-port=10000
outbound-ip=::
outbound-port=20000
turbo=true
inversion=true
backlog=511
fast-open=true
keep-alived=true
Expand Down
29 changes: 3 additions & 26 deletions uds/uds/client/Router.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -156,17 +156,6 @@ namespace uds {
uds::threading::ClearTimeout(constantof(timeout));
}
};
static const auto CloseIfNotSuccess = [](bool success, const TimeoutPtr& timeout, const AsioTcpSocket& network, const ITransmissionPtr& inbound, const ITransmissionPtr& outbound) noexcept {
if (!success) {
ClearTimeout(timeout);
if (outbound) {
outbound->Close();
}
inbound->Close();
Socket::Closesocket(network);
}
return success;
};

const std::shared_ptr<Reference> references = GetReference();
const AsioTcpSocket network = socket;
Expand All @@ -184,21 +173,9 @@ namespace uds {
return ResolveAddress(configuration_->Outbound.Domain, configuration_->Outbound.IP, configuration_->Outbound.Port,
[channelId, inbound, timeout, network, references, this](const boost::asio::ip::tcp::endpoint& remoteEP) noexcept {
if (!ConnectConnection(inbound->GetContext(), channelId, remoteEP,
[inbound, timeout, network, references, this](const ITransmissionPtr& transmission, int channelId) noexcept {
ITransmissionPtr outbound = transmission;
return CloseIfNotSuccess(Connection::HelloAsync(outbound,
[channelId, inbound, outbound, timeout, network, references, this](bool success) noexcept {
ClearTimeout(timeout);
if (success) {
if (channelId >> 31) {
success = Accept(network, channelId, outbound, inbound);
}
else {
success = Accept(network, channelId, inbound, outbound);
}
}
CloseIfNotSuccess(success, timeout, network, inbound, outbound);
}), timeout, network, inbound, outbound);
[inbound, timeout, network, references, this](const ITransmissionPtr& outbound, int channelId) noexcept {
ClearTimeout(timeout);
return Accept(network, channelId, inbound, outbound);
})) {
ClearTimeout(timeout);
inbound->Close();
Expand Down
1 change: 0 additions & 1 deletion uds/uds/configuration/AppConfiguration.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,6 @@ namespace uds {
configuration->Outbound.Port = section.GetValue<int>("outbound-port");
configuration->FastOpen = section.GetValue<bool>("fast-open");
configuration->Turbo = section.GetValue<bool>("turbo");
configuration->Inversion = section.GetValue<bool>("inversion");
configuration->Connect.Timeout = section.GetValue<int>("connect.timeout");
configuration->Handshake.Timeout = section.GetValue<int>("handshake.timeout");
configuration->Inbound.Domain = false;
Expand Down
1 change: 0 additions & 1 deletion uds/uds/configuration/AppConfiguration.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ namespace uds {
} Inbound, Outbound;
int Alignment = 0;
int Backlog = 511;
bool Inversion = false;
bool FastOpen = false;
bool Turbo = false;
bool KeepAlived = false;
Expand Down
21 changes: 4 additions & 17 deletions uds/uds/server/Switches.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ namespace uds {
namespace server {
Switches::Switches(const std::shared_ptr<uds::threading::Hosting>& hosting, const std::shared_ptr<uds::configuration::AppConfiguration>& configuration) noexcept
: disposed_(false)
, channel_(RandomNext(1, INT_MAX))
, channel_(0)
, hosting_(hosting)
, configuration_(configuration) {
if (hosting) {
Expand Down Expand Up @@ -140,7 +140,6 @@ namespace uds {
ClearTimeout(key);
outbound->Close();
}, (UInt64)configuration_->Connect.Timeout * 1000));
handshaked = handshaked && Connection::HelloAsync(outbound);
handshaked = handshaked && Connection::AcceptAsync(transmission,
[references, this, outbound](bool success, int channelId) noexcept -> void {
ClearTimeout(outbound.get());
Expand Down Expand Up @@ -182,8 +181,7 @@ namespace uds {

for (;;) {
int channelId = ++channel_;
if (channelId < 1) {
channel_ = 0;
if (!channelId) {
continue;
}

Expand All @@ -196,12 +194,6 @@ namespace uds {
continue;
}

if (configuration_->Inversion) {
int inversion = RandomNext() & 1;
if (inversion) {
channelId |= (int)(1 << 31);
}
}
channel->channel_ = channelId;
channel->inbound_ = inbound;
channel->network_ = network;
Expand Down Expand Up @@ -251,15 +243,10 @@ namespace uds {
if (!link) {
return false;
}

bool success = ClearTimeout(link->network_.get());
if (success) {
if (channel >> 31) {
success = Accept(channel, outbound, link->inbound_);
}
else {
success = Accept(channel, link->inbound_, outbound);
}
success = Accept(channel, link->inbound_, outbound);
}

if (!success) {
Expand Down
35 changes: 0 additions & 35 deletions uds/uds/tunnel/Connection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -355,10 +355,6 @@ namespace uds {
}

int channelId = (int)(v >> 32);
if (!channelId) {
callback(false, 0);
return;
}
callback(true, channelId);
});
}
Expand Down Expand Up @@ -388,37 +384,6 @@ namespace uds {
return HandshakeClient(inbound, std::forward<ConnectAsyncCallback>(handler));
}

bool Connection::HelloAsync(const ITransmissionPtr& outbound) noexcept {
if (!outbound) {
return false;
}

ITransmissionPtr transmission = outbound;
return HandshakeServer(outbound, UINT8_MAX << 1, RandomNext(1, INT_MAX),
[transmission](bool success, int) noexcept {
if (!success) {
transmission->Close();
}
});
}

bool Connection::HelloAsync(const ITransmissionPtr& inbound, HelloAsyncCallback&& handler) noexcept {
if (!inbound || !handler) {
return false;
}

HelloAsyncCallback callback = handler;
ITransmissionPtr transmission = inbound;

return HandshakeClient(inbound,
[transmission, callback](bool success, int) noexcept {
if (!success) {
transmission->Close();
}
callback(success);
});
}

bool Connection::PackPlaintextHeaders(Stream& stream, int channelId, int alignment) noexcept {
if (!stream.CanWrite()) {
return false;
Expand Down
3 changes: 0 additions & 3 deletions uds/uds/tunnel/Connection.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ namespace uds {
using AcceptAsyncCallback = std::function<void(bool, int)>;
using AcceptAsyncMeasureChannelId = std::function<int(const ITransmissionPtr&)>;
using ConnectAsyncCallback = AcceptAsyncCallback;
using HelloAsyncCallback = std::function<void(bool)>;

public:
const int ECONNECTION_MSS = uds::threading::Hosting::BufferSize;
Expand All @@ -55,8 +54,6 @@ namespace uds {
static bool AcceptAsync(const ITransmissionPtr& outbound, AcceptAsyncCallback&& handler) noexcept;
static bool ConnectAsync(const ITransmissionPtr& outbound, int alignment, int channelId, ConnectAsyncCallback&& handler) noexcept;
static bool ConnectAsync(const ITransmissionPtr& inbound, ConnectAsyncCallback&& handler) noexcept;
static bool HelloAsync(const ITransmissionPtr& outbound) noexcept;
static bool HelloAsync(const ITransmissionPtr& inbound, HelloAsyncCallback&& handler) noexcept;

private:
static bool PackPlaintextHeaders(Stream& stream, int channelId, int alignment) noexcept;
Expand Down
1 change: 0 additions & 1 deletion uds/udss.ini
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ inbound-port=10000
outbound-ip=::
outbound-port=20000
turbo=true
inversion=true
backlog=511
fast-open=true
keep-alived=true
Expand Down

0 comments on commit b0b1bfa

Please sign in to comment.