Exemplo n.º 1
0
 def postIdentity(self, data, decrypted):
     connection = Connection('localhost',27021)
     db = connection.yadaserver
     collection = db.identities
     node = Node(public_key = data['public_key'])
     node.sync(decrypted)
     node.save()
     return {}
Exemplo n.º 2
0
 def postRoutedFriendRequest(self, data, decrypted):
 
     node = Node(public_key=data['public_key'])
     node.set('data/friends', node.getFriends(), True)
     nodeComm = ManagerCommunicator(node)
     yadaserver = YadaServer()
     serverFriend = Node(node.getFriend(yadaserver.matchFriend(node)['public_key']))
     friendTest = Node.db.friends.find({'public_key': data['public_key'], 'friend.routed_public_key': decrypted['routed_public_key']})
     if friendTest.count() == 0:
         nodeComm.routeRequestThroughNode(serverFriend, decrypted['routed_public_key'], decrypted.get('name', decrypted['routed_public_key']), decrypted.get('avatar', ''))
         Node.db.friends.update({'public_key': data['public_key'], 'friend.routed_public_key': decrypted['routed_public_key']}, {"$set": {"friend.subscribed": "*"}})
         friend = Node.db.friends.find({'public_key': data['public_key'], 'friend.routed_public_key': decrypted['routed_public_key']})
         return {"status": "request sent", "friend": friend[0]['friend']}
     return {"status": "already friends"}
Exemplo n.º 3
0
    def postRoutedFriendRequest(self, data, decrypted):

        node = Node(public_key=data['public_key'])
        node.set('data/friends', node.getFriends(), True)
        nodeComm = ManagerCommunicator(node)
        yadaserver = YadaServer()
        serverFriend = Node(
            node.getFriend(yadaserver.matchFriend(node)['public_key']))
        friendTest = Node.db.friends.find({
            'public_key':
            data['public_key'],
            'friend.routed_public_key':
            decrypted['routed_public_key']
        })
        if friendTest.count() == 0:
            nodeComm.routeRequestThroughNode(
                serverFriend, decrypted['routed_public_key'],
                decrypted.get('name', decrypted['routed_public_key']),
                decrypted.get('avatar', ''))
            Node.db.friends.update(
                {
                    'public_key': data['public_key'],
                    'friend.routed_public_key': decrypted['routed_public_key']
                }, {"$set": {
                    "friend.subscribed": "*"
                }})
            friend = Node.db.friends.find({
                'public_key':
                data['public_key'],
                'friend.routed_public_key':
                decrypted['routed_public_key']
            })
            return {"status": "request sent", "friend": friend[0]['friend']}
        return {"status": "already friends"}
Exemplo n.º 4
0
    def onMessage(self, inbound, isBinary):
        """
        As soon as any data is received, write it back.
        """
        print 'got data!'
        f = open('/home/phablet/yadaserver.log', 'a')
        try:
            inboundObj = json.loads(inbound)
            if "METHOD" in inboundObj and inboundObj[
                    'METHOD'] == "CREATE_IDENTITY":
                f.write('got identity message')
                f.close()
                n = Node({}, {"name": ""})
                n._data['idlabel'] = inboundObj['DATA']
                n.save()
                return

            if "METHOD" in inboundObj and inboundObj[
                    'METHOD'] == "UPDATE_IDENTITY":
                f.write('got update identity message')
                f.close()
                print json.dumps(inboundObj, indent=2)
                n = Node(inboundObj['DATA'])
                n.save()
                return

        except:
            pass
        try:
            f.write('|---|%s|---|\n' % inbound)
            #f.write(json.dumps(inbound))
            #response = nodeComm.handlePacket(inbound)
            #returnData = json.dumps(response)
            """
		This is generally where a qr scanner would forward the object to postFriend api endpoint.
		instead, we're going to 
	    """
            print "about to start notify.py"
            r = requests.get(inbound)
            friend = r.text
            call(['python', '/home/phablet/notify.py', friend])
            self.sendMessage('OK')
        except:
            exc_type, exc_value, exc_traceback = sys.exc_info()
            lines = traceback.format_exception(exc_type, exc_value,
                                               exc_traceback)
            f.write(''.join('!! ' + line for line in lines))
            self.transport.write('Input not valid.')
            f.close()
Exemplo n.º 5
0
 def createIdentity(self, data, decrypted):
     node = Node({}, decrypted)
     node.save()
     return {
         'public_key':
         node.get('public_key'),
         'method':
         'GET',
         'data':
         encrypt(node.get('private_key'), node.get('private_key'),
                 json.dumps(node.get()))
     }
