Example #1
0
 def send_one_chunk( self, chunk, chunk_id, chunk_path, remote_chunk_path, job = None ):
    """
    Send a single chunk.
    
    @arg chunk
       The chunk data to send.  None is interpreted as "send the entire file"
    
    @arg chunk_id
       The numerical id of the chunk.  0 if chunk == None
    
    @arg chunk_path
       The path to the chunk on disk, or None if chunk != None
    
    @arg remote_chunk_path
       The path to which to send the chunk on the remote host.
    """
    
    stime = time.time()
    rc = self.send_chunk( chunk, chunk_id, chunk_path, remote_chunk_path )
    etime = time.time()
    
    status = False
    chunk_len = None
    if rc >= 0:
       status = True
    
    if chunk:
       chunk_len = max( len(chunk), rc )
    else:
       chunk_len = iftfile.get_filesize( self.ift_job.get_attr( iftfile.JOB_ATTR_SRC_NAME ) )
 
    if job == None:
       job = self.ift_job
       
    iftstats.log_chunk( job, self.name, status, stime, etime, chunk_len )
    return rc
Example #2
0
	iftfile.JOB_ATTR_SRC_NAME:"/home/jude/raven/tools/iftd/testfile",
	iftfile.JOB_ATTR_DEST_NAME:"/tmp/testfile",
	iftfile.JOB_ATTR_SRC_HOST:"localhost"
}

iftsocket_connect_attrs = {
   iftproto.PROTO_PORTNUM:4000
}

src_file = "/home/jude/raven/tools/iftd/testfile"

job_attrs = {
	iftfile.JOB_ATTR_SRC_HOST:"localhost",
	iftfile.JOB_ATTR_SRC_NAME:"/home/jude/raven/tools/iftd/testfile",
	iftfile.JOB_ATTR_FILE_HASH: iftfile.get_hash( src_file ),
	iftfile.JOB_ATTR_FILE_SIZE: iftfile.get_filesize( src_file ),
	protocols.raven.TRANSFER_PROGRAM_PACKAGE:"transfer.arizonatransfer_http",
	protocols.raven.INIT_TRANSFER_PROGRAM_ARG1:None,
	protocols.raven.INIT_TRANSFER_PROGRAM_ARG2:None,
	protocols.raven.INIT_TRANSFER_PROGRAM_ARG3:None,
	protocols.raven.INIT_TRANSFER_PROGRAM_ARG4:None,
	iftfile.JOB_ATTR_DEST_NAME:"/tmp/testfile",
	iftfile.JOB_ATTR_DEST_HOST:"localhost"
}

client = iftapi.make_XMLRPC_client()

connects = {
      "http_sender":http_connect_attrs,
      "http_receiver":http_connect_attrs,
      "iftsocket_receiver":iftsocket_connect_attrs,
Example #3
0
def get_iftd_sender_data( xmit_id, job_attrs, available_protos, connect_dict ):
   """
   Called by the receiver (remote) on the sender (local) to get
   the sender's capabilities--specifically, which protocols it
   has senders for, and where the chunks will be located.
   
   Return the list of protocols usable to both
   sender and receiver.
   """
   
   global TransferCore
   
   error_rc = (xmit_id, None, None, None, None, None, None, None) 
   file_name = job_attrs.get( iftfile.JOB_ATTR_SRC_NAME )
   user_job = iftfile.iftjob( job_attrs )
   
   # does the file exist?
   if not os.path.exists( file_name ):
      iftlog.log(5, "get_iftd_sender_data: file " + str(file_name) + " does not exist")
      return error_rc     # don't even bother
   
   # is the file readable?
   if not (stat.S_IWUSR & os.stat( file_name ).st_mode):
      iftlog.log(5, "get_iftd_sender_data: file " + str(file_name) + " is not readable")
      return error_rc     # don't bother--can't read
   
   # is the file accessible?
   from iftdata import SEND_FILES_DIR
   if SEND_FILES_DIR[-1] != '/':
      SEND_FILES_DIR = SEND_FILES_DIR + "/"
      
   if not os.path.abspath(file_name).startswith( SEND_FILES_DIR, 0, len(SEND_FILES_DIR)):
      iftlog.log(5, "get_iftd_sender_data: will not send " + str(file_name) + ", it is not in " + SEND_FILES_DIR )
      return error_rc     # access control violation


   # get our available protocols
   my_protos = proto_names( senders( list_protocols() ) )
   other_protos = []
   if available_protos:
      other_protos = proto_names( available_protos )
   
   # calculate intersection between both available protos
   my_protos_set = set( my_protos )
   other_protos_set = set( other_protos )
   usable_protos_set = my_protos_set.intersection( other_protos_set )
   file_size = iftfile.get_filesize( file_name )
 
   iftlog.log(1, "get_iftd_sender_data: file " + str(file_name) + ", size " + str(file_size))
   
   # start my passive senders
   sender_names = senders( list_protocols() )
   proto_insts = []
   for proto in sender_names:
      if PROTOCOLS.get(proto) != None and not PROTOCOLS.get(proto).isactive():
         p = None
         # start this passive sender
         try:
            p = copy.deepcopy( PROTOCOLS.get(proto) )
         except:
            iftlog.log(5, "get_iftd_sender_data: could not start passive sender " + proto)
            continue
         
         proto_insts.append(p)

   expected_fsize = user_job.get_attr( iftfile.JOB_ATTR_FILE_SIZE )
   min_fsize = user_job.get_attr( iftfile.JOB_ATTR_FILE_MIN_SIZE )
   max_fsize = user_job.get_attr( iftfile.JOB_ATTR_FILE_MAX_SIZE )
   
   # do some sanity checking...
   if min_fsize != None and max_fsize != None:
      if file_size < min_fsize or file_size > max_fsize:
         return error_rc      # wrong size expectation
   
   
   if expected_fsize != None and expected_fsize != file_size:
      return error_rc      # wrong size expectation
   

   # set up
   rc, file_hash, chunk_hashes, chunk_data = prepare_sender( file_name, user_job.get_attr( iftfile.JOB_ATTR_CHUNKSIZE ) )
   if rc != 0:
      iftlog.log(5, "get_iftd_sender_data: could not prepare to send")
      return error_rc

   
   user_job.supply_attr( iftfile.JOB_ATTR_FILE_SIZE, file_size )
   user_job.supply_attr( iftfile.JOB_ATTR_FILE_HASH, file_hash )
   user_job.supply_attr( iftfile.JOB_ATTR_FILE_TYPE, iftstats.filetype( file_name ) )

   passive_protos = start_passive_protos( connect_dict, user_job, proto_insts, 1.0 )
   
   
   # start passive protocol handling thread
   TransferCore.begin_ift_send( xmit_id, user_job, chunk_data, user_job.get_attr( iftfile.JOB_ATTR_CHUNK_TIMEOUT ), connect_dict )
   TransferCore.run_ift_send_passive( xmit_id, user_job, passive_protos, user_job.get_attr( iftfile.JOB_ATTR_CHUNK_TIMEOUT ))
   
   proto_mask = [0] * len(sender_names)
   
   for i in xrange(0, len(sender_names)):
      p = sender_names[i]
      if PROTOCOLS[p].isactive():
         proto_mask[i] = True
      else:
         proto_mask[i] = False
   
   return (xmit_id, iftfile.get_chunks_dir( file_name, file_hash, True), file_size, file_hash, iftstats.filetype(file_name), sender_names, proto_mask, chunk_hashes)