Normal proxy mode when handler is ready.
(self, handler)
| 432 | handler.signal_close() |
| 433 | |
| 434 | def _handler_ready_proxy_mode(self, handler): |
| 435 | """Normal proxy mode when handler is ready.""" |
| 436 | if handler.rpc_key.startswith("server:"): |
| 437 | pool_src, pool_dst = self._client_pool, self._server_pool |
| 438 | timeout = self.timeout_server |
| 439 | else: |
| 440 | pool_src, pool_dst = self._server_pool, self._client_pool |
| 441 | timeout = self.timeout_client |
| 442 | |
| 443 | key = handler.match_key |
| 444 | if key in pool_src: |
| 445 | self._pair_up(pool_src.pop(key), handler) |
| 446 | return |
| 447 | if key not in pool_dst: |
| 448 | pool_dst[key] = handler |
| 449 | |
| 450 | def cleanup(): |
| 451 | """Cleanup client connection if timeout""" |
| 452 | if pool_dst.get(key, None) == handler: |
| 453 | logging.info( |
| 454 | "Timeout client connection %s, cannot find match key=%s", |
| 455 | handler.name(), |
| 456 | key, |
| 457 | ) |
| 458 | pool_dst.pop(key) |
| 459 | handler.send_data(struct.pack("<i", base.RPC_CODE_MISMATCH)) |
| 460 | handler.signal_close() |
| 461 | |
| 462 | self.loop.call_later(timeout, cleanup) |
| 463 | else: |
| 464 | logging.info("Duplicate connection with same key=%s", key) |
| 465 | handler.send_data(struct.pack("<i", base.RPC_CODE_DUPLICATE)) |
| 466 | handler.signal_close() |
| 467 | |
| 468 | def handler_ready(self, handler): |
| 469 | """Report handler to be ready.""" |
no test coverage detected