Ejemplo n.º 1
0
 def joinNetwork(self, knownNodeAddresses=None):
     self._log.info('Joining network')
     StaticTupleSpacePeer.joinNetwork(self, knownNodeAddresses)
     self._joinDeferred.addCallback(self.startServices)
     self._joinDeferred.addCallback(self._execCallQueue)
     self._joinDeferred.addErrback(self._joinFailed)
Ejemplo n.º 2
0
        sys.exit(1)
    try:
        int(sys.argv[1])
    except ValueError:
        print '\nUDP_PORT must be an integer value.\n'
        print 'Usage:\n%s UDP_PORT  [KNOWN_NODE_IP  KNOWN_NODE_PORT]' % sys.argv[0]
        print 'or:\n%s UDP_PORT  [FILE_WITH_KNOWN_NODES]' % sys.argv[0]
        print '\nIf a file is specified, it should contain one IP address and UDP port\nper line, seperated by a space.'
        sys.exit(1)

    if len(sys.argv) == 4:
        knownNodes = [(sys.argv[2], int(sys.argv[3]))]
    elif len(sys.argv) == 3:
        knownNodes = []
        f = open(sys.argv[2], 'r')
        lines = f.readlines()
        f.close()
        for line in lines:
            ipAddress, udpPort = line.split()
            knownNodes.append((ipAddress, int(udpPort)))
    else:
        knownNodes = None

    node = StaticTupleSpacePeer( udpPort=int(sys.argv[1]) )
    
    node.joinNetwork(knownNodes)
    node._joinDeferred.addCallback(startServices)
    node._joinDeferred.addErrback(checkStatus)
    
    #twisted.internet.reactor.callLater(0.5, node.get,'tuple')
    twisted.internet.reactor.run()
Ejemplo n.º 3
0
class NetworkCreationTest(unittest.TestCase):
    """ This test suite tests that a StaticTupleSpacePeer can contact its peers (know addresses) and 
        obtain the tuples(data) stored at those peers
    """
       
    def setUp(self):
                        
        # create a fake protocol to imitate communication with other nodes
        self._protocol = FakeRPCProtocol()
        
        # Note: The reactor is never started for this test. All deferred calls run sequentially, 
        # since there is no asynchronous network communication
        
        # create the node to be tested in isolation
        self.node = StaticTupleSpacePeer(networkProtocol=self._protocol)
        
        self.updPort = 81173
        
        
        # create a network with IP addresses, port numbers and the corresponding node ID
        self.network = [['nodeID1',('127.0.0.1', 12345)],['nodeID2',('146.24.1.1', 34567)], ['nodeID3',('147.22.1.16', 234566)]]
        self.dataStore = [['nodeID1', ('resource1','ivr1', 'nodeID1')], ['nodeID2', ('resource2','ivr2', 'nodeID2')],\
                           ['nodeID3', ('resource3','ivr3', 'nodeID3')]]
        self._protocol.createNetwork(self.network)
        self._protocol.createDataStore(self.dataStore)
        
    def testJoinNetwork(self):
        # get the known addresses from self.network
        knownAddresses = []
        for item in self.network:
            knownAddresses.append(item[1])
        
        # Attempt to join the network of known addresses
        self.node.joinNetwork(knownAddresses)
                       
        # Check that the contacts have been added to the nodes contactsList
        # construct the contacts used for testing
        expectedContactsList = []
        for item in self.network:
            cont = Contact(item[0], item[1][0], item[1][1], self._protocol)
            expectedContactsList.append(cont)
        
#        print 'expected list '
#        for conti in expectedContactsList:
#            print str(conti)
        
        actualContactsList = self.node.contactsList
        
#        print 'actual contacts list ' + str(actualContactsList)
#        for conti in actualContactsList:
#            print str(conti)
        
        # Check that the expected contacts list are the same as the actual contacts list populated during the join sequence
        self.failUnlessEqual(expectedContactsList, actualContactsList, \
                                 "Contacts List populated by peer during join sequence doesn't contain the expected contacts")
        
        
        # Check that the dataStore has been populated 
        for item in self.dataStore:
            expectedTuple = item[1]
            #print 'searching for: ' + str(item[1])
            returnedTuple = self.node.get(expectedTuple)
            #print 'returned Tuple ' + str(returnedTuple)
            
            # Check that the returnedTuple is the same as the expected tuple
            self.failUnlessEqual(expectedTuple[1], returnedTuple[1], \
                                 "The data store was not populated correctly, expected tuple to be stored")