mirror of
https://github.com/v2fly/v2ray-core.git
synced 2025-01-03 07:56:42 -05:00
feat: packet_encoding for v4 config
This commit is contained in:
parent
9eaff44bc6
commit
cefddb0aa4
@ -3,6 +3,7 @@ package v4
|
|||||||
import (
|
import (
|
||||||
"github.com/golang/protobuf/proto"
|
"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/protocol"
|
||||||
"github.com/v2fly/v2ray-core/v5/common/serial"
|
"github.com/v2fly/v2ray-core/v5/common/serial"
|
||||||
"github.com/v2fly/v2ray-core/v5/infra/conf/cfgcommon"
|
"github.com/v2fly/v2ray-core/v5/infra/conf/cfgcommon"
|
||||||
@ -17,6 +18,7 @@ type ShadowsocksServerConfig struct {
|
|||||||
Email string `json:"email"`
|
Email string `json:"email"`
|
||||||
NetworkList *cfgcommon.NetworkList `json:"network"`
|
NetworkList *cfgcommon.NetworkList `json:"network"`
|
||||||
IVCheck bool `json:"ivCheck"`
|
IVCheck bool `json:"ivCheck"`
|
||||||
|
PacketEncoding string `json:"packetEncoding"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (v *ShadowsocksServerConfig) Build() (proto.Message, error) {
|
func (v *ShadowsocksServerConfig) Build() (proto.Message, error) {
|
||||||
@ -42,6 +44,13 @@ func (v *ShadowsocksServerConfig) Build() (proto.Message, error) {
|
|||||||
Account: serial.ToTypedMessage(account),
|
Account: serial.ToTypedMessage(account),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
switch v.PacketEncoding {
|
||||||
|
case "Packet":
|
||||||
|
config.PacketEncoding = packetaddr.PacketAddrType_Packet
|
||||||
|
case "", "None":
|
||||||
|
config.PacketEncoding = packetaddr.PacketAddrType_None
|
||||||
|
}
|
||||||
|
|
||||||
return config, nil
|
return config, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -6,6 +6,7 @@ import (
|
|||||||
|
|
||||||
"github.com/golang/protobuf/proto"
|
"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/protocol"
|
||||||
"github.com/v2fly/v2ray-core/v5/common/serial"
|
"github.com/v2fly/v2ray-core/v5/common/serial"
|
||||||
"github.com/v2fly/v2ray-core/v5/infra/conf/cfgcommon"
|
"github.com/v2fly/v2ray-core/v5/infra/conf/cfgcommon"
|
||||||
@ -36,6 +37,7 @@ type SocksServerConfig struct {
|
|||||||
Host *cfgcommon.Address `json:"ip"`
|
Host *cfgcommon.Address `json:"ip"`
|
||||||
Timeout uint32 `json:"timeout"`
|
Timeout uint32 `json:"timeout"`
|
||||||
UserLevel uint32 `json:"userLevel"`
|
UserLevel uint32 `json:"userLevel"`
|
||||||
|
PacketEncoding string `json:"packetEncoding"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (v *SocksServerConfig) Build() (proto.Message, error) {
|
func (v *SocksServerConfig) Build() (proto.Message, error) {
|
||||||
@ -64,6 +66,14 @@ func (v *SocksServerConfig) Build() (proto.Message, error) {
|
|||||||
|
|
||||||
config.Timeout = v.Timeout
|
config.Timeout = v.Timeout
|
||||||
config.UserLevel = v.UserLevel
|
config.UserLevel = v.UserLevel
|
||||||
|
|
||||||
|
switch v.PacketEncoding {
|
||||||
|
case "Packet":
|
||||||
|
config.PacketEncoding = packetaddr.PacketAddrType_Packet
|
||||||
|
case "", "None":
|
||||||
|
config.PacketEncoding = packetaddr.PacketAddrType_None
|
||||||
|
}
|
||||||
|
|
||||||
return config, nil
|
return config, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -4,6 +4,7 @@ import (
|
|||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/v2fly/v2ray-core/v5/common/net"
|
"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/protocol"
|
||||||
"github.com/v2fly/v2ray-core/v5/common/serial"
|
"github.com/v2fly/v2ray-core/v5/common/serial"
|
||||||
"github.com/v2fly/v2ray-core/v5/infra/conf/cfgcommon"
|
"github.com/v2fly/v2ray-core/v5/infra/conf/cfgcommon"
|
||||||
@ -30,7 +31,8 @@ func TestSocksInboundConfig(t *testing.T) {
|
|||||||
"udp": false,
|
"udp": false,
|
||||||
"ip": "127.0.0.1",
|
"ip": "127.0.0.1",
|
||||||
"timeout": 5,
|
"timeout": 5,
|
||||||
"userLevel": 1
|
"userLevel": 1,
|
||||||
|
"packetEncoding": "Packet"
|
||||||
}`,
|
}`,
|
||||||
Parser: testassist.LoadJSON(creator),
|
Parser: testassist.LoadJSON(creator),
|
||||||
Output: &socks.ServerConfig{
|
Output: &socks.ServerConfig{
|
||||||
@ -46,6 +48,7 @@ func TestSocksInboundConfig(t *testing.T) {
|
|||||||
},
|
},
|
||||||
Timeout: 5,
|
Timeout: 5,
|
||||||
UserLevel: 1,
|
UserLevel: 1,
|
||||||
|
PacketEncoding: packetaddr.PacketAddrType_Packet,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
@ -11,6 +11,7 @@ import (
|
|||||||
"github.com/golang/protobuf/proto"
|
"github.com/golang/protobuf/proto"
|
||||||
|
|
||||||
"github.com/v2fly/v2ray-core/v5/common/net"
|
"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/protocol"
|
||||||
"github.com/v2fly/v2ray-core/v5/common/serial"
|
"github.com/v2fly/v2ray-core/v5/common/serial"
|
||||||
"github.com/v2fly/v2ray-core/v5/infra/conf/cfgcommon"
|
"github.com/v2fly/v2ray-core/v5/infra/conf/cfgcommon"
|
||||||
@ -94,6 +95,7 @@ type TrojanServerConfig struct {
|
|||||||
Clients []*TrojanUserConfig `json:"clients"`
|
Clients []*TrojanUserConfig `json:"clients"`
|
||||||
Fallback json.RawMessage `json:"fallback"`
|
Fallback json.RawMessage `json:"fallback"`
|
||||||
Fallbacks []*TrojanInboundFallback `json:"fallbacks"`
|
Fallbacks []*TrojanInboundFallback `json:"fallbacks"`
|
||||||
|
PacketEncoding string `json:"packetEncoding"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// Build implements Buildable
|
// Build implements Buildable
|
||||||
@ -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
|
return config, nil
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user