From ae5ad505d04fa347eb96a0d2bfb54ff541c3b709 Mon Sep 17 00:00:00 2001 From: MHSanaei Date: Mon, 20 Apr 2026 16:05:27 +0200 Subject: add hysteria inbound Co-Authored-By: Alireza Ahmadi --- sub/subJsonService.go | 45 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) (limited to 'sub/subJsonService.go') diff --git a/sub/subJsonService.go b/sub/subJsonService.go index 05552fe8..7ce93e22 100644 --- a/sub/subJsonService.go +++ b/sub/subJsonService.go @@ -194,6 +194,8 @@ func (s *SubJsonService) getConfig(inbound *model.Inbound, client model.Client, newOutbounds = append(newOutbounds, s.genVless(inbound, streamSettings, client)) case "trojan", "shadowsocks": newOutbounds = append(newOutbounds, s.genServer(inbound, streamSettings, client)) + case "hysteria": + newOutbounds = append(newOutbounds, s.genHy(inbound, newStream, client)) } newOutbounds = append(newOutbounds, s.defaultOutbounds...) @@ -389,6 +391,49 @@ func (s *SubJsonService) genServer(inbound *model.Inbound, streamSettings json_u return result } +func (s *SubJsonService) genHy(inbound *model.Inbound, newStream map[string]any, client model.Client) json_util.RawMessage { + outbound := Outbound{} + + outbound.Protocol = string(inbound.Protocol) + outbound.Tag = "proxy" + + if s.mux != "" { + outbound.Mux = json_util.RawMessage(s.mux) + } + + var settings, stream map[string]any + json.Unmarshal([]byte(inbound.Settings), &settings) + version, _ := settings["version"].(float64) + outbound.Settings = map[string]any{ + "version": int(version), + "address": inbound.Listen, + "port": inbound.Port, + } + + json.Unmarshal([]byte(inbound.StreamSettings), &stream) + hyStream := stream["hysteriaSettings"].(map[string]any) + outHyStream := map[string]any{ + "version": int(version), + "auth": client.Auth, + } + if udpIdleTimeout, ok := hyStream["udpIdleTimeout"].(float64); ok { + outHyStream["udpIdleTimeout"] = int(udpIdleTimeout) + } + newStream["hysteriaSettings"] = outHyStream + + if finalmask, ok := hyStream["finalmask"].(map[string]any); ok { + newStream["finalmask"] = finalmask + } + + newStream["network"] = "hysteria" + newStream["security"] = "tls" + + outbound.StreamSettings, _ = json.MarshalIndent(newStream, "", " ") + + result, _ := json.MarshalIndent(outbound, "", " ") + return result +} + type Outbound struct { Protocol string `json:"protocol"` Tag string `json:"tag"` -- cgit v1.2.3