Ejemplo n.º 1
0
 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();
   }
 }
Ejemplo n.º 2
0
 @Override
 protected void onSafePacket(PacketAdapter packet) {
   pck = packet;
   if (pck.isAckowledgment()) {
     ackpacket = (AckPacket) pck;
     ackPacket();
   } else {
     log.error("unexpected packet type recieved");
     tftpadapter.close();
   }
 }
Ejemplo n.º 3
0
 private void sendNextBlock() {
   int block = ++expectedBlock;
   byte[] bytes;
   try {
     bytes = chunker.getNext();
     sendData(bytes, block);
   } catch (IOException e) {
     try {
       log.error("IOExeption when reading file, sending error packet to client", e);
       sendError(UNDEFINED, "IOException");
     } catch (IOException e1) {
       log.error("IOException could not send error packet to client", e1);
     }
     tftpadapter.close();
   }
 }