(key)
| 687 | |
| 688 | @gen.coroutine |
| 689 | def _connect(key): |
| 690 | conn = yield websocket.websocket_connect(url) |
| 691 | on_message = create_on_message(conn) |
| 692 | temp = _server_env(None) |
| 693 | # Start connecton |
| 694 | conn.write_message(struct.pack("<i", base.RPC_MAGIC), binary=True) |
| 695 | key = "server:" + key |
| 696 | conn.write_message(struct.pack("<i", len(key)), binary=True) |
| 697 | conn.write_message(key.encode("utf-8"), binary=True) |
| 698 | msg = yield conn.read_message() |
| 699 | assert len(msg) >= 4 |
| 700 | magic = struct.unpack("<i", msg[:4])[0] |
| 701 | if magic == base.RPC_CODE_DUPLICATE: |
| 702 | raise RuntimeError(f"key: {key} has already been used in proxy") |
| 703 | if magic == base.RPC_CODE_MISMATCH: |
| 704 | logging.info("RPCProxy do not have matching client key %s", key) |
| 705 | elif magic != base.RPC_CODE_SUCCESS: |
| 706 | raise RuntimeError(f"{url} is not RPC Proxy") |
| 707 | msg = msg[4:] |
| 708 | |
| 709 | logging.info("Connection established with remote") |
| 710 | |
| 711 | if msg: |
| 712 | on_message(bytearray(msg), 3) |
| 713 | |
| 714 | while True: |
| 715 | try: |
| 716 | msg = yield conn.read_message() |
| 717 | if msg is None: |
| 718 | break |
| 719 | on_message(bytearray(msg), 3) |
| 720 | except websocket.WebSocketClosedError as err: |
| 721 | break |
| 722 | logging.info("WebSocketProxyServer closed...") |
| 723 | temp.remove() |
| 724 | ioloop.IOLoop.current().stop() |
| 725 | |
| 726 | ioloop.IOLoop.current().spawn_callback(_connect, key) |
| 727 | ioloop.IOLoop.current().start() |
nothing calls this directly
no test coverage detected
searching dependent graphs…