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

[INTERNAL][CORE] Redo optimization to Socks5 transport #1074

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

srossbach
Copy link
Contributor

The current code was hard to understand and not really maintainable.

Removed the simultaneous connection attempts in both directions. Only
one connection attempt is made as is it very likely the the reverse
connection attempt will also fail if the first one fails.

The logic could be reintroduced but we should ensure that the connection
attempt to B->A is made after A->B and not in parallel to keep the logic
simple.

The current code was hard to understand and not really maintainable.

Removed the simultaneous connection attempts in both directions. Only
one connection attempt is made as is it very likely the the reverse
connection attempt will also fail if the first one fails.

The logic could be reintroduced but we should ensure that the connection
attempt to B->A is made after A->B and not in parallel to keep the logic
simple.
@srossbach srossbach added Aspect: Network Issue with Saros' network layer Area: Core Issue affecting the Saros Core Breaks Compatibility Change breaking compatibility with previous releases labels Jul 31, 2020
@srossbach srossbach requested review from m273d15 and tobous July 31, 2020 00:38
@saros-infrastructure
Copy link

Codacy Here is an overview of what got changed by this pull request:

Complexity decreasing per file
==============================
+ core/src/saros/net/stream/Socks5StreamService.java  -4
         

See the complete overview on Codacy

Copy link
Contributor

@m273d15 m273d15 left a comment

Choose a reason for hiding this comment

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

LGTM, but you touched all log messages. You could start to use log4j2:
Get logger with LogManager.getLogger


Socks5BytestreamSession session = preferInSession ? inSession : outSession;
log.debug(
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
log.debug(
log.debug("establishing Socks5 bytestream to: {}, {}...", () -> remoteAddress, () -> verboseLocalProxyInfo())

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Guess that this is my opinion but I find it very frustrating that you simply cannot mix up lambdas and objects.

Copy link
Contributor

Choose a reason for hiding this comment

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

I had the same expectation and was very confused about the error messages when I tried to mix both. However, I think it is still better than log4j-1.2.

((Socks5BytestreamRequest) request).setTotalConnectTimeout(TOTAL_CONNECT_TIMEOUT);
session = (Socks5BytestreamSession) request.accept();
} catch (InterruptedException e) {
log.warn("interrupted while accepting request from: " + remoteAddress);
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
log.warn("interrupted while accepting request from: " + remoteAddress);
log.warn("interrupted while accepting request from: {}", remoteAddress);

// Thread.currentThread().interrupt();
return;
} catch (XMPPException e) {
log.error("failed to accept request from from: " + remoteAddress, e);
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
log.error("failed to accept request from from: " + remoteAddress, e);
log.error("failed to accept request from from: {}", remoteAddress, e);

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Isnt this swallowing the exception ?

Copy link
Contributor

Choose a reason for hiding this comment

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

The exception handling is not very well documented, but the default exception handling is described in the layouts documentation (see alwaysWriteExceptions):

exceptions are always written even if the pattern contains no exception conversions. This means that if you do not include a way to output exceptions in your pattern, the default exception formatter will be added to the end of the pattern. Setting this to false disables this behavior and allows you to exclude exceptions from your pattern output.

return establishBinaryChannel(connectionID, remoteAddress.toString());
} catch (XMPPException e) {
throw new IOException(e);
log.error("failed to setup connection for request from: " + remoteAddress, e);
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
log.error("failed to setup connection for request from: " + remoteAddress, e);
log.error("failed to setup connection for request from: {}", remoteAddress, e);

@@ -819,93 +279,9 @@ private void configureSocks5Socket(Socks5BytestreamSession session) {

try {
socket.setTcpNoDelay(TCP_NODELAY);
log.debug("nagle algorithm for socket disabled: " + TCP_NODELAY);
log.debug("Nagle algorithm for session " + session + " disabled: " + TCP_NODELAY);
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
log.debug("Nagle algorithm for session " + session + " disabled: " + TCP_NODELAY);
log.debug("Nagle algorithm for session {} disabled: {}", session, TCP_NODELAY);


if (listener == null) throw new IOException(this + " transport is not initialized");
log.debug("received request to establish a Socks5 bytestream to: " + remoteAddress);
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
log.debug("received request to establish a Socks5 bytestream to: " + remoteAddress);
log.debug("received request to establish a Socks5 bytestream to: {}", remoteAddress);

log.warn(
"rejecting request from " + peer + " , no connection identifier found: " + sessionID);
if (currentConnectionListener == null || currentLocalAddress == null) {
log.warn("service is not initialized - rejecting request from: " + remoteAddress);
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
log.warn("service is not initialized - rejecting request from: " + remoteAddress);
log.warn("service is not initialized - rejecting request from: {}", remoteAddress);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area: Core Issue affecting the Saros Core Aspect: Network Issue with Saros' network layer Breaks Compatibility Change breaking compatibility with previous releases
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants