FrogTheFrog / moondeck

A plugin that makes it easier to manage your gamestream sessions from the SteamDeck.
GNU General Public License v3.0
123 stars 5 forks source link

Moon deck cannot connect to domain name with IPv6 address #61

Open DieMoe233 opened 2 months ago

DieMoe233 commented 2 months ago

I can pair Moondeck with "example.com" as host, where IPv6 address is returned by DNS, but Moondeck does not initiate connection. I've confirmed this is not firewall config issue, since moondeck-buddy already has allow through rule in Windows Firewall. Also, this is not caused by moonlight, since moonlight running in SteamDeck Desktop Mode can connect to the said address just fine. Thus this is a moondeck problem. The moondeck works fine when using IPv4.

DieMoe233 commented 2 months ago

BTW, the moondeck version is 1.7.2

FrogTheFrog commented 2 months ago

I have never tested this with IPv6. Will look into it when I have time.

FrogTheFrog commented 2 months ago

Well, the bad news is that my ISP does not provide IPv6 by default and I don't know how to setup it locally.

Can you please try going to https://<IPv6>:59999/apiVersion to reach your host. I wanna determine where the problem is. (https://github.com/FrogTheFrog/moondeck/wiki/Troubleshooting#make-sure-that-buddy-server-is-up-and-running)

DieMoe233 commented 2 months ago

Well, the bad news is that my ISP does not provide IPv6 by default and I don't know how to setup it locally.

Can you please try going to https://<IPv6>:59999/apiVersion to reach your host. I wanna determine where the problem is. (https://github.com/FrogTheFrog/moondeck/wiki/Troubleshooting#make-sure-that-buddy-server-is-up-and-running)

ERR_EMPTY_RESPONSE

8749236 commented 2 months ago

Well, the bad news is that my ISP does not provide IPv6 by default and I don't know how to setup it locally.

Do you have cellular data on your phone? Cellular network usually have IPv6 available. You can do a WiFi hotspot and get IPv6 for testing.

DieMoe233 commented 2 months ago

Well, the bad news is that my ISP does not provide IPv6 by default and I don't know how to setup it locally. Can you please try going to https://<IPv6>:59999/apiVersion to reach your host. I wanna determine where the problem is. (https://github.com/FrogTheFrog/moondeck/wiki/Troubleshooting#make-sure-that-buddy-server-is-up-and-running)

ERR_EMPTY_RESPONSE

Correction: When connecting directly with IPv6, everything works fine. But when accessing with domain name, browser will warn about HSTS and cuts connection.

image

image

FrogTheFrog commented 2 months ago

Well, the bad news is that my ISP does not provide IPv6 by default and I don't know how to setup it locally.

Do you have cellular data on your phone? Cellular network usually have IPv6 available. You can do a WiFi hotspot and get IPv6 for testing.

I'll try that later.

In the meantime @DieMoe233, do you think you (or anyone who's reading this) would be able to run this python script? test.zip (aiohttp needs to be installed manually). Replace the address variable with explicit IP and domain name please.

Maybe MS Edge has some additional guards for domains and it's on python side instead.

DieMoe233 commented 2 months ago

Well, the bad news is that my ISP does not provide IPv6 by default and I don't know how to setup it locally.

Do you have cellular data on your phone? Cellular network usually have IPv6 available. You can do a WiFi hotspot and get IPv6 for testing.

I'll try that later.

In the meantime @DieMoe233, do you think you (or anyone who's reading this) would be able to run this python script? test.zip (aiohttp needs to be installed manually). Replace the address variable with explicit IP and domain name please.

Maybe MS Edge has some additional guards for domains and it's on python side instead.

Screenshot_2024-08-22-23-43-38-847_Termux.png

FrogTheFrog commented 2 months ago

Well, the bad news is that my ISP does not provide IPv6 by default and I don't know how to setup it locally.

Do you have cellular data on your phone? Cellular network usually have IPv6 available. You can do a WiFi hotspot and get IPv6 for testing.

I'll try that later. In the meantime @DieMoe233, do you think you (or anyone who's reading this) would be able to run this python script? test.zip (aiohttp needs to be installed manually). Replace the address variable with explicit IP and domain name please. Maybe MS Edge has some additional guards for domains and it's on python side instead.

Screenshot_2024-08-22-23-43-38-847_Termux.png

Is this the same for both my_domain.com and [explicit IPv6]?

DieMoe233 commented 2 months ago

@

Well, the bad news is that my ISP does not provide IPv6 by default and I don't know how to setup it locally.

Do you have cellular data on your phone? Cellular network usually have IPv6 available. You can do a WiFi hotspot and get IPv6 for testing.

I'll try that later. In the meantime @DieMoe233, do you think you (or anyone who's reading this) would be able to run this python script? test.zip (aiohttp needs to be installed manually). Replace the address variable with explicit IP and domain name please. Maybe MS Edge has some additional guards for domains and it's on python side instead.

Screenshot_2024-08-22-23-43-38-847_Termux.png

Is this the same for both my_domain.com and [explicit IPv6]?

Yes. image

FrogTheFrog commented 2 months ago

Please enable "runner" debug logs in MoonDeck (via a toggle button in some tab, maybe under "Runner settings" or something). Then try streaming the game via moondeck and once that fails, paste the /tmp/moondeck-runner.log (only this one).

DieMoe233 commented 2 months ago
2024-08-23 00:43:42,258 INFO Resetting runner result
2024-08-23 00:43:42,258 INFO Getting app id
2024-08-23 00:43:42,258 INFO Getting current host settings
2024-08-23 00:43:42,259 INFO Using auto resolution from MoonDeck: {'width': 1280, 'height': 800}
2024-08-23 00:43:42,259 INFO Parsed resolution settings: {'dimensions': {'size': {'width': 1280, 'height': 800}, 'bitrate': None, 'fps': None}, 'passToBuddy': True, 'passToMoonlight': True}
2024-08-23 00:43:42,259 INFO Trying to run the game using the app MoonDeckStream
2024-08-23 00:43:42,261 INFO Checking connection to Buddy and GameStream server
2024-08-23 00:43:42,261 INFO Sending WOL (deleted mac) to example.com
2024-08-23 00:43:42,268 ERROR Unhandled exception
Traceback (most recent call last):
  File "/home/deck/homebrew/plugins/moondeck/python/./runner.py", line 272, in run_game
    result = await establish_connection(client=client, mac=mac, hostInfoPort=hostInfoPort, timeouts=timeouts)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/deck/homebrew/plugins/moondeck/python/./runner.py", line 248, in establish_connection
    async with WolSplashScreen(client.address, mac, timeouts["wakeOnLan"]) as splash:
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/deck/homebrew/plugins/moondeck/python/lib/wolsplashscreen.py", line 87, in __init__
    wake_on_lan(address=address, mac=mac)
  File "/home/deck/homebrew/plugins/moondeck/python/lib/utils.py", line 123, in wake_on_lan
    send_magic_packet(mac, ip_address=address)
  File "/home/deck/homebrew/plugins/moondeck/python/externals/wakeonlan/__init__.py", line 74, in send_magic_packet
    sock.connect((ip_address, port))
socket.gaierror: [Errno -2] Name or service not known
2024-08-23 00:43:42,270 ERROR Unhandled exception!
FrogTheFrog commented 2 months ago

@DieMoe233 please test this out for me when domain only has IPv6 or IPv4 (test both options please, if you can):

Find this line in this file on the SteamDeck (should be in ~/homebrew/plugins/moondeck/python/ or somewhere where the python files are stored): https://github.com/FrogTheFrog/moondeck/blob/bd5de42176cf8f8250fb4ce6c7ad90d132ac3160/defaults/python/lib/utils.py#L119

Delete the def wake_on_lan(address: str, mac: str): function completely and replace it with:

def wake_on_lan(address: str, mac: str):
    import socket
    import ipaddress

    default_port = 9

    def _try_parse_info(ip_address: str):
        try:
            parsed_address = ipaddress.ip_address(ip_address)
            if isinstance(parsed_address, ipaddress.IPv4Address):
                return socket.AF_INET, ip_address
            if isinstance(parsed_address, ipaddress.IPv6Address):
                return socket.AF_INET6, ip_address
        except ValueError:
            pass

        return None

    # if valid IP was specified, we don't need to call `getaddrinfo` at all
    info = _try_parse_info(address)
    if info:
        infos = [info]
    else:
        infos = [(x[0], x[4][0]) for x in socket.getaddrinfo(address, default_port, family=socket.AF_UNSPEC)
                 if x[0] in [socket.AF_INET, socket.AF_INET6]]

    if not infos:
        raise Exception("WOL failed - {address} does not have any IPv4 or IPv6 interfaces!") 

    for family, address_info in infos:
        send_magic_packet(mac, ip_address=address_info, address_family=family, port=default_port)

You will need to restart the SteamDeck once the file contents are replaced.

DieMoe233 commented 2 months ago

@FrogTheFrog This change is very effective, I've successfully run it on moondeck and it works correctly.

FrogTheFrog commented 2 months ago

@DieMoe233 I've pushed 1.8.0 to the testing store (decided to increment the version for reasons unrelated to this issue). Could you try it out and see if it still works?

DieMoe233 commented 2 months ago

@DieMoe233 I've pushed 1.8.0 to the testing store (decided to increment the version for reasons unrelated to this issue). Could you try it out and see if it still works?

Test passed, 1.8.0 is working, functionality looks good.

hhu94 commented 1 week ago

I ran into the same issue with 1.8.0.

After deleting this line from my utils.py it works.

Was this line introduced on purpose? The proposed snippet in this comment did not have it.

FrogTheFrog commented 1 week ago

I ran into the same issue with 1.8.0.

After deleting this line from my utils.py it works.

Was this line introduced on purpose? The proposed snippet in this comment did not have it.

Unless this line is throwing for some reason it should not have any affect. Could you try adding a try...except block around it?

What I'm doing here is sending the WOL on a broadcast address as this is how it's usually done on LAN (for IPv4). I do not have IPv6, so I do not know if sending WOL to ff02::1 for IPv6 is really needed, just read about it on the internet.