WIP BugFix 3

This commit is contained in:
GustavoHMDS committed 2026-09-29 01:13:42 -03:00
1 parent 0c71a85cba
commit fa4ee046b1
5 files changed
+10 -30

No files matched your search

Binary file not shown.
Binary file not shown.
@@ -62,16 +62,10 @@ public class ConnectionFactory {
HandshakeMessage handshake = new HandshakeMessage(isPrivate, sender, receiver);
connection.send(handshake.toByteArray());
System.out.println("Enviou handhsake");
HandshakeMessage handshakeResponse = validateConnection(connection);
System.out.println("Recebeu resposta");
if (handshakeResponse == null) {
System.out.println("Conexao falhou");
return null;
}
if (handshakeResponse == null) return null;
System.out.println("Sucesso na conexao");
connection.setTimeout(STANDARD_TIMEOUT);
return connection;
@@ -106,10 +100,8 @@ public class ConnectionFactory {
HandshakeMessage handshake = validateConnection(connection);
if (handshake == null) {
System.out.println("Conexao falhou");
return null;
}
if (handshake == null) return null;
connection.send(handshake.createResponse().toByteArray());
@@ -119,7 +111,6 @@ public class ConnectionFactory {
connection.setTimeout(STANDARD_TIMEOUT);
System.out.println("Sucesso na conexao");
return connection;
}
catch (IOException ex) {
@@ -161,13 +152,10 @@ public class ConnectionFactory {
if (object instanceof Message message) {
SysInfoMessage sysInfo = SysInfoMessage.parseSystemInfo(bytes);
if (sysInfo != null) {
System.out.println(sysInfo.getMessage());
return null;
}
if (sysInfo != null) return null;
if (message instanceof HandshakeMessage handshake) {
System.out.println("Recebeu handshake");
return (validateHandshake(handshake, connection)) ? handshake : null;
}
}
@@ -222,7 +210,6 @@ public class ConnectionFactory {
SysInfoType.CONNECTION_REJECTED,
"Invalid Sender: " + sender + "."
);
System.out.println("Handshake invalido");
return false;
}
if (receiver == null || receiver.isBlank()) {
@@ -231,11 +218,9 @@ public class ConnectionFactory {
SysInfoType.CONNECTION_REJECTED,
"Invalid Receiver: " + receiver + "."
);
System.out.println("Handshake invalido");
return false;
}
System.out.println("Handshake valido");
return true;
}
}
+5 -9
View File
@@ -135,7 +135,6 @@ public class SocketTCP extends Thread {
connection = connectionManager.getPublicConnection(destinationAddress);
if (connection != null && !connection.isClosed()) return connection;
System.out.println("Trying to Establish TCP connection.");
connection = establishOutgoingConnection(destinationAddress, senderId, receiverId, false);
@@ -195,7 +194,7 @@ public class SocketTCP extends Thread {
saveConnection(connection);
connectionExecutor.submit(() -> {
startReceiver(connection, false);
startReceiver(connection);
});
return connection;
@@ -212,12 +211,11 @@ public class SocketTCP extends Thread {
*/
private void acceptIncomingConnection(Socket socket) {
connectionExecutor.submit(() -> {
System.out.println("Accepted TCP connection.");
TcpConnection connection = ConnectionFactory.receiveConnection(socket);
if (connection == null) return;
saveConnection(connection);
startReceiver(connection, true);
startReceiver(connection);
});
}
@@ -248,10 +246,9 @@ public class SocketTCP extends Thread {
* estabelecimento da conexão.</p>
*
* @param connection conexão cujo fluxo de entrada será processado.
* @param notify indica se o plugin destinatário deve ser notificado sobre
* o recebimento de uma nova conexão privada.
*/
private void startReceiver(TcpConnection connection, boolean notify) {
private void startReceiver(TcpConnection connection) {
if (!connection.isPrivate()) {
publicConnectionReceiver(connection);
return;
@@ -264,9 +261,8 @@ public class SocketTCP extends Thread {
Plugin receiver = findConnectionReceiver(connection);
if (receiver instanceof PrivateConnectionPlugin plugin) {
if (notify) {
plugin.receivePrivateConnection(connection);
}
privateConnectionReceiver(connection, plugin);
}
}
@@ -144,7 +144,6 @@ public class SocketUDP extends Thread {
}
throw ex;
}
System.out.println("Message! it is from: " + msgPacket.getSocketAddress());
HeartbeatMessage heartbeat = tryParseHeartbeat(msgPacket.getData());
if (heartbeat != null) {