Exemplo n.º 1
0
def test1():
    from websocket._core import create_connection
    import json
    import cookies
    import config
    import time
    import urllib
    
    import ssl
    

    auth_key_client1 = urllib.quote(cookies.create_signed_value(config.SERVER_SECRET  , config.SERVER_AUTH_KEY_STRING ,"abhinav")) #urllib.quote("gRT1avr5ZUaGyLlVkhBeas8QdLx5a4EJCgdhYmhpbmF2")
    
    auth_key_client2 = urllib.quote(cookies.create_signed_value(config.SERVER_SECRET  , config.SERVER_AUTH_KEY_STRING ,"sindhu")) #urllib.quote("gRS9lTlvtfZTBsTbVb3XH4c3EkPKwYEICgZzaW5kaHU=")
    
    
    ws1 = create_connection("ws://localhost:8081/connectV3?auth_key="+auth_key_client1+"&data_type=json" , sslopt={"verify":False, "ca_certs":"/home/abhinav/any/allsparkrt_c/allspark_cert.pem"})
    print "created_connection 1"
    
    ws2 = create_connection("ws://localhost:8081/connectV3?auth_key="+auth_key_client2+"&data_type=json",sslopt={"verify":False, "ca_certs":"/home/abhinav/any/allsparkrt_c/allspark_cert.pem"})
    print "created_connection 2"
    
    time.sleep(1)
    
    ws1.send(json.dumps({'dest_id':"sindhu", "payload":"Hello world" }))
    print ws2.recv()
    ws2.send(json.dumps({'dest_id':"abhinav", "payload":"Hello world 2" }))

    print ws1.recv()
    print ws1.recv()
Exemplo n.º 2
0
def send_push_routerapp():
    import cookies
    import config
    auth_key = cookies.create_signed_value(config.SERVER_SECRET,
                                           config.SERVER_AUTH_KEY_STRING,
                                           "krDJDQIM14WgzGl")

    print get_data("http://192.168.1.109:8081/push_message?auth_key=" +
                   auth_key + "&to_nodes=" + json.dumps(["sindhu"]),
                   post=json.dumps({
                       "src_id":
                       "abhinav",
                       "timestamp":
                       1475238418310,
                       "payload2":
                       "",
                       "payload1":
                       "1475234654.001990079879761-QCyXLnaNtT__147536164876",
                       "type":
                       4,
                       "payload":
                       "1475234654.001990079879761-QCyXLnaNtT"
                   }),
                   headers={
                       "Connection": "keep-alive"
                   }).read()
Exemplo n.º 3
0
def test2():
    from websocket._core import create_connection
    from bson import json_util
    import cookies
    from database import Db
    import config
    import time

    db = Db()
    db.init()
    # this is where user connects to nodes
    db.remove_client_nodes("abhinav")
    client_node_id1 = db.create_node("abhinav", None, None, None)  # client
    client_node_id2 = db.create_node("abhinav", None, None, None)  # client

    print "creating nodes", client_node_id1, client_node_id2

    auth_key_client1 = cookies.create_signed_value(
        config.SERVER_SECRET, "auth",
        json_util.dumps({'node_id': client_node_id1}))

    auth_key_client2 = cookies.create_signed_value(
        config.SERVER_SECRET, "auth",
        json_util.dumps({'node_id': client_node_id2}))

    ws1 = create_connection("ws://192.168.1.146:8081/connect?auth_key=" +
                            auth_key_client1)
    print "created_connection 1"

    ws2 = create_connection("ws://192.168.1.146:8083/connect?auth_key=" +
                            auth_key_client2)
    print "created_connection 2"

    time.sleep(1)

    ws1.send(
        json_util.dumps({
            'dest_id': client_node_id2,
            "payload": "Hello world"
        }))
    time.sleep(0.1)
    print ws2.recv()
    time.sleep(0.1)
    print ws1.recv()

    ws1.send_close()
    ws2.send_close()
Exemplo n.º 4
0
def test1():
    from websocket._core import create_connection
    import json
    import cookies
    import config
    import time
    import urllib

    import ssl

    auth_key_client1 = urllib.quote(
        cookies.create_signed_value(config.SERVER_SECRET,
                                    config.SERVER_AUTH_KEY_STRING, "abhinav")
    )  #urllib.quote("gRT1avr5ZUaGyLlVkhBeas8QdLx5a4EJCgdhYmhpbmF2")

    auth_key_client2 = urllib.quote(
        cookies.create_signed_value(config.SERVER_SECRET,
                                    config.SERVER_AUTH_KEY_STRING, "sindhu")
    )  #urllib.quote("gRS9lTlvtfZTBsTbVb3XH4c3EkPKwYEICgZzaW5kaHU=")

    ws1 = create_connection(
        "ws://localhost:8081/connectV3?auth_key=" + auth_key_client1 +
        "&data_type=json",
        sslopt={
            "verify": False,
            "ca_certs": "/home/abhinav/any/allsparkrt_c/allspark_cert.pem"
        })
    print "created_connection 1"

    ws2 = create_connection(
        "ws://localhost:8081/connectV3?auth_key=" + auth_key_client2 +
        "&data_type=json",
        sslopt={
            "verify": False,
            "ca_certs": "/home/abhinav/any/allsparkrt_c/allspark_cert.pem"
        })
    print "created_connection 2"

    time.sleep(1)

    ws1.send(json.dumps({'dest_id': "sindhu", "payload": "Hello world"}))
    print ws2.recv()
    ws2.send(json.dumps({'dest_id': "abhinav", "payload": "Hello world 2"}))

    print ws1.recv()
    print ws1.recv()
