feature/separacao-gerenciadores #1
No files matched your search
@@ -64,9 +64,14 @@ public class ConnectionFactory {
|
|||||||
connection.send(handshake.toByteArray());
|
connection.send(handshake.toByteArray());
|
||||||
System.out.println("Enviou handhsake");
|
System.out.println("Enviou handhsake");
|
||||||
HandshakeMessage handshakeResponse = validateConnection(connection);
|
HandshakeMessage handshakeResponse = validateConnection(connection);
|
||||||
|
System.out.println("Recebeu resposta");
|
||||||
|
|
||||||
if (handshakeResponse == null) return null;
|
if (handshakeResponse == 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;
|
||||||
@@ -101,7 +106,12 @@ public class ConnectionFactory {
|
|||||||
|
|
||||||
HandshakeMessage handshake = validateConnection(connection);
|
HandshakeMessage handshake = validateConnection(connection);
|
||||||
|
|
||||||
if (handshake == null) return null;
|
if (handshake == null) {
|
||||||
|
System.out.println("Conexao falhou");
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
connection.send(handshake.createResponse().toByteArray());
|
||||||
|
|
||||||
connection.setSender(handshake.getSender());
|
connection.setSender(handshake.getSender());
|
||||||
connection.setReceiver(handshake.getReceiver());
|
connection.setReceiver(handshake.getReceiver());
|
||||||
@@ -109,6 +119,7 @@ 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) {
|
||||||
@@ -149,8 +160,9 @@ public class ConnectionFactory {
|
|||||||
Object object = ois.readObject();
|
Object object = ois.readObject();
|
||||||
|
|
||||||
if (object instanceof Message message) {
|
if (object instanceof Message message) {
|
||||||
if (SysInfoMessage.parseSystemInfo(bytes) != null) {
|
SysInfoMessage sysInfo = SysInfoMessage.parseSystemInfo(bytes);
|
||||||
//TODO: Tratar erros
|
if (sysInfo != null) {
|
||||||
|
System.out.println(sysInfo.getMessage());
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -210,6 +222,7 @@ 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()) {
|
||||||
@@ -218,8 +231,11 @@ 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;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -135,6 +135,7 @@ 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);
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user