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)
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)
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
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
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)
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
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)