aboutsummaryrefslogtreecommitdiffstats
path: root/scripts/ws-irc-bridge.py
diff options
context:
space:
mode:
Diffstat (limited to 'scripts/ws-irc-bridge.py')
-rw-r--r--scripts/ws-irc-bridge.py54
1 files changed, 0 insertions, 54 deletions
diff --git a/scripts/ws-irc-bridge.py b/scripts/ws-irc-bridge.py
deleted file mode 100644
index cca3375..0000000
--- a/scripts/ws-irc-bridge.py
+++ /dev/null
@@ -1,54 +0,0 @@
-#!/usr/bin/env python3
-"""
-WebSocket-to-IRC bridge for gamja anonymous web client.
-Each WebSocket connection gets its own TCP connection to ngircd.
-Listens on 127.0.0.1:7778, forwards to 127.0.0.1:6667.
-"""
-import asyncio
-import websockets
-
-WS_HOST = "127.0.0.1"
-WS_PORT = 7778
-IRC_HOST = "127.0.0.1"
-IRC_PORT = 6667
-
-
-async def bridge(ws):
- try:
- reader, writer = await asyncio.open_connection(IRC_HOST, IRC_PORT)
- except OSError:
- await ws.close()
- return
-
- async def ws_to_irc():
- try:
- async for msg in ws:
- data = msg if isinstance(msg, bytes) else msg.encode()
- writer.write(data)
- await writer.drain()
- except Exception:
- pass
- finally:
- writer.close()
-
- async def irc_to_ws():
- try:
- while True:
- data = await reader.read(4096)
- if not data:
- break
- await ws.send(data)
- except Exception:
- pass
- finally:
- await ws.close()
-
- await asyncio.gather(ws_to_irc(), irc_to_ws())
-
-
-async def main():
- async with websockets.serve(bridge, WS_HOST, WS_PORT):
- await asyncio.Future()
-
-
-asyncio.run(main())