def Main(): # usage: experiment1_server.py <tmpfs_dir> [start|stop] tmpfs_dir = sys.argv[1] opt = sys.argv[2] if opt == "start": files = make_files( tmpfs_dir, "file" ) # write the filenames to a place where the client can find them fd = open( os.path.join( tmpfs_dir, "files.txt" ), "wb" ) for f in files: fd.write(f + "\n") # write the file hashes to a place where the client can find them fd = open( os.path.join( tmpfs_dir, "hashes.txt" ), "wb" ) for f in files: fd.write( str(iftfile.get_hash(os.path.join( tmpfs_dir, f))) + "\n") # write the filenames to a place where the client can find them fd = open( os.path.join( tmpfs_dir, "sizes.txt" ), "wb" ) for f in files: fd.write( str(os.stat( os.path.join(tmpfs_dir, f) ).st_size) + "\n") fd.close() print "serving..." os.chdir("/") #thread.start_new_thread( run_server, (tmpfs_dir, 8000) ) pid = os.fork() if pid == 0: run_server( tmpfs_dir, 8000 ) else: run_server( tmpfs_dir, 8001 ) return 0 elif opt == "stop": fd = open( os.path.join( tmpfs_dir, "files.txt" ) ) files = fd.readlines() fd.close() cleanup_files( tmpfs_dir, files ) os.popen("rm -rf " + os.path.join( tmpfs_dir, "files.txt") ).close() os.popen("rm -rf " + os.path.join( tmpfs_dir, "hashes.txt") ).close() os.popen("rm -rf " + os.path.join( tmpfs_dir, "sizes.txt") ).close() for f in files: os.popen("rm -rf " + os.path.join( tmpfs_dir, f ) ).close() return 0 print "usage: experiment2_server.py <tmpfs_dir> [start|stop]" return 1
iftproto.PROTO_PORTNUM:8080, 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,
try: proto_handle = server.make_protocol( 'iftsocket', connect_args, connect_args, 0.01, 0.01 ) assert proto_handle > 0, "make_protocol(\'iftsocket\') rc=" + str(proto_handle) except Exception, inst: print "couldn't use protocol iftsocket" print str(inst) rc = server.activate_protocol( proto_handle, {iftproto.PROTO_PORTNUM:8080}, True ) assert rc == [0,0], "activate_protocol rc=" + str(rc) fsize = os.stat( "/home/jude/raven/tools/iftd/testfile" ).st_size fhash = iftfile.get_hash( "/home/jude/raven/tools/iftd/testfile" ) job_attrs = { iftfile.JOB_ATTR_SRC_NAME:"/home/jude/raven/tools/iftd/testfile", iftfile.JOB_ATTR_DEST_NAME:"/tmp/testfile", iftfile.JOB_ATTR_PROTOS:"iftsocket", iftfile.JOB_ATTR_SRC_HOST:"localhost", iftfile.JOB_ATTR_DEST_HOST:"localhost", iftfile.JOB_ATTR_CHUNKSIZE:3, iftfile.JOB_ATTR_FILE_SIZE:fsize, iftfile.JOB_ATTR_FILE_HASH:fhash } rc = server.simple_send( proto_handle, job_attrs ) assert rc == 0, "simple_send: rc=" + str(rc)