Ejemplo n.º 1
0
    def Indexer_managedFriendRequest(self):

        #setup the server
        serverObject = YadaServer({}, {"name": "yada server"})

        #setup the nodes
        data = Node({}, {'name': 'node 1'})
        friend = Node({}, {'name': 'node 2'})

        #setup the indexer
        host = str(uuid4()).replace('-', '') + '.com'
        indexer = Node({}, {"name": host})

        #make the nodes and indexer hosted on server
        serverObject.add(
            'data/managed_nodes',
            [data.get(), friend.get(), indexer.get()], True)

        #for the sake of the test, just force approved friendships on the nodes and indexer with the server
        serverObject.forceJoinNodes(data, serverObject)
        serverObject.forceJoinNodes(friend, serverObject)
        serverObject.forceJoinNodes(indexer, serverObject)

        #also force joining the nodes to the indexer so they will be able to route and retrieve friend requests
        newFriend = serverObject.forceJoinNodes(data, indexer)
        newFriend = serverObject.forceJoinNodes(friend, indexer)

        #test to see if any friend requests exists in the indexer already, this should fail
        self.assertEqual([], indexer.get('data/routed_friend_requests'))

        nc = NodeCommunicator(serverObject)
        #now we do the actual friend request where we route a request from data to indexer
        newFriend = nc.routeRequestThroughNode(indexer,
                                               newFriend['public_key'])
        #we now assert that the friend request was added successfully to the routed_friend_requests array of the indexer
        self.assertTrue(len(indexer.get('data/routed_friend_requests')) > 0)

        friendRequests = serverObject.getFriendRequestsFromIndexer(
            friend, indexer)
        self.assertEqual(friendRequests.keys(), {'friend_requests': ''}.keys())
        self.assertEqual(friendRequests['friend_requests'][0]['public_key'],
                         newFriend['public_key'])
Ejemplo n.º 2
0
    def Messaging(self):
                
        if os.getenv('PRODUCTION'):
            host1 = 'localhost:8040'
        else:
            host1 = 'yadaproject.com:8040'
            
        node1name = str(uuid4())
        
        node1 = Node({}, {"name" : node1name})
        
 
        nc1 = NodeCommunicator(node1)
         
        nc1.requestFriend(host1)
        
        uuidSubject = str(uuid4())
        nc1.sendMessage(nc1.node.getFriendPublicKeysArray(), uuidSubject, "message")
        import urllib2
        json = urllib2.urlopen("http://" + host1).read()
        self.assertTrue(uuidSubject in json)
Ejemplo n.º 3
0
 def postMessage(self, data, decrypted):
     friends_indexed = []
     connection = Connection('localhost',27021)
     db = connection.yadaserver
     data = Node(public_key = data['public_key'])
     dataNodeComm = NodeCommunicator(data, self.nodeComm.node)
     try:
         message = b64decode(decrypted['message'])
     except:
         message = decrypted['message']
     dataNodeComm.sendMessage(pub_keys=decrypted['public_key'], subject=decrypted['subject'], message=message, thread_id=decrypted['thread_id'], guid=decrypted['guid'])
     
     """
     selectedFriends = {}
     for i, friend in enumerate(data['data']['friends']):
         if friend['public_key'] in decrypted['public_key']:
             selectedFriends[friend['public_key']] = friend
     for i, friend in enumerate(decrypted['public_key']):
         data['public_key'] = selectedFriends[friend]['public_key']
         data['private_key'] = selectedFriends[friend]['private_key']
         hostedUserUpdate({"method" : "POST", "public_key" :friend, "data" : encrypt(selectedFriends[friend]['private_key'], selectedFriends[friend]['private_key'], json.dumps(data, cls=MongoEncoder))})
     """
     return {}
