Skip to content

Commit

Permalink
chore(xray-config): update transports and parse properly (#14)
Browse files Browse the repository at this point in the history
  • Loading branch information
khodedawsh authored Dec 6, 2024
1 parent 589217c commit 954aee8
Showing 1 changed file with 25 additions and 4 deletions.
29 changes: 25 additions & 4 deletions marznode/backends/xray/_config.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import json
from collections import defaultdict

import commentjson

Expand All @@ -7,6 +8,26 @@
from ...models import Inbound
from ...storage import BaseStorage

transport_map = defaultdict(
lambda: "tcp",
{
"tcp": "tcp",
"raw": "tcp",
"splithttp": "splithttp",
"xhttp": "splithttp",
"grpc": "grpc",
"kcp": "kcp",
"mkcp": "kcp",
"h2": "http",
"h3": "http",
"http": "http",
"ws": "ws",
"websocket": "ws",
"httpupgrade": "httpupgrade",
"quic": "quic",
},
)


class XrayConfig(dict):
def __init__(
Expand Down Expand Up @@ -104,7 +125,7 @@ def _resolve_inbounds(self):
security = stream.get("security")
tls_settings = stream.get(f"{security}Settings")

settings["network"] = net
settings["network"] = transport_map[net]

if security == "tls":
settings["tls"] = "tls"
Expand All @@ -122,7 +143,7 @@ def _resolve_inbounds(self):

settings["sid"] = tls_settings.get("shortIds", [""])[0]

if net == "tcp":
if net in ["tcp", "raw"]:
header = net_settings.get("header", {})
request = header.get("request", {})
path = request.get("path")
Expand All @@ -136,14 +157,14 @@ def _resolve_inbounds(self):
if host and isinstance(host, list):
settings["host"] = host

elif net in ["ws", "httpupgrade", "splithttp"]:
elif net in ["ws", "websocket", "httpupgrade", "splithttp", "xhttp"]:
settings["path"] = net_settings.get("path")
settings["host"] = net_settings.get("host")

elif net == "grpc":
settings["path"] = net_settings.get("serviceName")

elif net == "kcp":
elif net in ["kcp", "mkcp"]:
settings["path"] = net_settings.get("seed")
settings["header_type"] = net_settings.get("header", {}).get("type")

Expand Down

0 comments on commit 954aee8

Please sign in to comment.