Esempio n. 1
0
def send_cmd(msg):

    if type(msg) is str:
        msg = msg.encode()

    final_cmd = format_cmd(msg)
    logger.debug('sending: {}'.format(log.nomore(final_cmd)))
    server_transport.write(final_cmd)
Esempio n. 2
0
def send_payload(ip, port, data):

    sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
    sock.connect((ip, port))

    final = format_cmd(b'CSTR ' + data)
    logger.debug('sending: {}'.format(log.nomore(final)))
    sock.send(final)
Esempio n. 3
0
def send_cmd(msg):

    if type(msg) is str:
        msg = msg.encode()

    final_cmd = format_cmd(msg)
    logger.debug('sending: {}'.format(log.nomore(final_cmd)))
    server_transport.write(final_cmd)
Esempio n. 4
0
def send_payload(ip, port, data):

    sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
    sock.connect((ip, port))

    final = format_cmd(b'CSTR ' + data)
    logger.debug('sending: {}'.format(log.nomore(final)))
    sock.send(final)
Esempio n. 5
0
    def connection_made(self, transp):

        NetworkClient.connection_made(self, transp)

        global server_transport

        logger.info("connected to master server")
        server_transport = transp

        try:
            protocol.login(self)
        except Exception as e:
            logger.error(e)
            logger.error('{} was raised'.format(log.nomore(e)))
            for l in traceback.format_tb(e.__traceback__):
                logger.debug(l)
            raise e
Esempio n. 6
0
def login(client):

    json_tree = tree.usertree
    my_chks = list(chunk.my_chunks.keys())
    my_store = []  # TODO: later read the content of .store

    hashes = 'None' if len(my_chks) == 0 else ':'.join(my_chks + my_store)

    try:
        network.send_cmd('JOIN {} {} {} {}'.format(client.username,
                                                   client.port, hashes,
                                                   json.dumps(json_tree)))
    except Exception as e:
        logger.error('2: {} was raised'.format(log.nomore(e)))
        for l in traceback.format_tb(e.__traceback__):
            logger.debug(l)
        raise e
Esempio n. 7
0
def parse(cmd, size, args):
    class Command:
        def __init__(self, fcall, isstr):
            self.function_call = fcall
            self.is_string = isstr

    cmds = {
        b'FADD': Command(FADD, True),
        b'FUPT': Command(FUPT, True),
        b'CSND': Command(CSND, True),
        # TODO: rethink the hole stuff
        b'CSTR': Command(CSTR, False),
        b'CDEL': Command(CDEL, True)
    }

    logger.debug('somebody sent {} with args {}'.format(cmd, log.nomore(args)))
    cmds[cmd].function_call(args)
Esempio n. 8
0
def login(client):

    json_tree = tree.usertree
    my_chks = list(chunk.my_chunks.keys())
    my_store = []  # TODO: later read the content of .store

    hashes = 'None' if len(my_chks) == 0 else ':'.join(my_chks + my_store)
  
    try:
      network.send_cmd('JOIN {} {} {} {}'
          .format(client.username, client.port,
            hashes, json.dumps(json_tree)))
    except Exception as e:
        logger.error('2: {} was raised'.format(log.nomore(e)))
        for l in traceback.format_tb(e.__traceback__):
            logger.debug(l)
        raise e
Esempio n. 9
0
def parse(cmd, size, args):

    class Command:

        def __init__(self, fcall, isstr):
            self.function_call = fcall
            self.is_string = isstr

    cmds = {b'FADD': Command(FADD, True),
            b'FUPT': Command(FUPT, True),
            b'CSND': Command(CSND, True),
            # TODO: rethink the hole stuff
            b'CSTR': Command(CSTR, False),
            b'CDEL': Command(CDEL, True)}

    logger.debug('somebody sent {} with args {}'.format(cmd, log.nomore(args)))
    cmds[cmd].function_call(args)
Esempio n. 10
0
    def connection_made(self, transp):
        
        NetworkClient.connection_made(self, transp)

        global server_transport

        logger.info("connected to master server")
        server_transport = transp

        try:
            protocol.login(self)
        except Exception as e:
            logger.error(e)
            logger.error('{} was raised'.format(log.nomore(e)))
            for l in traceback.format_tb(e.__traceback__):
                logger.debug(l)
            raise e