sdedic commented on code in PR #6330:
URL: https://github.com/apache/netbeans/pull/6330#discussion_r1298153305
##########
java/java.lsp.server/src/org/netbeans/modules/java/lsp/server/ConnectionSpec.java:
##########
@@ -129,26 +152,48 @@ public void run() {
}
};
listeningThread.start();
- out.write((prefix + " listening at port " + localPort).getBytes());
+ StringBuilder message = new StringBuilder();
+ message.append(prefix).append(" listening at port
").append(localPort);
+ if (hash) {
+ message.append(" with hash ");
+ for (char c : hashContent) {
+ message.append(c);
+ }
+ }
+ message.append("\n");
+ out.write(message.toString().getBytes());
out.flush();
} else {
// connect to TCP
final Socket socket = new
Socket(Inet4Address.getLoopbackAddress(), port);
- connectToSocket(socket, prefix, session, serverSetter, launcher);
+ connectToSocket(socket, prefix, session, serverSetter, launcher,
null);
}
}
private <ServerType extends LspSession.ScheduledServer> void
connectToSocket(
final Socket socket, String prefix, LspSession session,
BiConsumer<LspSession, ServerType> serverSetter,
- BiFunction<Pair<InputStream, OutputStream>, LspSession,
ServerType> launcher) {
+ BiFunction<Pair<InputStream, OutputStream>, LspSession,
ServerType> launcher,
+ char[] hashContent) {
final int connectTo = socket.getPort();
Thread connectedThread = new Thread(prefix + " connected to " +
connectTo) {
@Override
public void run() {
try {
- ServerType connectionObject =
launcher.apply(Pair.of(socket.getInputStream(), socket.getOutputStream()),
session);
+ InputStream in = socket.getInputStream();
+
+ if (hashContent != null) {
+ for (char c : hashContent) {
+ byte b = (byte) in.read();
+
+ if (b != c) {
+ throw new IOException("Hash validation
failed!");
Review Comment:
close the IS and the socket ?
##########
java/java.lsp.server/src/org/netbeans/modules/java/lsp/server/ConnectionSpec.java:
##########
@@ -109,6 +117,21 @@ public <ServerType extends LspSession.ScheduledServer>
void prepare(
// listen on TCP
ServerSocket server = new ServerSocket(port, 1,
Inet4Address.getLoopbackAddress());
close.add(server);
+
+ char[] hashContent;
+ if (hash) {
+ byte[] hashBytes = new byte[HASH_LEN];
+ new Random().nextBytes(hashBytes);
+ hashContent = new char[hashBytes.length * 2];
+ int idx = 0;
+ for (byte b : hashBytes) {
+ hashContent[idx + 0] = Integer.toHexString((b >> 4) &
0xFF).charAt(0);
Review Comment:
nitpick: should be &0x0f, not 0xff, but works anyway.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]
For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists