def chordStart(self, bootstrapNodeList, isBootstrapNode, enableAutoDiscovery, myPort, myIP, statusCallback, enclaveToJoin, nodeID, authenticationPayload): ''' Start Chord using the given parameters ''' # Find a live bootstrap node bootstrapNodeLocation = yield Utils.findLiveBootstrapNode(bootstrapNodeList, enableAutoDiscovery) log.msg("DEBUG: chordStart: bootstrapNodeLocation returned: %s" % bootstrapNodeLocation, system="chordStart") if bootstrapNodeLocation is None: if isBootstrapNode: # This is okay, we are just the only node. bootstrapNodeIP = None bootstrapNodePort = None else: # Failure... we can't startup by ourselves! log.msg("Failed to join because could not find a live bootstrap node.") statusCallback(False, None) return else: bootstrapNodeIP = bootstrapNodeLocation.ip bootstrapNodePort = bootstrapNodeLocation.port # Setup the bootstrap node location list if bootstrapNodeList == None: bootstrapNodeList = [] if bootstrapNodeIP is not None and bootstrapNodePort is not None: bootstrapNodeList.append( NodeLocation(None,bootstrapNodeIP,bootstrapNodePort)) # Figure out the enclave we're joining if bootstrapNodeIP == None and bootstrapNodePort == None: if enclaveToJoin is None: enclaveToJoin = 'localhost' else: # There is another node we can get info from if enclaveToJoin is None or enclaveToJoin == 'fromBootstrap': # Figure it out from the bootstrap node enclaveToJoin = yield self.findEnclave(bootstrapNodeIP, bootstrapNodePort) else: # Check if the bootstrap node is consistent status = yield self.checkEnclave(bootstrapNodeIP, bootstrapNodePort, enclaveToJoin) if not status: raise Exception('Bootstrap node is not part of enclave [%s]. Cannot join like that.' % enclaveToJoin) print("DEBUG: ChordStart: enclave to join is : %s : %s " % (enclaveToJoin, type(enclaveToJoin))) # Get the node ID for this Node/Enclave if nodeID == None: raise Exception("Programming error. NodeID cannot be None.") # Make sure it's an int if not isinstance( nodeID, ( int, long ) ): raise Exception("Programming error. NodeID must be an int.") # Set myPort and myIP if myPort is None: raise Exception("No port specified in ChordStart. No can do!") # This is the IP of the node. Note: This MUST be # an external ID or the code won't work! allowFloatingIP = myIP == None # Do we allow chord node to change the IP? True | False if myIP is None: if bootstrapNodeIP is None: myIP = socket.gethostbyname(socket.gethostname()) # To use ipNode, We need bootstrapNodeLocation. # Not sure how to change this code if we need external IP? # Maybe this code is fine. -Fengwei else: # There is someone else to ask! # Create an IPNode ipNode = NetworkUtils.IPNode() # The IP address should get from the IPNode in case of NAT try: myIP = yield ipNode.getRemoteIP(bootstrapNodeLocation) except: log.err() # Now startup the node log.msg("ClassChord API| Starting Chord Node on Port: %s:%s:%s" %(myIP, myPort, enclaveToJoin)) self.chordNode = ChordNode(myIP, myPort, nodeID, allowFloatingIP) self.chordNode.setAuthenticator(self.classChordClientObj) # Who can auth messages for us? self.serverFactory = GmuServerFactory(self.chordNode) deferResult = self.chordNode.join(bootstrapNodeList,enableAutoDiscovery, enclaveToJoin, authenticationPayload, isBootstrapNode, factory=self.serverFactory) deferResult.addBoth(self.joinComplete, statusCallback) # This is our callback, we use it to set some things upon completion.