Skip to content

Commit b859fde

Browse files
committed
Fix shadowsocks inbound
1 parent be15d93 commit b859fde

File tree

2 files changed

+38
-21
lines changed

2 files changed

+38
-21
lines changed

core/inbound.go

Lines changed: 38 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -326,18 +326,52 @@ func buildShadowsocks(nodeInfo *panel.NodeInfo, inbound *coreConf.InboundDetourC
326326
Password: randomPasswd,
327327
}
328328
settings.Users = append(settings.Users, defaultSSuser)
329+
// Default: support both tcp and udp
329330
settings.NetworkList = &coreConf.NetworkList{"tcp", "udp"}
330331
settings.IVCheck = true
331-
t := coreConf.TransportProtocol("tcp")
332-
inbound.StreamSetting = &coreConf.StreamConfig{Network: &t}
332+
// Only set StreamSetting when NetworkSettings is configured
333333
if len(s.NetworkSettings) != 0 {
334334
shttp := &ShadowsocksHTTPNetworkSettings{}
335335
err := json.Unmarshal(s.NetworkSettings, shttp)
336336
if err != nil {
337337
return fmt.Errorf("unmarshal shadowsocks settings error: %s", err)
338338
}
339-
inbound.StreamSetting.RAWSettings.AcceptProxyProtocol = shttp.AcceptProxyProtocol
340-
//todo path and host
339+
// HTTP obfuscation requires TCP only (PROXY protocol can work with UDP)
340+
if shttp.Path != "" || shttp.Host != "" {
341+
// Restrict protocol-level network list to TCP only for HTTP obfuscation
342+
settings.NetworkList = &coreConf.NetworkList{"tcp"}
343+
}
344+
345+
// Set StreamSetting for TCP features (PROXY protocol and/or HTTP obfuscation)
346+
if shttp.AcceptProxyProtocol || shttp.Path != "" || shttp.Host != "" {
347+
t := coreConf.TransportProtocol("tcp")
348+
inbound.StreamSetting = &coreConf.StreamConfig{Network: &t}
349+
inbound.StreamSetting.TCPSettings = &coreConf.TCPConfig{}
350+
inbound.StreamSetting.TCPSettings.AcceptProxyProtocol = shttp.AcceptProxyProtocol
351+
// Set HTTP header settings if path or host is configured
352+
if shttp.Path != "" || shttp.Host != "" {
353+
httpHeader := map[string]interface{}{
354+
"type": "http",
355+
"request": map[string]interface{}{},
356+
}
357+
request := httpHeader["request"].(map[string]interface{})
358+
// Use "/" as default path if not specified
359+
path := shttp.Path
360+
if path == "" {
361+
path = "/"
362+
}
363+
request["path"] = []string{path}
364+
if shttp.Host != "" {
365+
request["headers"] = map[string]interface{}{
366+
"Host": []string{shttp.Host},
367+
}
368+
}
369+
headerJSON, err := json.Marshal(httpHeader)
370+
if err == nil {
371+
inbound.StreamSetting.TCPSettings.HeaderConfig = json.RawMessage(headerJSON)
372+
}
373+
}
374+
}
341375
}
342376

343377
sets, err := json.Marshal(settings)

core/outbound.go

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,11 @@
11
package core
22

33
import (
4-
"context"
54
"fmt"
65

76
"encoding/json"
87

98
"github.com/xtls/xray-core/core"
10-
"github.com/xtls/xray-core/features/outbound"
119
"github.com/xtls/xray-core/infra/conf"
1210
)
1311

@@ -46,18 +44,3 @@ func buildDnsOutbound() (*core.OutboundHandlerConfig, error) {
4644
outboundDetourConfig.Tag = "dns_out"
4745
return outboundDetourConfig.Build()
4846
}
49-
50-
func (v *V2Core) addOutbound(config *core.OutboundHandlerConfig) error {
51-
rawHandler, err := core.CreateObject(v.Server, config)
52-
if err != nil {
53-
return err
54-
}
55-
handler, ok := rawHandler.(outbound.Handler)
56-
if !ok {
57-
return fmt.Errorf("not an InboundHandler: %s", err)
58-
}
59-
if err := v.ohm.AddHandler(context.Background(), handler); err != nil {
60-
return err
61-
}
62-
return nil
63-
}

0 commit comments

Comments
 (0)