Ejemplo n.º 4
0
    def Indexer_managedFriendRequest(self):
        
        #setup the server
        serverObject = YadaServer({}, {"name" : "yada server"})
        
        #setup the nodes
        data = Node({}, { 'name' : 'node 1'})
        friend = Node({}, { 'name' : 'node 2'})
        
        #setup the indexer
        host = str(uuid4()).replace('-','') + '.com'
        indexer = Node({}, {"name" : host})

        #make the nodes and indexer hosted on server
        serverObject.add('data/managed_nodes', [data.get(), friend.get(), indexer.get()], True)
        
        #for the sake of the test, just force approved friendships on the nodes and indexer with the server
        serverObject.forceJoinNodes(data, serverObject)
        serverObject.forceJoinNodes(friend, serverObject)
        serverObject.forceJoinNodes(indexer, serverObject)
        
        #also force joining the nodes to the indexer so they will be able to route and retrieve friend requests
        newFriend = serverObject.forceJoinNodes(data, indexer)
        newFriend = serverObject.forceJoinNodes(friend, indexer)
        
        #test to see if any friend requests exists in the indexer already, this should fail
        self.assertEqual([], indexer.get('data/routed_friend_requests'))
        
        nc = NodeCommunicator(serverObject)
        #now we do the actual friend request where we route a request from data to indexer
        newFriend = nc.routeRequestThroughNode(indexer, newFriend['public_key'])
        #we now assert that the friend request was added successfully to the routed_friend_requests array of the indexer
        self.assertTrue(len(indexer.get('data/routed_friend_requests')) > 0)
        
        friendRequests = serverObject.getFriendRequestsFromIndexer(friend, indexer)
        self.assertEqual(friendRequests.keys(),{'friend_requests' : ''}.keys())
        self.assertEqual(friendRequests['friend_requests'][0]['public_key'], newFriend['public_key'])
Ejemplo n.º 5
0
    def Messaging(self):

        if os.getenv('PRODUCTION'):
            host1 = 'localhost:8040'
        else:
            host1 = 'yadaproject.com:8040'

        node1name = str(uuid4())

        node1 = Node({}, {"name": node1name})

        nc1 = NodeCommunicator(node1)

        nc1.requestFriend(host1)

        uuidSubject = str(uuid4())
        nc1.sendMessage(nc1.node.getFriendPublicKeysArray(), uuidSubject,
                        "message")
        import urllib2
        json = urllib2.urlopen("http://" + host1).read()
        self.assertTrue(uuidSubject in json)
Ejemplo n.º 6
0
    def addRemoteManager(self):

        if not os.getenv('PRODUCTION'):
            host1 = 'localhost'
            host2 = 'localhost'
        else:
            host1 = 'yadaproject.com'
            host2 = 'yadaproject.com'

        node1name = str(uuid4())
        node2name = str(uuid4())
        node1 = Node({}, {"name": node1name})
        node2 = Node({}, {"name": node2name})

        #we're trying to recreate the above test but with a remote manager
        #this is the code we need to make remote.
        nc1 = NodeCommunicator(node1)
        nc2 = NodeCommunicator(node2)

        #make the node hosted on server
        response = nc1.addManager("%s:8040" % host1)
        response = nc2.addManager("%s:8041" % host2)

        #we need to know about node 2 in the manager's friends list before we can request them.
        #we need another update from the manager before we can route a request to them, legally.
        nc1ServerFriend = Node(node1.get('data/friends')[0])
        nc1.updateRelationship(nc1ServerFriend)
        self.assertEqual(nc1ServerFriend.get('data/identity/name'), "node 1")

        nc1.requestFriend("%s:8041" % host2)

        #request to be friends with the manager's other friend (node 2)
        response = nc1.routeRequestThroughNode(
            Node(node1.get('data/friends')[1]),
            json.loads(response[1])['public_key'])
        self.assertEqual(len(nc1.node.get('data/friends')), 3)

        #lets pull down our new friend request
        nc2.updateRelationship(Node(node2.get('data/friends')[0]))
        self.assertEqual(
            len(
                node2.get('data/friends')[0]['data']
                ['routed_friend_requests']), 1)

        #get the request
        request = node2.get(
            'data/friends')[0]['data']['routed_friend_requests'][0]

        #accept the friend request
        node2.addFriend(request)

        #now we need to push the identity back because we just added a friend
        response = nc1.syncManager()
        response = nc2.syncManager()

        #now lets try to sync with the new friend, should automatically go to their manager
        nc2.updateRelationship(Node(node2.get('data/friends')[1]))

        response = nc1.syncManager()

        #now we verify that we can pull down the information from the new friend
        self.assertEqual(
            Node(node1.get('data/friends')[2]).get('data/identity/name'),
            node2name)
