############################################################## # # Name: buddycast.py # # Description: buddycast algorithm # # Usage: python buddycast nodeid num_of_nodes instanceid num_of_instance other_prg_param # nodes is the cpu; instance is an instance over a cpu. # # other_prg_param including: # ExperimentType RandomCacheSize BuddyCacheSize r(i.e.Exploration/explitation Rate) ... # # author: Jun Wang j.wang@ewi.tudelft.nl # ############################################################## import struct import time import sys from ConfigParser import * from connectinterface import * from receiver import receiver from node import node def timestamp(): return time.time() def now(): return time.ctime(time.time()) #fsock = open('error.log','w') #sys.stderr = fsock serverportbase = 40000 clientportbase = 10000 ################################################ # reading paremeters ################################################ # Basic settings #print 'parameters for buddycast.py:', sys.argv[1:] nodeid = int(sys.argv[1]) numnodes = int(sys.argv[2]) instanceid = int(sys.argv[3]) numinstances = int(sys.argv[4]) # number of instance outputfile = sys.argv[5] outputfile = outputfile + '.' + str(instanceid) foutput = open(outputfile,'w') sys.stdout = foutput #print 'outputfile is:', outputfile #experiement setting #expType = str(sys.argv[5]) # experiement type #randCacheSize = int(sys.argv[6]) # #buddyCacheSize = int(sys.argv[7]) # #r = float(sys.argv[8]) # exploration/exploitation rate configdict = ConfigParser() configdict.read('/home3/jwang/buddycast/emulation.cfg') expType = configdict.getint('BUDDYCAST','ExperimentType') # experiement type randCacheSize = configdict.getint('BUDDYCAST','RandomCacheSize') buddyCacheSize = configdict.getint('BUDDYCAST','BuddyCacheSize') # r = configdict.getfloat('BUDDYCAST','r') # exploration/exploitation rate ############################################################### # make different experiements # expType = 'addingpeer' # : peer add to the network each by each # # expType = 'removingpeerpeer' # : peer is removed from the network each by each # expType = 'corrupt' # : a large number of peers suddently leaves the network # ################################################################ peer = node(nodeid,instanceid,numinstances,svrportbase = 50000,cltportbase = 10000, buddysize = buddyCacheSize, cachesize = randCacheSize) peerid = peer.info['peer_id'] #print '[peer:', peerid,']', 'initialization: tcp/ip configuration...', handle = receiver # make a threaded server, listen/handle clients forever time.sleep(0.05*int(peerid)) peer.startServer(handle) print 'done' print '[peer:', peerid,']', 'initialization: get user_pref...', peer.initialUserPref() user_pref = peer.info['user_pref'] sizePL = len(user_pref) print 'done', 'number of items in the user_pref:', sizePL time.sleep(3) print '[peer:', peerid,']', 'joining: bootstrap get a ramdom peer...', peer.initialCache(1) peers = peer.randCache.getAll() sizeCache = len(peers) print 'done', 'peer cache size:', sizeCache print '[peer:', peerid,']', 'joining: register ip and port...', while peer.info['ownport']== 'null': pass peer.register() print 'done' time.sleep(5) print 'Let us buddycast...' loop = 0 while loop < 10: time.sleep(0.5) peers = peer.randCache.getAll() peer.push() loop = loop + 1 time.sleep(20 - 0.05*int(peerid)) try: sys.exit() except : print '[peer:', peerid, ']', 'left...'