Skip to content

Debloat any Android or Google TV over Wi-Fi and get an Apple TV-style home.

tools: relay.py names an address that is a URL or a path instead of relaying to it

xbsheng19959e514ed6
diff --git a/tools/relay.py b/tools/relay.py
index b91941c88..3138ca2cf 100644
--- a/tools/relay.py
+++ b/tools/relay.py
@@ -10,6 +10,7 @@ terminal, then point the tools at it:
Usage: relay.py [TV_HOST[:PORT]] [--tv-port 5555] [--port 15555]
The TV's port is --tv-port, else the one in the address, else TV_PORT, else 5555.
+A URL or a page opened at the address is refused by name: give the IP (or IP:port) alone.
It listens on 127.0.0.1 only, never on the network. Read tools/relay.md first.
"""
import argparse
@@ -70,6 +71,28 @@ def serve(srv, tv_host, tv_port):
threading.Thread(target=pipe, args=(a, b), daemon=True).start()
+def address_problem(word):
+ """Why this word cannot be the TV's address, as the sentence to print, or None.
+
+ The address is read out of a browser or copied off a page often enough that the two shapes it is
+ never in are worth naming. `http://<tv ip>` split into the host "http" and the port "//<tv ip>", so
+ the run answered "not a port number: '//<tv ip>'" - a sentence about a port fragment for a word that
+ is an address of another kind. `http://<tv ip>:5555` and `<tv ip>/6/system` became hosts literally
+ named for the URL and the page, and the relay started and printed where it forwards to, so the owner
+ was told it was up; only a client that connected was told "cannot reach ... (is the TV on, and network
+ debugging still on?)" - the TV, its standby and the network blamed for an argument this script cannot
+ use. Neither a scheme nor a path is ever part of an address, in brackets for IPv6 or not.
+ """
+ word = word.strip()
+ if "://" in word:
+ return ("that is a URL, not the TV's address: give the IP (or IP:port) alone, e.g. "
+ "tools/venv/bin/python -I tools/relay.py <tv ip>")
+ if "/" in word:
+ return ("that is a path, not the TV's address: give the IP (or IP:port) alone, without the / or "
+ "the page it opens, e.g. tools/venv/bin/python -I tools/relay.py <tv ip>")
+ return None
+
+
def checked_port(p, flag, port, lowest):
"""A port this script can bind or connect to, or the parser's refusal: --port may be 0, the TV's port may not."""
if port is not None and not lowest <= port <= 65535:
@@ -88,6 +111,12 @@ def main():
args = p.parse_args()
if not args.tv_host:
p.error("give the TV's IP address, e.g. tools/venv/bin/python -I tools/relay.py 192.168.1.50")
+ # Before the port is read out of it, so a URL's "//<tv ip>" is not answered as a port fragment and a
+ # page's "/6/system" does not become the host the relay prints as where it forwards to. 2, like the
+ # other refusals here: nothing was bound and nothing was asked of the TV.
+ problem = address_problem(args.tv_host)
+ if problem:
+ p.error(problem)
# Both options are ports, and neither was checked: --port went to bind() as typed, and bind() refuses a
# port above 65535 (or a negative one) with an OverflowError - not an OSError, so the "cannot listen"
# message below never saw it - while --tv-port skipped the 1..65535 check the address and TV_PORT get a