Ejemplo n.º 7
0
from api.node import MongoApi
from pymongo import Connection
from lib.crypt import decrypt
from subprocess import call

### Protocol Implementation
Node.host = 'localhost'
Node.port = 27017
Node.conn = Connection(Node.host, Node.port)
Node.db = Node.conn.yadaserver
Node.col = Node.db.identities
# This is just about the simplest possible protocol
YadaServer._data = {}
YadaServer._data['public_key'] = '84ce10c5-5970-4007-92a7-c1f00f0329c5'
ys = YadaServer()
nodeComm = NodeCommunicator(ys)
mongoapi = MongoApi(nodeComm)


class MyServerProtocol(WebSocketServerProtocol):
    def onConnect(self, request):
        print 'connected!'
        f = open('/home/phablet/yadaserver.log', 'a')
        f.write('connected2\n')
        f.close()

    def onMessage(self, inbound, isBinary):
        """
        As soon as any data is received, write it back.
        """
        print 'got data!'
Ejemplo n.º 8
0
    def addRemoteManager(self):
                
        if not os.getenv('PRODUCTION'):
            host1 = 'localhost'
            host2 = 'localhost'
        else:
            host1 = 'yadaproject.com'
            host2 = 'yadaproject.com'
            
        node1name = str(uuid4())
        node2name = str(uuid4())
        node1 = Node({}, {"name" : node1name})
        node2 = Node({}, {"name" : node2name})
        
 
        #we're trying to recreate the above test but with a remote manager
        #this is the code we need to make remote.
        nc1 = NodeCommunicator(node1)
        nc2 = NodeCommunicator(node2)
         
        #make the node hosted on server
        response = nc1.addManager("%s:8040" % host1)
        response = nc2.addManager("%s:8041" % host2)
        
        #we need to know about node 2 in the manager's friends list before we can request them.
        #we need another update from the manager before we can route a request to them, legally.
        nc1ServerFriend = Node(node1.get('data/friends')[0])
        nc1.updateRelationship(nc1ServerFriend)
        self.assertEqual(nc1ServerFriend.get('data/identity/name'), "node 1")
        
        nc1.requestFriend("%s:8041" % host2)
        
        #request to be friends with the manager's other friend (node 2)
        response = nc1.routeRequestThroughNode(Node(node1.get('data/friends')[1]), json.loads(response[1])['public_key'])
        self.assertEqual(len(nc1.node.get('data/friends')), 3)
        
        #lets pull down our new friend request
        nc2.updateRelationship(Node(node2.get('data/friends')[0]))
        self.assertEqual(len(node2.get('data/friends')[0]['data']['routed_friend_requests']), 1)
        
        #get the request
        request = node2.get('data/friends')[0]['data']['routed_friend_requests'][0]
        
        #accept the friend request
        node2.addFriend(request)
        
        #now we need to push the identity back because we just added a friend
        response = nc1.syncManager()
        response = nc2.syncManager()
        
        #now lets try to sync with the new friend, should automatically go to their manager
        nc2.updateRelationship(Node(node2.get('data/friends')[1]))
        
        response = nc1.syncManager()
        
        #now we verify that we can pull down the information from the new friend
        self.assertEqual(Node(node1.get('data/friends')[2]).get('data/identity/name'), node2name)