Added protocol version check
Former-commit-id: b8a86baa0586c8c87cd92be16789295848c45799
This commit is contained in:
parent
9f9d0e73ee
commit
440cc1ec62
2 changed files with 12 additions and 4 deletions
|
|
@ -49,6 +49,15 @@ public class PCDataSynchronizationClient implements HalDaemon {
|
||||||
ObjectOutputStream out = new ObjectOutputStream(s.getOutputStream());
|
ObjectOutputStream out = new ObjectOutputStream(s.getOutputStream());
|
||||||
ObjectInputStream in = new ObjectInputStream(s.getInputStream());
|
ObjectInputStream in = new ObjectInputStream(s.getInputStream());
|
||||||
|
|
||||||
|
// Check server protocol version
|
||||||
|
int version = in.readInt();
|
||||||
|
if(version != PCDataSynchronizationDaemon.PROTOCOL_VERSION){
|
||||||
|
logger.warning("Protocol version do not match, skipping user. " +
|
||||||
|
"(local v"+PCDataSynchronizationDaemon.PROTOCOL_VERSION+" != remote v"+version+")");
|
||||||
|
out.writeObject(null); // Tell server we are disconnecting
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
// Request peer data
|
// Request peer data
|
||||||
out.writeObject(new PeerDataReqDTO());
|
out.writeObject(new PeerDataReqDTO());
|
||||||
PeerDataRspDTO peerData = (PeerDataRspDTO) in.readObject();
|
PeerDataRspDTO peerData = (PeerDataRspDTO) in.readObject();
|
||||||
|
|
@ -98,10 +107,7 @@ public class PCDataSynchronizationClient implements HalDaemon {
|
||||||
logger.fine("Skipped sensor " + sensor.getId());
|
logger.fine("Skipped sensor " + sensor.getId());
|
||||||
}
|
}
|
||||||
out.writeObject(null); // Tell server we are disconnecting
|
out.writeObject(null); // Tell server we are disconnecting
|
||||||
out.close();
|
|
||||||
in.close();
|
|
||||||
s.close();
|
|
||||||
|
|
||||||
} catch (NoRouteToHostException|UnknownHostException|ConnectException e) {
|
} catch (NoRouteToHostException|UnknownHostException|ConnectException e) {
|
||||||
logger.warning("Unable to connect to "+ user.getHostname()+":"+user.getPort() +", "+ e.getMessage());
|
logger.warning("Unable to connect to "+ user.getHostname()+":"+user.getPort() +", "+ e.getMessage());
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
|
|
|
||||||
|
|
@ -28,6 +28,7 @@ import java.util.logging.Logger;
|
||||||
|
|
||||||
public class PCDataSynchronizationDaemon extends ThreadedTCPNetworkServer implements HalDaemon {
|
public class PCDataSynchronizationDaemon extends ThreadedTCPNetworkServer implements HalDaemon {
|
||||||
private static final Logger logger = LogUtil.getLogger();
|
private static final Logger logger = LogUtil.getLogger();
|
||||||
|
public static final int PROTOCOL_VERSION = 2;
|
||||||
|
|
||||||
|
|
||||||
public PCDataSynchronizationDaemon() {
|
public PCDataSynchronizationDaemon() {
|
||||||
|
|
@ -71,6 +72,7 @@ public class PCDataSynchronizationDaemon extends ThreadedTCPNetworkServer implem
|
||||||
|
|
||||||
try {
|
try {
|
||||||
Object obj = null;
|
Object obj = null;
|
||||||
|
out.writeInt(PROTOCOL_VERSION); // send our protocol version to client
|
||||||
while((obj = in.readObject()) != null){
|
while((obj = in.readObject()) != null){
|
||||||
if(obj instanceof PeerDataReqDTO){
|
if(obj instanceof PeerDataReqDTO){
|
||||||
logger.fine("Client requesting peer data");
|
logger.fine("Client requesting peer data");
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue