Exemplo n.º 1
0
 def get_network_info(self):
     self.dbManager = DatabaseManager(self.config_params.DATABASE_NAME)
     mixes = self.dbManager.select_all_mixnodes()
     providers = self.dbManager.select_all_providers()
     self.register_mixes([m for m in mixes if not m.name == self.name])
     self.register_providers(
         [p for p in providers if not p.name == self.name])
Exemplo n.º 2
0
 def get_network_info(self):
     self.dbManager = DatabaseManager(self.config_params.DATABASE_NAME)
     self.register_mixes(self.dbManager.select_all_mixnodes())
     self.register_providers(self.dbManager.select_all_providers())
     self.register_friends(self.dbManager.select_all_clients())
     self.provider = self.dbManager.select_provider_by_name(self.provider.name)
     log.msg("[%s] > Registered network information" % self.name)
Exemplo n.º 3
0
class LoopixClient(DatagramProtocol):
    jsonReader = JSONReader(
        os.path.join(os.path.dirname(__file__), 'config.json'))
    config_params = jsonReader.get_client_config_params()
    output_buffer = Queue()
    process_queue = ProcessQueue()
    reactor = reactor
    resolvedAdrs = {}

    def __init__(self,
                 sec_params,
                 name,
                 port,
                 host,
                 provider_id,
                 privk=None,
                 pubk=None):
        self.name = name
        self.port = port
        self.host = host
        self.privk = privk or sec_params.group.G.order().random()
        self.pubk = pubk or (self.privk * sec_params.group.G.generator())
        self.crypto_client = ClientCore((sec_params, self.config_params),
                                        self.name, self.port, self.host,
                                        self.privk, self.pubk)
        self.provider = Provider(name=provider_id)
        self.latency_file = open('latency.csv', 'a')

    def startProtocol(self):
        log.msg("[%s] > Started" % self.name)
        self.get_network_info()
        self.get_provider_data()
        self.subscribe_to_provider()
        self.turn_on_packet_processing()
        self.make_loop_stream()
        self.make_drop_stream()
        self.make_real_stream()

    def get_network_info(self):
        self.dbManager = DatabaseManager(self.config_params.DATABASE_NAME)
        self.register_mixes(self.dbManager.select_all_mixnodes())
        self.register_providers(self.dbManager.select_all_providers())
        self.register_friends(self.dbManager.select_all_clients())
        self.provider = self.dbManager.select_provider_by_name(
            self.provider.name)
        log.msg("[%s] > Registered network information" % self.name)

    def get_provider_data(self):
        self.provider = self.dbManager.select_provider_by_name(
            self.provider.name)
        try:
            result = socket.gethostbyname(self.provider.host)
            self.provider = self.provider._replace(host=result)
        except socket.gaierror, err:
            print(err)
Exemplo n.º 4
0
class LoopixMixNode(DatagramProtocol):
    jsonReader = JSONReader(
        os.path.join(os.path.dirname(__file__), 'config.json'))
    config_params = jsonReader.get_mixnode_config_params()
    reactor = reactor
    process_queue = ProcessQueue()
    resolvedAdrs = {}

    def __init__(self,
                 sec_params,
                 name,
                 port,
                 host,
                 group,
                 privk=None,
                 pubk=None):
        self.name = name
        self.port = port
        self.host = host
        self.group = group

        self.privk = privk or sec_params.group.G.order().random()
        self.pubk = pubk or (self.privk * sec_params.group.G.generator())
        self.crypto_node = MixCore((sec_params, self.config_params), self.name,
                                   self.port, self.host, self.privk, self.pubk)

    def startProtocol(self):
        print "[%s] > Started" % self.name
        self.get_network_info()
        self.turn_on_processing()
        self.make_loop_stream()

    def get_network_info(self):
        self.dbManager = DatabaseManager(self.config_params.DATABASE_NAME)
        mixes = self.dbManager.select_all_mixnodes()
        providers = self.dbManager.select_all_providers()
        self.register_mixes([m for m in mixes if not m.name == self.name])
        self.register_providers(
            [p for p in providers if not p.name == self.name])

    def register_mixes(self, mixes):
        self.pubs_mixes = group_layered_topology(mixes)

    def register_providers(self, providers):
        self.pubs_providers = providers

    def turn_on_processing(self):
        self.reactor.callLater(20.0, self.get_and_addCallback,
                               self.handle_packet)

    def get_and_addCallback(self, function):
        self.process_queue.get().addCallback(function)

    def make_loop_stream(self):
        self.send_loop_message()
        self.schedule_next_call(self.config_params.EXP_PARAMS_LOOPS,
                                self.make_loop_stream)

    def send_loop_message(self):
        path = self.generate_random_path()
        packet = self.crypto_node.create_loop_message(path)
        addr = (path[0].host, path[0].port)
        self.send(packet, addr)

    def generate_random_path(self):
        return self.construct_full_path()

    def construct_full_path(self):
        sequence = []
        num_all_layers = len(self.pubs_mixes)
        layer = self.group + 1
        while layer != self.group:
            mix = random.choice(self.pubs_mixes[layer % num_all_layers])
            sequence.append(mix)
            layer = (layer + 1) % num_all_layers
        sequence.insert(num_all_layers - 1 - self.group,
                        random.choice(self.pubs_providers))
        return sequence

    def schedule_next_call(self, param, method):
        interval = sample_from_exponential(param)
        self.reactor.callLater(interval, method)

    def datagramReceived(self, data, (host, port)):
        self.process_queue.put(data)
Exemplo n.º 5
0
class LoopixClient(DatagramProtocol):
    jsonReader = JSONReader(os.path.join(os.path.dirname(__file__), 'config.json'))
    config_params = jsonReader.get_client_config_params()
    output_buffer = Queue()
    process_queue = ProcessQueue()
    reactor = reactor
    resolvedAdrs = {}

    def __init__(self, sec_params, name, port, host, provider_id, privk=None, pubk=None):
        self.name = name
        self.port = port
        self.host = host
        self.privk = privk or sec_params.group.G.order().random()
        self.pubk = pubk or (self.privk * sec_params.group.G.generator())
        self.crypto_client = ClientCore((sec_params, self.config_params), self.name,
                                        self.port, self.host, self.privk, self.pubk)
        self.provider = Provider(name=provider_id)


    def startProtocol(self):
        log.msg("[%s] > Started" % self.name)
        self.get_network_info()
        self.get_provider_data()
        self.subscribe_to_provider()
        self.turn_on_packet_processing()
        self.make_loop_stream()
        self.make_drop_stream()
        self.make_real_stream()

    def get_network_info(self):
        self.dbManager = DatabaseManager(self.config_params.DATABASE_NAME)
        self.register_mixes(self.dbManager.select_all_mixnodes())
        self.register_providers(self.dbManager.select_all_providers())
        self.register_friends(self.dbManager.select_all_clients())
        self.provider = self.dbManager.select_provider_by_name(self.provider.name)
        log.msg("[%s] > Registered network information" % self.name)

    def get_provider_data(self):
        self.provider = self.dbManager.select_provider_by_name(self.provider.name)
        d = twisted.names.client.getHostByName(self.provider.host)
        d.addCallback(self.resolve_provider_address)

    def resolve_provider_address(self, result):
        self.provider = self.provider._replace(host = result)

    def subscribe_to_provider(self):
        lc = task.LoopingCall(self.send, ['SUBSCRIBE', self.name, self.host, self.port])
        lc.start(self.config_params.TIME_PULL, now=True)

    def register_mixes(self, mixes):
        self.pubs_mixes = group_layered_topology(mixes)

    def register_providers(self, providers):
        self.pubs_providers = providers

    def register_friends(self, clients):
        self.befriended_clients = clients

    def turn_on_packet_processing(self):
        self.retrieve_messages()
        self.reactor.callLater(20.0, self.get_and_addCallback, self.handle_packet)
        log.msg("[%s] > Turned on retrieving and processing of messages" % self.name)

    def retrieve_messages(self):
        lc = task.LoopingCall(self.send, ['PULL', self.name])
        lc.start(self.config_params.TIME_PULL, now=True)

    def get_and_addCallback(self, function):
        self.process_queue.get().addCallback(function)

    def datagramReceived(self, data, (host, port)):
        self.process_queue.put(data)
Exemplo n.º 6
0
def readFiles():
    import petlib.pack

    # sys.path += ["../loopix"]
    # local("rm -f example.db")

    #import databaseConnect as dc
    from database_connect import DatabaseManager
    databaseName = "example.db"
    dbManager = DatabaseManager(databaseName)
    dbManager.create_users_table("Users")
    dbManager.create_providers_table("Providers")
    dbManager.create_mixnodes_table("Mixnodes")

    for f in os.listdir('.'):
        if f.endswith(".bin"):
            with open(f, 'rb') as fileName:
                lines = petlib.pack.decode(fileName.read())
                print 'Lines: ', lines
                if lines[0] == "client":
                    dbManager.insert_row_into_table('Users', [
                        None, lines[1], lines[2], lines[3],
                        sqlite3.Binary(petlib.pack.encode(lines[4])), lines[5]
                    ])
                elif lines[0] == "mixnode":
                    dbManager.insert_row_into_table('Mixnodes', [
                        None, lines[1], lines[2], lines[3],
                        sqlite3.Binary(petlib.pack.encode(lines[5])), lines[4]
                    ])
                elif lines[0] == "provider":
                    dbManager.insert_row_into_table('Providers', [
                        None, lines[1], lines[2], lines[3],
                        sqlite3.Binary(petlib.pack.encode(lines[4]))
                    ])
                else:
                    assert False
    dbManager.close_connection()
