diff --git a/Cookie Protocol Spec.pdf b/Cookie Protocol Spec.pdf new file mode 100644 index 0000000000000000000000000000000000000000..d58eb831a0a56eb77f91b2acd0697fabe5a93467 Binary files /dev/null and b/Cookie Protocol Spec.pdf differ diff --git a/Documentation_codeChange_task2.docx b/Documentation_codeChange_task2.docx index 763a0c909aff210e8cfb5f8b39e9494777181455..cad8b3faeeb09dff0a4a593e8369f2b5a32ef2c4 100644 Binary files a/Documentation_codeChange_task2.docx and b/Documentation_codeChange_task2.docx differ diff --git a/Exercise - CP1.pdf b/Exercise - CP1.pdf new file mode 100644 index 0000000000000000000000000000000000000000..41f972a36b70897695592b3b6ff1a4a7f0077985 Binary files /dev/null and b/Exercise - CP1.pdf differ diff --git a/Exercise - CP2.pdf b/Exercise - CP2.pdf new file mode 100644 index 0000000000000000000000000000000000000000..8550033c79090c202aa0894df02ec8e04ef794d6 Binary files /dev/null and b/Exercise - CP2.pdf differ diff --git a/src/main/java/cp/CPCommandMessage.java b/src/main/java/cp/CPCommandMessage.java index dceda0a0e9c73378632cf5803a156fdc8c1e0f61..a8f71f49fd0b61cc1c189fe26bd4b65c8f0f94a5 100644 --- a/src/main/java/cp/CPCommandMessage.java +++ b/src/main/java/cp/CPCommandMessage.java @@ -9,7 +9,9 @@ public class CPCommandMessage extends CPMsg{ private int currentMessageId; protected static final String HEADER = "command"; - public CPCommandMessage() {} + public CPCommandMessage() { + + } public CPCommandMessage create(String cookie, String command, String message, int messageIdCount){ diff --git a/src/main/java/cp/CPCommandResponseMessage.java b/src/main/java/cp/CPCommandResponseMessage.java index 14e63b9bb736f479eb5e70da24c815a5e2b87c3c..9c8fb47128c14f8fee4e72f01c3d5122f7f0556b 100644 --- a/src/main/java/cp/CPCommandResponseMessage.java +++ b/src/main/java/cp/CPCommandResponseMessage.java @@ -78,7 +78,7 @@ public class CPCommandResponseMessage extends CPMsg{ //comparing the CRC checksum - System.out.println("Checksum: " + fields[fields.length - 1]); + //sets the received message as the data, so the client can print it on the console this.data = reconstructedMessage.toString(); diff --git a/src/main/java/cp/CPProtocol.java b/src/main/java/cp/CPProtocol.java index 15a823fab94f6e3f4bb3dc7f8ae0680b9bb569fa..e27711d71a2e7034589d3765d57d2b3e52f4375d 100644 --- a/src/main/java/cp/CPProtocol.java +++ b/src/main/java/cp/CPProtocol.java @@ -21,7 +21,7 @@ public class CPProtocol extends Protocol { private PhyConfiguration PhyConfig; private PhyProtocol PhyProto; boolean isClient; - HashMap<PhyConfiguration, Integer> cookieMap; + HashMap<PhyConfiguration, String> cookieMap; Random rnd; // Constructor for clients @@ -49,8 +49,9 @@ public class CPProtocol extends Protocol { //1.2: 1 a if(cookie != null) { - //does not send message if the maximal id is exeeded. increments id when command message is allowed to be created + //does not send message if the maximal id is exceeded. increments id when command message is allowed to be created if(messageIdCount >= MAX_ID){ + System.out.println("Max message Id Cont exceeded."); return; }else{ messageIdCount++; @@ -58,7 +59,7 @@ public class CPProtocol extends Protocol { //1.2: 1 b CPCommandMessage cmdMsg = new CPCommandMessage(); - cmdMsg.create(cookie, s, "status", messageIdCount); + cmdMsg.create(cookie, s, "", messageIdCount); //remembers the id of the current message, so when it's time to receive wel can check if the id's are the same this.id = cmdMsg.getMessageId(); @@ -92,6 +93,7 @@ public class CPProtocol extends Protocol { //Discard Message } + /* //discard message, if not instance of CPCommandMessage if(!(in instanceof CPCommandResponseMessage)){ continue; @@ -100,17 +102,21 @@ public class CPProtocol extends Protocol { //compare the id from the received message and the earlier sent message if(((CPCommandResponseMessage) in).getMessageId() != this.id){ continue; - } + }*/ receving = false; } - return in; } public void cookieProcesing(PhyConfiguration config, String cookie){ + if(cookieMap.size() >= CP_HASHMAP_SIZE){ + return; + } + + cookieMap.put(config, cookie); } diff --git a/src/main/java/cp/CPStatusCommand.java b/src/main/java/cp/CPStatusCommand.java new file mode 100644 index 0000000000000000000000000000000000000000..41cbd7d5cfada1c389bb1d2e3eafc464db20fc29 --- /dev/null +++ b/src/main/java/cp/CPStatusCommand.java @@ -0,0 +1,6 @@ +package cp; + +public class CPStatusCommand extends CPMsg{ + + +} diff --git a/src/main/java/phy/PhyConfiguration.java b/src/main/java/phy/PhyConfiguration.java index e323121e59f39816f9893f823e7c876ecbb8fe0b..121f9bd7ea9173b1d79327f65c5ff5914734c585 100644 --- a/src/main/java/phy/PhyConfiguration.java +++ b/src/main/java/phy/PhyConfiguration.java @@ -28,4 +28,13 @@ public class PhyConfiguration extends Configuration{ return this.remoteIPAddress; } public Protocol.proto_id getPid() {return this.pid;} + + + public boolean equals(PhyConfiguration otherConfig){ + return false; + } + public int hashCode(){ + + return 0; + } } diff --git a/src/test/java/phy/CPClientCookieRequestTest.java b/src/test/java/phy/CPClientCookieRequestTest.java index e89af21fd9e0d0b4b6fe7c28839a104d46e2a889..055227d5186165ece7da1be22051f6ee37b59b70 100644 --- a/src/test/java/phy/CPClientCookieRequestTest.java +++ b/src/test/java/phy/CPClientCookieRequestTest.java @@ -58,7 +58,7 @@ public class CPClientCookieRequestTest { when(phyProtocolMock.receive(anyInt())).thenReturn(testMsg); // Run the test - assertDoesNotThrow(()->cProtocol.requestCookie(1)); + assertDoesNotThrow(()->cProtocol.requestCookie(0)); // verify a specified behavior verify(phyProtocolMock, times(1)).receive(2000); @@ -77,7 +77,7 @@ public class CPClientCookieRequestTest { // Run the test assertThrows(CookieRequestException.class, - ()->cProtocol.requestCookie(1)); + ()->cProtocol.requestCookie(0)); verify(phyProtocolMock, times(1)).receive(2000); } @@ -96,7 +96,7 @@ public class CPClientCookieRequestTest { when(phyProtocolMock.receive(anyInt())).thenReturn(corruptedPhyMsg).thenReturn(testMsg); // Run the test - assertDoesNotThrow(()->cProtocol.requestCookie(1)); + assertDoesNotThrow(()->cProtocol.requestCookie(0)); verify(phyProtocolMock, times(2)).receive(2000); } @@ -113,7 +113,7 @@ public class CPClientCookieRequestTest { when(phyProtocolMock.receive(anyInt())).thenReturn(corruptedMsg).thenReturn(testMsg); // Run the test - assertDoesNotThrow(()->cProtocol.requestCookie(1)); + assertDoesNotThrow(()->cProtocol.requestCookie(0)); verify(phyProtocolMock, times(2)).receive(2000); } @@ -130,7 +130,7 @@ public class CPClientCookieRequestTest { when(phyProtocolMock.receive(anyInt())).thenReturn(corruptedMsg).thenReturn(testMsg); // Run the test - assertDoesNotThrow(()->cProtocol.requestCookie(1)); + assertDoesNotThrow(()->cProtocol.requestCookie(0)); verify(phyProtocolMock, times(2)).receive(anyInt()); } @@ -143,7 +143,7 @@ public class CPClientCookieRequestTest { // Run the test assertThrows(CookieRequestException.class, - ()->cProtocol.requestCookie(1)); + ()->cProtocol.requestCookie(0)); verify(phyProtocolMock, times(3)).receive(2000); }