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"}
from yadapy.db.mongodb.node import Node 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. """