private void ackPacket() { if (isExpectedBlockAck()) { if (chunker.hasNextByte()) { sendNextBlock(); } else { // no more blocks so close adapter tftpadapter.close(); } } else if (isWrapAround()) { expectedBlock = 0; if (chunker.hasNextByte()) { sendNextBlock(); } else { // no more blocks so close adapter tftpadapter.close(); } } else if (isPreviousBlockAck()) { log.error( "acknowledgment not for expected block number:" + expectedBlock + " instead, acknowledgment recieved for block number:" + ackpacket.getBlockNumber()); } else if (isGreaterAckThanBlock()) { log.error("out of order acknowledgment recieved"); } else { log.error("unexpected problem occured"); tftpadapter.close(); } }
private boolean isGreaterAckThanBlock() { return ackpacket.getBlockNumber() > expectedBlock; }
private boolean isWrapAround() { return 0 == ackpacket.getBlockNumber(); }
private boolean isPreviousBlockAck() { return ackpacket.getBlockNumber() < expectedBlock; }
private boolean isExpectedBlockAck() { return ackpacket.getBlockNumber() == expectedBlock; }