Exemplo n.º 7
0
class LoopixClient(DatagramProtocol):
    jsonReader = JSONReader(
        os.path.join(os.path.dirname(__file__), 'config.json'))
    config_params = jsonReader.get_client_config_params()
    output_buffer = Queue()
    process_queue = ProcessQueue()
    reactor = reactor
    resolvedAdrs = {}
    number_of_chunks = 4  #depends on the quality/size of frame
    buffering = 200  #equals to pull size for simplicity on metrics
    stream_length = 1000000  #to chnage this consider adding more space to the body. 1 space for every digit
    stream_buffer = [[None for x in range(number_of_chunks)]
                     for y in range(stream_length)]  #hashtable for chunks
    chunk_count = [0] * stream_length  #hashtable to know a frame is full
    frames_received = 0
    frames_played = 0
    playing = False
    video_ended = False

    def __init__(self,
                 sec_params,
                 name,
                 port,
                 host,
                 provider_id,
                 privk=None,
                 pubk=None):
        self.name = name
        self.port = port
        self.host = host
        self.privk = privk or sec_params.group.G.order().random()
        self.pubk = pubk or (self.privk * sec_params.group.G.generator())
        self.crypto_client = ClientCore((sec_params, self.config_params),
                                        self.name, self.port, self.host,
                                        self.privk, self.pubk)
        self.provider = Provider(name=provider_id)

    def startProtocol(self):
        log.msg("[%s] > Started" % self.name)
        self.get_network_info()
        self.get_provider_data()
        self.subscribe_to_provider()
        self.turn_on_packet_processing()
        #self.make_loop_stream()
        #self.make_drop_stream()
        self.make_real_stream()
        if self.name != 'Client1':
            self.send_video('../../example3.mp4', self.befriended_clients[0])

    def get_network_info(self):
        self.dbManager = DatabaseManager(self.config_params.DATABASE_NAME)
        self.register_mixes(self.dbManager.select_all_mixnodes())
        self.register_providers(self.dbManager.select_all_providers())
        self.register_friends(self.dbManager.select_all_clients())
        self.provider = self.dbManager.select_provider_by_name(
            self.provider.name)
        log.msg("[%s] > Registered network information" % self.name)

    def get_provider_data(self):
        self.provider = self.dbManager.select_provider_by_name(
            self.provider.name)
        d = twisted.names.client.getHostByName(self.provider.host)
        d.addCallback(self.resolve_provider_address)

    def resolve_provider_address(self, result):
        self.provider = self.provider._replace(host=result)

    def subscribe_to_provider(self):
        lc = task.LoopingCall(self.send,
                              ['SUBSCRIBE', self.name, self.host, self.port])
        lc.start(self.config_params.TIME_PULL, now=True)

    def register_mixes(self, mixes):
        self.pubs_mixes = group_layered_topology(mixes)

    def register_providers(self, providers):
        self.pubs_providers = providers

    def register_friends(self, clients):
        self.befriended_clients = clients

    def turn_on_packet_processing(self):
        self.retrieve_messages()
        self.reactor.callLater(20.0, self.get_and_addCallback,
                               self.handle_packet)
        log.msg("[%s] > Turned on retrieving and processing of messages" %
                self.name)

    def retrieve_messages(self):
        lc = task.LoopingCall(self.send, ['PULL', self.name])
        lc.start(self.config_params.TIME_PULL, now=True)

    def get_and_addCallback(self, function):
        self.process_queue.get().addCallback(function)

    def datagramReceived(self, data, (host, port)):
        self.process_queue.put(data)
Exemplo n.º 8
0
from database_connect import DatabaseManager
import sys
import core
import petlib.pack
import os.path
import sqlite3

if not os.path.isfile('../example/example.db'):
    dbManager = DatabaseManager('../example/example.db')
    dbManager.create_mixnodes_table('Mixnodes')
    dbManager.create_providers_table('Providers')
    dbManager.create_users_table('Users')

dbManager = DatabaseManager('../example/example.db')
#python setup_exampledb.py 9999 '127.0.0.1' 'Mix1' 0 9998 '127.0.0.1' 'Mix2' 1 9997 '127.0.0.1' 'Mix3' 2
def startMixes():
    for i in range(3):
        port = int(sys.argv[1 + (i*4)])
        host = sys.argv[2 + (i*4)]
        name = sys.argv[3 + (i*4)]
        group = int(sys.argv[4 + (i*4)])
        setup = core.setup()
        G, o, g, o_bytes = setup
        secret = o.random()
        file("../example/secretMixnode%d.prv"%(i+1), "wb").write(petlib.pack.encode(secret))
        pub = secret * g
        file("../example/publicMixnode%d.bin"%(i+1), "wb").write(petlib.pack.encode(["mixnode", name, port, host, group, pub]))
        dbManager.insert_row_into_table('Mixnodes',
                [None, name, port, host,
                sqlite3.Binary(petlib.pack.encode(pub)), group])