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"}
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. """
port = argSplit[1] connection = Connection('localhost',27021) db = connection.yadaserver manager = db.command( { "aggregate" : "identities", "pipeline" : [ { "$match" : { "data.identity.ip_address.address" : host, "data.identity.ip_address.port" : port, "data.type" : "manager" } }, ] })['result'] if len(manager): manager[0]['_id'] = str(manager[0]['_id']) node1 = manager[0] node1 = YadaServer(node1) else: node1 = YadaServer({}, {"name" : "node"}) node1.addIPAddress(host, port) node1.save() node1.save() nodeComm1 = NodeCommunicator(node1) tr = TestResource(nodeComm1, MongoApi(nodeComm1)) reactor.callInThread(tr.syncAllFriends) reactor.listenTCP(int(port), server.Site(tr)) reactor.run()