def createPeer(port=4000,ipaddress=None,startport=None,net=None): #import twisted.internet.reactor import sys, os if ipaddress != None: knownPeers = [(ipaddress, startport)] else: knownPeers = None #print knownPeers, port urn = "urn:peer:id:"+uuid.uuid1().__str__() peer = DefaultPeer(net,urn,port) #peer = DHTPeer(udpPort=port) #peer.joinNetwork(knownPeers) dhtpeer = peer.getDHTPeer() dhtpeer.joinNetwork(knownPeers)
def factorySimulationProcess(self): simulation = self.getSimulation() network = simulation.getNetwork() peer_number = 0 port = 4000 portalID = network.getPortalID() while ( ( peer_number < simulation.getNetwork().getPeers())):# and ( simulation.getSimInstance().now() < simulation.getSimulationTime() )): peer_number+=1 urn = "urn:peer:"+uuid.uuid1().__str__() logMsg = "Factoring Process %s => Simulation Time %10.2f making peer number : %s id %s" % (self.getName(),simulation.getSimInstance().now() ,peer_number, urn) SimulationProcessLogger().resgiterLoggingInfo(logMsg) #print logMsg peer = DefaultPeer(urn,port) self.createServices(peer,simulation.getResourcePeer(),simulation.getTransactionDateTimeStart(),simulation.getTransactionDateTimeStop()) #print peer.getServices().getElements().keys() self.createEquivalence(peer, simulation.getTransactionDateTimeStart(),simulation.getTransactionDateTimeStop()) self.createTrust(peer,network.getPeersFromLayout(peer),simulation.getTransactionNumber(),simulation.getTransactionDateTimeStart(),simulation.getTransactionDateTimeStop()) network.addPeer(peer) peer.connectPortal(portalID) t = threading.Thread( target = peer.mainLoop, args = [] ) t.start() port += 1 print "Defau Peer = %s = %s = %s = %s"%(datetime.today(), peer.getPID(),peer_number,simulation.getSimInstance().now()) randa = randint(5,10)# yield hold, self, randa