Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: packet_encoding for config v4 #3083

Merged
merged 1 commit into from
Aug 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 16 additions & 7 deletions infra/conf/v4/shadowsocks.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,22 @@ package v4
import (
"github.com/golang/protobuf/proto"

"github.com/v2fly/v2ray-core/v5/common/net/packetaddr"
"github.com/v2fly/v2ray-core/v5/common/protocol"
"github.com/v2fly/v2ray-core/v5/common/serial"
"github.com/v2fly/v2ray-core/v5/infra/conf/cfgcommon"
"github.com/v2fly/v2ray-core/v5/proxy/shadowsocks"
)

type ShadowsocksServerConfig struct {
Cipher string `json:"method"`
Password string `json:"password"`
UDP bool `json:"udp"`
Level byte `json:"level"`
Email string `json:"email"`
NetworkList *cfgcommon.NetworkList `json:"network"`
IVCheck bool `json:"ivCheck"`
Cipher string `json:"method"`
Password string `json:"password"`
UDP bool `json:"udp"`
Level byte `json:"level"`
Email string `json:"email"`
NetworkList *cfgcommon.NetworkList `json:"network"`
IVCheck bool `json:"ivCheck"`
PacketEncoding string `json:"packetEncoding"`
}

func (v *ShadowsocksServerConfig) Build() (proto.Message, error) {
Expand All @@ -42,6 +44,13 @@ func (v *ShadowsocksServerConfig) Build() (proto.Message, error) {
Account: serial.ToTypedMessage(account),
}

switch v.PacketEncoding {
case "Packet":
config.PacketEncoding = packetaddr.PacketAddrType_Packet
case "", "None":
config.PacketEncoding = packetaddr.PacketAddrType_None
}

return config, nil
}

Expand Down
22 changes: 16 additions & 6 deletions infra/conf/v4/socks.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (

"github.com/golang/protobuf/proto"

"github.com/v2fly/v2ray-core/v5/common/net/packetaddr"
"github.com/v2fly/v2ray-core/v5/common/protocol"
"github.com/v2fly/v2ray-core/v5/common/serial"
"github.com/v2fly/v2ray-core/v5/infra/conf/cfgcommon"
Expand All @@ -30,12 +31,13 @@ const (
)

type SocksServerConfig struct {
AuthMethod string `json:"auth"`
Accounts []*SocksAccount `json:"accounts"`
UDP bool `json:"udp"`
Host *cfgcommon.Address `json:"ip"`
Timeout uint32 `json:"timeout"`
UserLevel uint32 `json:"userLevel"`
AuthMethod string `json:"auth"`
Accounts []*SocksAccount `json:"accounts"`
UDP bool `json:"udp"`
Host *cfgcommon.Address `json:"ip"`
Timeout uint32 `json:"timeout"`
UserLevel uint32 `json:"userLevel"`
PacketEncoding string `json:"packetEncoding"`
}

func (v *SocksServerConfig) Build() (proto.Message, error) {
Expand Down Expand Up @@ -64,6 +66,14 @@ func (v *SocksServerConfig) Build() (proto.Message, error) {

config.Timeout = v.Timeout
config.UserLevel = v.UserLevel

switch v.PacketEncoding {
case "Packet":
config.PacketEncoding = packetaddr.PacketAddrType_Packet
case "", "None":
config.PacketEncoding = packetaddr.PacketAddrType_None
}

return config, nil
}

Expand Down
9 changes: 6 additions & 3 deletions infra/conf/v4/socks_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"testing"

"github.com/v2fly/v2ray-core/v5/common/net"
"github.com/v2fly/v2ray-core/v5/common/net/packetaddr"
"github.com/v2fly/v2ray-core/v5/common/protocol"
"github.com/v2fly/v2ray-core/v5/common/serial"
"github.com/v2fly/v2ray-core/v5/infra/conf/cfgcommon"
Expand All @@ -30,7 +31,8 @@ func TestSocksInboundConfig(t *testing.T) {
"udp": false,
"ip": "127.0.0.1",
"timeout": 5,
"userLevel": 1
"userLevel": 1,
"packetEncoding": "Packet"
}`,
Parser: testassist.LoadJSON(creator),
Output: &socks.ServerConfig{
Expand All @@ -44,8 +46,9 @@ func TestSocksInboundConfig(t *testing.T) {
Ip: []byte{127, 0, 0, 1},
},
},
Timeout: 5,
UserLevel: 1,
Timeout: 5,
UserLevel: 1,
PacketEncoding: packetaddr.PacketAddrType_Packet,
},
},
})
Expand Down
15 changes: 12 additions & 3 deletions infra/conf/v4/trojan.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"github.com/golang/protobuf/proto"

"github.com/v2fly/v2ray-core/v5/common/net"
"github.com/v2fly/v2ray-core/v5/common/net/packetaddr"
"github.com/v2fly/v2ray-core/v5/common/protocol"
"github.com/v2fly/v2ray-core/v5/common/serial"
"github.com/v2fly/v2ray-core/v5/infra/conf/cfgcommon"
Expand Down Expand Up @@ -91,9 +92,10 @@ type TrojanUserConfig struct {

// TrojanServerConfig is Inbound configuration
type TrojanServerConfig struct {
Clients []*TrojanUserConfig `json:"clients"`
Fallback json.RawMessage `json:"fallback"`
Fallbacks []*TrojanInboundFallback `json:"fallbacks"`
Clients []*TrojanUserConfig `json:"clients"`
Fallback json.RawMessage `json:"fallback"`
Fallbacks []*TrojanInboundFallback `json:"fallbacks"`
PacketEncoding string `json:"packetEncoding"`
}

// Build implements Buildable
Expand Down Expand Up @@ -167,5 +169,12 @@ func (c *TrojanServerConfig) Build() (proto.Message, error) {
}
}

switch c.PacketEncoding {
case "Packet":
config.PacketEncoding = packetaddr.PacketAddrType_Packet
case "", "None":
config.PacketEncoding = packetaddr.PacketAddrType_None
}

return config, nil
}
Loading