added app
All checks were successful
Build and Push Multi-Platform Docker Image / build-and-push (push) Successful in 1m10s

This commit is contained in:
Hirviturkki 2025-04-29 14:23:15 +02:00
parent 58d90f4229
commit 2b2067482d

View File

@ -5,6 +5,7 @@ Signalling relay + periodic label aggregation broadcaster with staletimeout.
import asyncio, json, logging, time
import websockets
import requests
logging.basicConfig(level=logging.INFO)
@ -24,6 +25,20 @@ warning = False
info = False
debug = False
def lookup_location(ip):
try:
response = requests.get(f"https://ipinfo.io/{ip}/json")
if response.status_code == 200:
data = response.json()
city = data.get("city")
region = data.get("region")
country = data.get("country")
return f"{city}, {region}, {country}"
else:
return "Unknown location"
except Exception as e:
return f"Lookup failed: {e}"
async def handler(ws: websockets.WebSocketServerProtocol):
peer_id = None
try:
@ -41,6 +56,10 @@ async def handler(ws: websockets.WebSocketServerProtocol):
if not peer_id:
await ws.close(code=4000, reason="Missing id")
return
ip, port = ws.remote_address
logging.info(f"New connection from {ip}:{port}")
location = lookup_location(ip)
logging.info(f"Approximate location: {location}")
CLIENTS[peer_id] = ws
CLIENT_LABELS[peer_id] = []
CLIENT_LABELS_TS[peer_id] = time.monotonic()