Skip to content

Commit

Permalink
tcp + http
Browse files Browse the repository at this point in the history
  • Loading branch information
frainzy1477 committed Aug 22, 2021
1 parent 117626f commit 6f827b5
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 6 deletions.
1 change: 1 addition & 0 deletions api/apimodel.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ type NodeInfo struct {
EnableVless bool
CypherMethod string
ServiceName string
HeaderType string
}

type UserInfo struct {
Expand Down
22 changes: 16 additions & 6 deletions api/sspanel/sspanel.go
Original file line number Diff line number Diff line change
Expand Up @@ -340,7 +340,7 @@ func (c *APIClient) ReportIllegal(detectResultList *[]api.DetectResult) error {
// ParseV2rayNodeResponse parse the response for the given nodeinfor format
func (c *APIClient) ParseV2rayNodeResponse(nodeInfoResponse *NodeInfoResponse) (*api.NodeInfo, error) {
var enableTLS bool
var path, host, TLStype, transportProtocol, serviceName string
var path, host, TLStype, transportProtocol, serviceName, HeaderType string
var speedlimit uint64 = 0
if nodeInfoResponse.RawServerString == "" {
return nil, fmt.Errorf("No server info in response")
Expand Down Expand Up @@ -372,7 +372,8 @@ func (c *APIClient) ParseV2rayNodeResponse(nodeInfoResponse *NodeInfoResponse) (
}
}
extraServerConf := strings.Split(serverConf[5], "|")

serviceName = ""
HeaderType = "none"
for _, item := range extraServerConf {
conf := strings.Split(item, "=")
key := conf[0]
Expand All @@ -388,6 +389,8 @@ func (c *APIClient) ParseV2rayNodeResponse(nodeInfoResponse *NodeInfoResponse) (
host = value
case "servicename":
serviceName = value
case "headertype":
HeaderType = value
}
}
if c.SpeedLimit > 0 {
Expand All @@ -410,6 +413,7 @@ func (c *APIClient) ParseV2rayNodeResponse(nodeInfoResponse *NodeInfoResponse) (
Host: host,
EnableVless: c.EnableVless,
ServiceName: serviceName,
HeaderType: HeaderType,
}

return nodeinfo, nil
Expand All @@ -419,7 +423,7 @@ func (c *APIClient) ParseV2rayNodeResponse(nodeInfoResponse *NodeInfoResponse) (
func (c *APIClient) ParseSSNodeResponse(nodeInfoResponse *NodeInfoResponse) (*api.NodeInfo, error) {
var port int = 0
var speedlimit uint64 = 0
var method string
var method, HeaderType string
path := "/mod_mu/users"
res, err := c.client.R().
SetQueryParam("node_id", strconv.Itoa(c.NodeID)).
Expand All @@ -445,7 +449,7 @@ func (c *APIClient) ParseSSNodeResponse(nodeInfoResponse *NodeInfoResponse) (*ap
break
}
}

HeaderType = "none"
if port == 0 || method == "" {
return nil, fmt.Errorf("Cant find the single port multi user")
}
Expand All @@ -463,6 +467,7 @@ func (c *APIClient) ParseSSNodeResponse(nodeInfoResponse *NodeInfoResponse) (*ap
SpeedLimit: speedlimit,
TransportProtocol: "tcp",
CypherMethod: method,
HeaderType: HeaderType,
}

return nodeinfo, nil
Expand All @@ -471,7 +476,7 @@ func (c *APIClient) ParseSSNodeResponse(nodeInfoResponse *NodeInfoResponse) (*ap
// ParseSSPluginNodeResponse parse the response for the given nodeinfor format
func (c *APIClient) ParseSSPluginNodeResponse(nodeInfoResponse *NodeInfoResponse) (*api.NodeInfo, error) {
var enableTLS bool
var path, host, TLStype, transportProtocol string
var path, host, TLStype, transportProtocol, HeaderType string
var speedlimit uint64 = 0

serverConf := strings.Split(nodeInfoResponse.RawServerString, ";")
Expand Down Expand Up @@ -499,6 +504,8 @@ func (c *APIClient) ParseSSPluginNodeResponse(nodeInfoResponse *NodeInfoResponse
transportProtocol = "tcp"
}
}
HeaderType = "none"

extraServerConf := strings.Split(serverConf[5], "|")
for _, item := range extraServerConf {
conf := strings.Split(item, "=")
Expand Down Expand Up @@ -532,6 +539,7 @@ func (c *APIClient) ParseSSPluginNodeResponse(nodeInfoResponse *NodeInfoResponse
TLSType: TLStype,
Path: path,
Host: host,
HeaderType: HeaderType,
}

return nodeinfo, nil
Expand All @@ -541,7 +549,7 @@ func (c *APIClient) ParseSSPluginNodeResponse(nodeInfoResponse *NodeInfoResponse
func (c *APIClient) ParseTrojanNodeResponse(nodeInfoResponse *NodeInfoResponse) (*api.NodeInfo, error) {
// 域名或IP;port=连接端口#偏移端口|host=xx
// gz.aaa.com;port=443#12345|host=hk.aaa.com
var p, TLSType, host, outsidePort, insidePort, transportProtocol, serviceName string
var p, TLSType, host, outsidePort, insidePort, transportProtocol, serviceName, HeaderType string
var speedlimit uint64 = 0
if c.EnableXTLS {
TLSType = "xtls"
Expand Down Expand Up @@ -576,6 +584,7 @@ func (c *APIClient) ParseTrojanNodeResponse(nodeInfoResponse *NodeInfoResponse)
serverConf := strings.Split(nodeInfoResponse.RawServerString, ";")
extraServerConf := strings.Split(serverConf[1], "|")
transportProtocol = "tcp"
HeaderType = "none"
serviceName = ""
for _, item := range extraServerConf {
conf := strings.Split(item, "=")
Expand Down Expand Up @@ -608,6 +617,7 @@ func (c *APIClient) ParseTrojanNodeResponse(nodeInfoResponse *NodeInfoResponse)
TLSType: TLSType,
Host: host,
ServiceName: serviceName,
HeaderType: HeaderType,
}

return nodeinfo, nil
Expand Down
8 changes: 8 additions & 0 deletions service/controller/inboundbuilder.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,8 +120,16 @@ func InboundBuilder(config *Config, nodeInfo *api.NodeInfo) (*core.InboundHandle
return nil, fmt.Errorf("convert TransportProtocol failed: %s", err)
}
if networkType == "tcp" {
headers := make(map[string]string)
headers["type"] = nodeInfo.HeaderType
var header json.RawMessage
header, err := json.Marshal(headers)
if err != nil {
return nil, fmt.Errorf("Marshal Header Type %s into config fialed: %s", header, err)
}
tcpSetting := &conf.TCPConfig{
AcceptProxyProtocol: config.EnableProxyProtocol,
HeaderConfig : header,
}
streamSetting.TCPSettings = tcpSetting
} else if networkType == "websocket" {
Expand Down

0 comments on commit 6f827b5

Please sign in to comment.