def restore(): global proxies global next_id assert len(proxies) == 0 assert next_id == 1 try: f = open(status_file_path(), 'r') items = json.load(f) for item in items: if item['kind'] == 'server': p = ClientProxy(item['id'], str(item['channel']), (str(item['target'][0]), item['target'][1])) proxies.append(p) p.start() next_id = max(next_id, p.id + 1) elif item['kind'] == 'client': p = ServerProxy(item['id'], str(item['channel']), item['port']) proxies.append(p) p.start() next_id = max(next_id, p.id + 1) else: assert False except IOError: pass
def server(channel, target): global next_id assert isinstance(channel, str) assert isinstance(target, tuple) assert len(target) == 2 addr, port = target p = ClientProxy(next_id, channel, (addr, port)) next_id += 1 proxies.append(p) p.start() return ''