feature/separacao-gerenciadores #1

Merged
gustavo merged 31 commits from feature/separacao-gerenciadores into main 2026-09-30 18:34:54 -03:00
5 changed files with 11 additions and 31 deletions
Showing only changes of commit fa4ee046b1 - Show all commits

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