-
Notifications
You must be signed in to change notification settings - Fork 52
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] moves Socks5Logic out of XMPPConnection #869
base: master
Are you sure you want to change the base?
Conversation
|
||
socks5Proxy = null; | ||
|
||
if (socks5ProxyPort < 0) return; |
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.
<=
final Socks5Proxy newSocks5Proxy = Socks5Proxy.getSocks5Proxy(); | ||
socks5Proxy = newSocks5Proxy; |
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.
final Socks5Proxy newSocks5Proxy = Socks5Proxy.getSocks5Proxy(); | |
socks5Proxy = newSocks5Proxy; | |
socks5Proxy = Socks5Proxy.getSocks5Proxy(); |
Do you need the "newSocks5Proxy" variable? It is used by l. 137, l. 159. I see no need for an additional variable.
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.
I have not found any information if lambdas act as closures nor not. The lambda should definitely not access the socks5Proxy variable as it can already be null inside the threads.
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.
Do you mean
saros/core/src/saros/net/xmpp/Socks5ProxySupport.java
Lines 127 to 132 in 6655c32
ThreadUtils.runSafeAsync( | |
"saros-stun-discovery", | |
log, | |
() -> { | |
discoverAndPublishStunAddresses(socks5Proxy, stunServerAddress, stunServerPort); | |
}); |
In this case
socks5Proxy
is used from the heap, so formally this is a concurrency problem which is unlikely (disableProxy()
would need to run before...).
return; | ||
} | ||
|
||
Socks5Proxy.getSocks5Proxy().stop(); |
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.
Would lead to a NPE if called before the "enableProxy" method. I don't know whether it is worth to check for null.
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 was a C&P, socks5Proxy.stop()
is the correct call.
private static void addSocks5ProxyAddresses( | ||
final Socks5Proxy proxy, final Collection<String> addresses, boolean inFront) { | ||
|
||
synchronized (socks5AddressReplacementLock) { |
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.
Just for my own understanding: I would assume that you could make the method synchronized without the extra object, because synchronized <methodname>
locks this
and synchronized static
locks <ClassName>.class
. Is this true?
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.
Yes I could also synchronize on the class variable. I could also make this method non static however it should not use synchronized(this) then.
|
||
if (!upnpService.isMapped(device, socks5ProxyPort, IUPnPService.TCP)) return; | ||
|
||
if (!upnpService.deletePortMapping(device, socks5ProxyPort, IUPnPService.TCP)) { |
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.
Move call out of if condition to make it clearer that it actually has an effect?
if (!upnpService.deletePortMapping(device, socks5ProxyPort, IUPnPService.TCP)) { | |
boolean portMappingDeletionSuccessful = | |
upnpService.deletePortMapping(device, socks5ProxyPort, IUPnPService.TCP); | |
if (!portMappingDeletionSuccessful) { |
} | ||
} | ||
|
||
try { |
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 block only tears down the upnp service. But during the setup, you also initialized the stun service. Does it not require a "manual" teardown?
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.
The Stun service does only lookup some stuff while the UPNP stuff may setup a permanent port mapping. I.e the retrieved addresses goes to no longer valid socks5 proxy instance and therefore it does not matter. I can also change the code to not even wait for the stun process to finish at all, it would not matter.
|
||
upnpService.deletePortMapping(device, socks5ProxyPort, IUPnPService.TCP); | ||
|
||
if (!upnpService.createPortMapping( |
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.
Move call that actually has an effect out of if condition?
* @return <code>true</code> if the proxy was successfully started, <code>false</code> if it could | ||
* not be started or is already running | ||
*/ | ||
public synchronized boolean enableProxy( |
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.
The old logic called socks5Proxy.start()
in the setup. Is such a call no longer necessary?
Sames goes for socks5Proxy.stop()
in the teardown.
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.
The socks 5 proxy will automatically start if you call getSocks5Proxy() after setting setLocalSocks5ProxyEnabled(true)
I still have I hard time as the Smack source code is no longer available and I cannot find the source anymore for the version we are currently using.
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.
The src is still available https://github.com/igniterealtime/Smack/tree/3.4.1
+ socks5Proxy.getPort() | ||
+ " [listening on all interfaces]"); | ||
|
||
final List<String> proxyAddressesToPublish = new ArrayList<>(); |
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.
Any reason to not directly assign the collected / copied lists?
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.
Because proxyAddresses is a collection and not a list.
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.
?
you could do proxyAddressesToPublish = new ArrayList<>(proxyAddresses);
The whole logic regarding the Socks5Proxy is now handled in its own class. In addition only the STUN discovery is performed asynchronous. Assuming the UPNP router works as expected mapping and unmapping ports just takes a few milliseconds.
1a59ae7
to
6655c32
Compare
Here is an overview of what got changed by this pull request: Complexity increasing per file
==============================
- core/src/saros/net/xmpp/Socks5ProxySupport.java 17
Complexity decreasing per file
==============================
+ core/src/saros/net/xmpp/XMPPConnectionService.java -3
See the complete overview on Codacy |
@srossbach Is this ready to review? |
Yes. |
return; | ||
} | ||
|
||
log.info( |
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.
Move to else
block and remove return
from if
to improve readability/make code paths easier to understand?
+ "]"); | ||
} | ||
|
||
log.info( |
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.
Same as above. Move to else
block?
Otherwise, you should add a return
statement to the if
block as currently the "successful" message is still also displayed on failure.
The whole logic regarding the Socks5Proxy is now handled in its own
class.