def handle(self, pkt, raddress, rport):
        "Handle a packet, hopefully an ACK since we just sent a DAT."
        if isinstance(pkt, TftpPacketACK):
            log.debug("Received ACK for packet %d" % pkt.blocknumber)
            # Is this an ack to the one we just sent?
            if self.context.next_block == pkt.blocknumber:
                if self.context.pending_complete:
                    log.info("Received ACK to final DAT, we're done.")
                    return None
                else:
                    log.debug("Good ACK, sending next DAT")
                    self.context.next_block += 1
                    log.debug("Incremented next_block to %d",
                        self.context.next_block)
                    self.context.pending_complete = self.sendDAT()

            elif pkt.blocknumber < self.context.next_block:
                log.warning("Received duplicate ACK for block %d"
                    % pkt.blocknumber)
                self.context.metrics.add_dup(pkt)

            else:
                log.warning("Oooh, time warp. Received ACK to packet we "
                         "didn't send yet. Discarding.")
                self.context.metrics.errors += 1
            return self
        elif isinstance(pkt, TftpPacketERR):
            log.error("Received ERR packet from peer: %s" % str(pkt))
            raise TftpException("Received ERR packet from peer: %s" % str(pkt))
        else:
            log.warning("Discarding unsupported packet: %s" % str(pkt))
            return self
def handle ( self , pkt , raddress , rport ) : if isinstance ( pkt , TftpPacketACK ) : log . debug ( "Received ACK for packet %d" % pkt . blocknumber ) if self . context . next_block == pkt . blocknumber : if self . context . pending_complete : log . info ( "Received ACK to final DAT, we're done." ) return None else : log . debug ( "Good ACK, sending next DAT" ) self . context . next_block += 1 log . debug ( "Incremented next_block to %d" , self . context . next_block ) self . context . pending_complete = self . sendDAT ( ) elif pkt . blocknumber < self . context . next_block : log . warning ( "Received duplicate ACK for block %d" % pkt . blocknumber ) self . context . metrics . add_dup ( pkt ) else : log . warning ( "Oooh, time warp. Received ACK to packet we " "didn't send yet. Discarding." ) self . context . metrics . errors += 1 return self elif isinstance ( pkt , TftpPacketERR ) : log . error ( "Received ERR packet from peer: %s" % str ( pkt ) ) raise TftpException ( "Received ERR packet from peer: %s" % str ( pkt ) ) else : log . warning ( "Discarding unsupported packet: %s" % str ( pkt ) ) return self
Handle a packet, hopefully an ACK since we just sent a DAT.