def phase_two(self): hash = None i = -1 for message in self.phase_two_messages: i += 1 # Sent ANP transport header log.debug("Phase 2: sending ANPT header %i, size %i." % ( i, message.size )) self.writer.send_command_header(kanp.KANP_CMD_KFS_PHASE_2, message.size) log.debug("Phase 2: sent ANPT header %i, size %i." % ( i, message.size )) # Send base message anp message. kanp.send_anpt_msg(self.writer, message.anpm) if not hash: hash = hashlib.md5() j = -1 for subm in message.sub_messages: j += 1 if isinstance(subm, PhaseTwoChunkSubMessage): # send chunk log.debug("Phase 2: preparing file %i chunk %i anp message." % ( i, j )) bytes = subm.chunk.read() hash.update(bytes) subm.anpm.add_bin(bytes) log.debug("Phase 2: sending file %i chunk %i anp message." % ( i, j )) kanp.send_anpt_msg(self.writer, subm.anpm) log.debug("Phase 2: sent file %i chunk %i anp message." % ( i, j )) else: assert isinstance(subm, PhaseTwoCommitSubMessage) # send commit log.debug("Phase 2: preparing file %i commit anp message." % ( i )) bytes = hash.digest() subm.anpm.add_bin(bytes) hash = hashlib.md5() log.debug("Phase 2: sending file %i commit anp message." % ( i )) kanp.send_anpt_msg(self.writer, subm.anpm) log.debug("Phase 2: sent file %i commit anp message." % ( i )) # get response log.debug("Phase 2: getting %i reply." % ( i )) h, m = kanp.get_anpt_all(self.reader) log.debug("Phase 2: got %i reply." % ( i )) if h.type == kanp.KANP_RES_FAIL: raise kanp.KANPFailure(m.get_u32(), m.get_str()) assert h.type == kanp.KANP_RES_OK # get response h, m = kanp.get_anpt_all(self.reader) log.debug("Phase 2: got final reply.") if h.type == kanp.KANP_RES_FAIL: raise kanp.KANPFailure(m.get_u32(), m.get_str()) assert h.type == kanp.KANP_RES_OK log.debug("File upload finished.")
def phase_2_send_message_with_one_submessage(self, subm): # Prepare ANP message. message = PhaseTwoMessage() message.anpm = kanp.ANP_msg() message.anpm.add_u32(1) # Send only one sub-message # Calculate base messasge size. message.size = message.anpm.get_payload_size() #log.debug("Base message size: %i bytes." % ( message.size )) # Calculate total sub-message size. subm.size = subm.anpm.get_payload_size() log.debug("Chunk sub-message size: %i bytes." % ( subm.size )) total_size = message.size + subm.size # Sent ANP transport header #log.debug("Phase 2: sending ANPT header with data size %i." % ( total_size )) self.writer.send_command_header(kanp.KANP_CMD_KFS_PHASE_2, total_size) #log.debug("Phase 2: sent ANPT header, size %i." % ( total_size )) # Send base message. kanp.send_anpt_msg(self.writer, message.anpm) # Send sub-message. kanp.send_anpt_msg(self.writer, subm.anpm) # get response #log.debug("Phase 2: getting reply.") h, m = kanp.get_anpt_all(self.reader) #log.debug("ANP RESPONSE DUMP: %s" % (str(m.dump()))) #log.debug("Phase 2: got reply.") if h.type == kanp.KANP_RES_FAIL: raise kanp.KANPFailure(m.get_u32(), m.get_str()) assert h.type == kanp.KANP_RES_OK
def phase_2_send_message_with_one_submessage(self, subm): # Prepare ANP message. message = PhaseTwoMessage() message.anpm = kanp.ANP_msg() message.anpm.add_u32(1) # Send only one sub-message # Calculate base messasge size. message.size = message.anpm.get_payload_size() #log.debug("Base message size: %i bytes." % ( message.size )) # Calculate total sub-message size. subm.size = subm.anpm.get_payload_size() log.debug("Chunk sub-message size: %i bytes." % (subm.size)) total_size = message.size + subm.size # Sent ANP transport header #log.debug("Phase 2: sending ANPT header with data size %i." % ( total_size )) self.writer.send_command_header(kanp.KANP_CMD_KFS_PHASE_2, total_size) #log.debug("Phase 2: sent ANPT header, size %i." % ( total_size )) # Send base message. kanp.send_anpt_msg(self.writer, message.anpm) # Send sub-message. kanp.send_anpt_msg(self.writer, subm.anpm) # get response #log.debug("Phase 2: getting reply.") h, m = kanp.get_anpt_all(self.reader) #log.debug("ANP RESPONSE DUMP: %s" % (str(m.dump()))) #log.debug("Phase 2: got reply.") if h.type == kanp.KANP_RES_FAIL: raise kanp.KANPFailure(m.get_u32(), m.get_str()) assert h.type == kanp.KANP_RES_OK
def phase_two(self): hash = None i = -1 for message in self.phase_two_messages: i += 1 # Sent ANP transport header log.debug("Phase 2: sending ANPT header %i, size %i." % (i, message.size)) self.writer.send_command_header(kanp.KANP_CMD_KFS_PHASE_2, message.size) log.debug("Phase 2: sent ANPT header %i, size %i." % (i, message.size)) # Send base message anp message. kanp.send_anpt_msg(self.writer, message.anpm) if not hash: hash = hashlib.md5() j = -1 for subm in message.sub_messages: j += 1 if isinstance(subm, PhaseTwoChunkSubMessage): # send chunk log.debug( "Phase 2: preparing file %i chunk %i anp message." % (i, j)) bytes = subm.chunk.read() hash.update(bytes) subm.anpm.add_bin(bytes) log.debug( "Phase 2: sending file %i chunk %i anp message." % (i, j)) kanp.send_anpt_msg(self.writer, subm.anpm) log.debug("Phase 2: sent file %i chunk %i anp message." % (i, j)) else: assert isinstance(subm, PhaseTwoCommitSubMessage) # send commit log.debug( "Phase 2: preparing file %i commit anp message." % (i)) bytes = hash.digest() subm.anpm.add_bin(bytes) hash = hashlib.md5() log.debug("Phase 2: sending file %i commit anp message." % (i)) kanp.send_anpt_msg(self.writer, subm.anpm) log.debug("Phase 2: sent file %i commit anp message." % (i)) # get response log.debug("Phase 2: getting %i reply." % (i)) h, m = kanp.get_anpt_all(self.reader) log.debug("Phase 2: got %i reply." % (i)) if h.type == kanp.KANP_RES_FAIL: raise kanp.KANPFailure(m.get_u32(), m.get_str()) assert h.type == kanp.KANP_RES_OK # get response h, m = kanp.get_anpt_all(self.reader) log.debug("Phase 2: got final reply.") if h.type == kanp.KANP_RES_FAIL: raise kanp.KANPFailure(m.get_u32(), m.get_str()) assert h.type == kanp.KANP_RES_OK log.debug("File upload finished.")