Exemplo n.º 6
0
 def postFriend(self, data, decrypted):
     node = Node(public_key = data['public_key'])
     if 'messages' not in decrypted['data']:
         decrypted['data']['messages'] = []
     if 'friends' not in decrypted['data']:
         decrypted['data']['friends'] = []
     if 'public_key' not in decrypted:
         decrypted['public_key'] = []
     if 'private_key' not in decrypted:
         decrypted['private_key'] = []
     friend = Node(decrypted)
     node.addFriend(friend.get())
     node.save()
     return {}
Exemplo n.º 7
0
    def onMessage(self, inbound, isBinary):
        """
        As soon as any data is received, write it back.
        """
        print 'got data!'
	f = open('/home/phablet/yadaserver.log', 'a')
        try:
            inboundObj = json.loads(inbound)
            if "METHOD" in inboundObj and inboundObj['METHOD'] == "CREATE_IDENTITY":
                f.write('got identity message')
                f.close()
                n = Node({}, {"name": ""})
                n._data['idlabel'] = inboundObj['DATA']
                n.save()
                return

            if "METHOD" in inboundObj and inboundObj['METHOD'] == "UPDATE_IDENTITY":
                f.write('got update identity message')
                f.close()
                print json.dumps(inboundObj, indent=2)
                n = Node(inboundObj['DATA'])
                n.save()
                return

        except:
	    pass
        try:
            f.write('|---|%s|---|\n' % inbound)
            #f.write(json.dumps(inbound))
	    #response = nodeComm.handlePacket(inbound)
            #returnData = json.dumps(response)
            """
		This is generally where a qr scanner would forward the object to postFriend api endpoint.
		instead, we're going to 
	    """
            print "about to start notify.py"
	    r = requests.get(inbound)
            friend = r.text
            call (['python', '/home/phablet/notify.py', friend])
            self.sendMessage('OK')
        except:
	    exc_type, exc_value, exc_traceback = sys.exc_info()
	    lines = traceback.format_exception(exc_type, exc_value, exc_traceback)
    	    f.write(''.join('!! ' + line for line in lines))
            self.transport.write('Input not valid.')
            f.close()
Exemplo n.º 8
0
 def createIdentity(self, data, decrypted):
     node = Node({}, decrypted)
     node.save()
     return {'public_key': node.get('public_key'), 'method': 'GET', 'data': encrypt(node.get('private_key'), node.get('private_key'), json.dumps(node.get()))}
Exemplo n.º 9
0
 def getIdentity(self, data, decrypted):
     node = Node(public_key=data['public_key'], host='localhost', port=27017)
     return {'identity':node.get('data/identity'), 'requestType':'getIdentity'}
Exemplo n.º 10
0
 def getFriendRequest(self, data, decrypted):
     posts = []
     connection = Connection('localhost',27021)
     db = connection.yadaserver
     
     friend = db.command(
             {
                 "aggregate" : "identities", "pipeline" : [
                     {
                         "$match" : {
                             "public_key" : data['public_key']
                         }
                     },
                     {
                         "$match" : {
                             "data.friends" : { "$not" : {"$size" : 0}}
                         }
                     },
                     {
                         "$project" : {
                             "friend" : "$data.friends",
                         }
                     },
                     {
                         "$unwind" : "$friend"
                      },
                     {
                         "$match" : {
                             "friend.data.routed_friend_requests" : { "$not" : {"$size" : 0}}
                         }
                     },
                     {
                         "$unwind" : "$friend.data.routed_friend_requests"
                     },
                     {
                         "$match" : {
                             "friend.data.routed_friend_requests.public_key" : decrypted['public_key']
                         }
                     },
                     {
                         "$project" : {
                                       "routed_public_key" :"$friend.data.routed_friend_requests.routed_public_key",
                                       "friendRequest" : "$friend.data.routed_friend_requests"
                                     }
                     },
                 ]
             })['result']
             
     localFriendRequest = db.command(
         {
             "aggregate" : "identities", "pipeline" : [
                 {
                     "$match" : {
                         "public_key" : data['public_key']
                     }
                 },
                 {
                     "$match" : {
                         "friend_requests" : { "$not" : {"$size" : 0}}
                     }
                 },
                 {
                     "$unwind" : "$friend_requests"
                  },
                 {
                     "$match" : {
                         "friend_requests.public_key" : decrypted['public_key']
                     }
                 },
                 {
                     "$project" : {
                                   "request_public_key" : "$friend_requests.public_key",
                                   "friendRequest" : "$friend_requests"
                                 }
                 },
             ]
         })['result']
         
     try:
         friend = friend[0]
     except:
         friend = localFriendRequest[0]
     friendNode = Node(friend['friendRequest'])
     friendNode.stripIdentityAndFriendsForProtocolV1()
     return friendNode.get()