コード例 #1
0
ファイル: mongoapi.py プロジェクト: pdxwebdev/yadaproject
 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 {}
コード例 #2
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()))
     }
コード例 #3
0
ファイル: mongoapi.py プロジェクト: pdxwebdev/yadaproject
 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 {}
コード例 #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()
コード例 #5
0
ファイル: server.py プロジェクト: pdxwebdev/yadapy
    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()
コード例 #6
0
ファイル: manager.py プロジェクト: pdxwebdev/yadapy
 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()))}