Exemplo n.º 5
0
def test2():
    from websocket._core import create_connection
    from bson import json_util
    import cookies
    from database import Db
    import config
    import time
    
    db = Db()    
    db.init()
    # this is where user connects to nodes    
    db.remove_client_nodes("abhinav")    
    client_node_id1 = db.create_node("abhinav", None, None, None)# client
    client_node_id2 = db.create_node("abhinav", None, None , None)# client
    
    print "creating nodes" , client_node_id1, client_node_id2
    
    auth_key_client1 = cookies.create_signed_value(config.SERVER_SECRET , "auth", json_util.dumps({'node_id':client_node_id1}))
    
    auth_key_client2 = cookies.create_signed_value(config.SERVER_SECRET , "auth",json_util.dumps({'node_id':client_node_id2}))
        
    ws1 = create_connection("ws://192.168.1.146:8081/connect?auth_key="+auth_key_client1)
    print "created_connection 1"
    
    
    ws2 = create_connection("ws://192.168.1.146:8083/connect?auth_key="+auth_key_client2)
    print "created_connection 2"

    time.sleep(1)
    
    
    ws1.send(json_util.dumps({'dest_id':client_node_id2, "payload":"Hello world" }))
    time.sleep(0.1)
    print ws2.recv()
    time.sleep(0.1)
    print ws1.recv()
    
    ws1.send_close()
    ws2.send_close()
Exemplo n.º 6
0
def test0():
    import cookies
    import config

    trans_5C = "".join ([chr (x ^ 0x5C) for x in xrange(256)])
    trans_36 = "".join ([chr (x ^ 0x36) for x in xrange(256)])

    print config.SERVER_SECRET.translate(trans_5C)

    auth_key = cookies.create_signed_value(config.SERVER_SECRET  , config.SERVER_AUTH_KEY_STRING ,"f**k yo")
    print auth_key
    
    return True
Exemplo n.º 7
0
    def open_connections(node_ids , i , j, id):
        print "Spinning a thread ", id, "node_ids from ", i , j
        for p in range(i , j):
            node_id = node_ids[p]
            try:
                auth_key = cookies.create_signed_value(config.SERVER_SECRET  , config.SERVER_AUTH_KEY_STRING ,node_id)
#               ws = create_connection("ws://104.199.129.250:8081/connectV2?auth_key="+auth_key)
                ws = create_connection("ws://35.xxxxxxxx/connectV3?auth_key="+auth_key)
                #print "created connection", ws
                node_connections[node_id] = ws
                tasklets.append(gevent.spawn(recv_message , ws))
            except Exception as e: 
                print "exception opening connection"
                pass
Exemplo n.º 8
0
def test0():
    import cookies
    import config

    trans_5C = "".join([chr(x ^ 0x5C) for x in xrange(256)])
    trans_36 = "".join([chr(x ^ 0x36) for x in xrange(256)])

    print config.SERVER_SECRET.translate(trans_5C)

    auth_key = cookies.create_signed_value(config.SERVER_SECRET,
                                           config.SERVER_AUTH_KEY_STRING,
                                           "f**k yo")
    print auth_key

    return True
Exemplo n.º 9
0
 def open_connections(node_ids, i, j, id):
     print "Spinning a thread ", id, "node_ids from ", i, j
     for p in range(i, j):
         node_id = node_ids[p]
         try:
             auth_key = cookies.create_signed_value(
                 config.SERVER_SECRET, config.SERVER_AUTH_KEY_STRING,
                 node_id)
             #               ws = create_connection("ws://104.199.129.250:8081/connectV2?auth_key="+auth_key)
             ws = create_connection("ws://35.xxxxxxxx/connectV3?auth_key=" +
                                    auth_key)
             #print "created connection", ws
             node_connections[node_id] = ws
             tasklets.append(gevent.spawn(recv_message, ws))
         except Exception as e:
             print "exception opening connection"
             pass
Exemplo n.º 10
0
 def get_connection_auth_key(cls, node_id, connection_id):
     return cookies.create_signed_value(config.SERVER_SECRET, config.SERVER_AUTH_KEY_STRING  , json_util.dumps({"node_id":node_id, "connection_id":connection_id}))
Exemplo n.º 11
0
 def create_connection_validation_key(cls, node_id):
     return cookies.create_signed_value(config.SERVER_SECRET, config.SERVER_AUTH_KEY_STRING  , json_util.dumps({"node_id":node_id, "timestamp":int(time.time())}))
Exemplo n.º 12
0
def send_push_routerapp():
    import cookies 
    import config
    auth_key = cookies.create_signed_value(config.SERVER_SECRET  , config.SERVER_AUTH_KEY_STRING , "krDJDQIM14WgzGl")
       
    print get_data("http://192.168.1.109:8081/push_message?auth_key="+auth_key+"&to_nodes="+json.dumps(["sindhu"]), post=json.dumps({"src_id": "abhinav", "timestamp": 1475238418310, "payload2": "", "payload1": "1475234654.001990079879761-QCyXLnaNtT__147536164876", "type": 4, "payload": "1475234654.001990079879761-QCyXLnaNtT"}), headers={"Connection":"keep-alive"}).read()