mirror of
https://github.com/v2fly/v2ray-core.git
synced 2025-01-02 15:36:41 -05:00
Add packetEncoding for Hysteria 2
This commit is contained in:
parent
8b36010fc2
commit
256a8166cf
@ -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"
|
||||||
@ -60,10 +61,18 @@ func (c *Hysteria2ClientConfig) Build() (proto.Message, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Hysteria2ServerConfig is Inbound configuration
|
// Hysteria2ServerConfig is Inbound configuration
|
||||||
type Hysteria2ServerConfig struct{}
|
type Hysteria2ServerConfig struct {
|
||||||
|
PacketEncoding string `json:"packetEncoding"`
|
||||||
|
}
|
||||||
|
|
||||||
// Build implements Buildable
|
// Build implements Buildable
|
||||||
func (c *Hysteria2ServerConfig) Build() (proto.Message, error) {
|
func (c *Hysteria2ServerConfig) Build() (proto.Message, error) {
|
||||||
config := new(hysteria2.ServerConfig)
|
config := new(hysteria2.ServerConfig)
|
||||||
|
switch c.PacketEncoding {
|
||||||
|
case "Packet":
|
||||||
|
config.PacketEncoding = packetaddr.PacketAddrType_Packet
|
||||||
|
case "", "None":
|
||||||
|
config.PacketEncoding = packetaddr.PacketAddrType_None
|
||||||
|
}
|
||||||
return config, nil
|
return config, nil
|
||||||
}
|
}
|
||||||
|
@ -145,9 +145,10 @@ type Hy2ConfigCongestion struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type Hy2Config struct {
|
type Hy2Config struct {
|
||||||
Password string `json:"password"`
|
Password string `json:"password"`
|
||||||
Congestion Hy2ConfigCongestion `json:"congestion"`
|
Congestion Hy2ConfigCongestion `json:"congestion"`
|
||||||
UseUdpExtension bool `json:"use_udp_extension"`
|
UseUdpExtension bool `json:"use_udp_extension"`
|
||||||
|
IgnoreClientBandwidth bool `json:"ignore_client_bandwidth"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// Build implements Buildable.
|
// Build implements Buildable.
|
||||||
@ -158,7 +159,9 @@ func (c *Hy2Config) Build() (proto.Message, error) {
|
|||||||
DownMbps: c.Congestion.DownMbps,
|
DownMbps: c.Congestion.DownMbps,
|
||||||
UpMbps: c.Congestion.UpMbps,
|
UpMbps: c.Congestion.UpMbps,
|
||||||
},
|
},
|
||||||
UseUdpExtension: c.UseUdpExtension}, nil
|
UseUdpExtension: c.UseUdpExtension,
|
||||||
|
IgnoreClientBandwidth: c.IgnoreClientBandwidth,
|
||||||
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
type WebSocketConfig struct {
|
type WebSocketConfig struct {
|
||||||
|
@ -9,6 +9,7 @@ import (
|
|||||||
"github.com/v2fly/v2ray-core/v5/common"
|
"github.com/v2fly/v2ray-core/v5/common"
|
||||||
"github.com/v2fly/v2ray-core/v5/common/buf"
|
"github.com/v2fly/v2ray-core/v5/common/buf"
|
||||||
"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/retry"
|
"github.com/v2fly/v2ray-core/v5/common/retry"
|
||||||
"github.com/v2fly/v2ray-core/v5/common/session"
|
"github.com/v2fly/v2ray-core/v5/common/session"
|
||||||
@ -19,6 +20,7 @@ import (
|
|||||||
"github.com/v2fly/v2ray-core/v5/transport"
|
"github.com/v2fly/v2ray-core/v5/transport"
|
||||||
"github.com/v2fly/v2ray-core/v5/transport/internet"
|
"github.com/v2fly/v2ray-core/v5/transport/internet"
|
||||||
hyTransport "github.com/v2fly/v2ray-core/v5/transport/internet/hysteria2"
|
hyTransport "github.com/v2fly/v2ray-core/v5/transport/internet/hysteria2"
|
||||||
|
"github.com/v2fly/v2ray-core/v5/transport/internet/udp"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Client is an inbound handler
|
// Client is an inbound handler
|
||||||
@ -98,6 +100,51 @@ func (c *Client) Process(ctx context.Context, link *transport.Link, dialer inter
|
|||||||
ctx, cancel := context.WithCancel(ctx)
|
ctx, cancel := context.WithCancel(ctx)
|
||||||
timer := signal.CancelAfterInactivity(ctx, cancel, sessionPolicy.Timeouts.ConnectionIdle)
|
timer := signal.CancelAfterInactivity(ctx, cancel, sessionPolicy.Timeouts.ConnectionIdle)
|
||||||
|
|
||||||
|
if packetConn, err := packetaddr.ToPacketAddrConn(link, destination); err == nil {
|
||||||
|
postRequest := func() error {
|
||||||
|
defer timer.SetTimeout(sessionPolicy.Timeouts.DownlinkOnly)
|
||||||
|
|
||||||
|
var buffer [2048]byte
|
||||||
|
n, addr, err := packetConn.ReadFrom(buffer[:])
|
||||||
|
if err != nil {
|
||||||
|
return newError("failed to read a packet").Base(err)
|
||||||
|
}
|
||||||
|
dest := net.DestinationFromAddr(addr)
|
||||||
|
|
||||||
|
bufferWriter := buf.NewBufferedWriter(buf.NewWriter(conn))
|
||||||
|
connWriter := &ConnWriter{Writer: bufferWriter, Target: dest}
|
||||||
|
packetWriter := &PacketWriter{Writer: connWriter, Target: dest, HyConn: hyConn}
|
||||||
|
|
||||||
|
// write some request payload to buffer
|
||||||
|
if _, err := packetWriter.WriteTo(buffer[:n], addr); err != nil {
|
||||||
|
return newError("failed to write a request payload").Base(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Flush; bufferWriter.WriteMultiBuffer now is bufferWriter.writer.WriteMultiBuffer
|
||||||
|
if err = bufferWriter.SetBuffered(false); err != nil {
|
||||||
|
return newError("failed to flush payload").Base(err).AtWarning()
|
||||||
|
}
|
||||||
|
|
||||||
|
return udp.CopyPacketConn(packetWriter, packetConn, udp.UpdateActivity(timer))
|
||||||
|
}
|
||||||
|
|
||||||
|
getResponse := func() error {
|
||||||
|
defer timer.SetTimeout(sessionPolicy.Timeouts.UplinkOnly)
|
||||||
|
|
||||||
|
packetReader := &PacketReader{Reader: conn, HyConn: hyConn}
|
||||||
|
packetConnectionReader := &PacketConnectionReader{reader: packetReader}
|
||||||
|
|
||||||
|
return udp.CopyPacketConn(packetConn, packetConnectionReader, udp.UpdateActivity(timer))
|
||||||
|
}
|
||||||
|
|
||||||
|
responseDoneAndCloseWriter := task.OnSuccess(getResponse, task.Close(link.Writer))
|
||||||
|
if err := task.Run(ctx, postRequest, responseDoneAndCloseWriter); err != nil {
|
||||||
|
return newError("connection ends").Base(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
postRequest := func() error {
|
postRequest := func() error {
|
||||||
defer timer.SetTimeout(sessionPolicy.Timeouts.DownlinkOnly)
|
defer timer.SetTimeout(sessionPolicy.Timeouts.DownlinkOnly)
|
||||||
|
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
package hysteria2
|
package hysteria2
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
packetaddr "github.com/v2fly/v2ray-core/v5/common/net/packetaddr"
|
||||||
protocol "github.com/v2fly/v2ray-core/v5/common/protocol"
|
protocol "github.com/v2fly/v2ray-core/v5/common/protocol"
|
||||||
_ "github.com/v2fly/v2ray-core/v5/common/protoext"
|
_ "github.com/v2fly/v2ray-core/v5/common/protoext"
|
||||||
protoreflect "google.golang.org/protobuf/reflect/protoreflect"
|
protoreflect "google.golang.org/protobuf/reflect/protoreflect"
|
||||||
@ -105,6 +106,8 @@ type ServerConfig struct {
|
|||||||
state protoimpl.MessageState
|
state protoimpl.MessageState
|
||||||
sizeCache protoimpl.SizeCache
|
sizeCache protoimpl.SizeCache
|
||||||
unknownFields protoimpl.UnknownFields
|
unknownFields protoimpl.UnknownFields
|
||||||
|
|
||||||
|
PacketEncoding packetaddr.PacketAddrType `protobuf:"varint,1,opt,name=packet_encoding,json=packetEncoding,proto3,enum=v2ray.core.net.packetaddr.PacketAddrType" json:"packet_encoding,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (x *ServerConfig) Reset() {
|
func (x *ServerConfig) Reset() {
|
||||||
@ -139,37 +142,50 @@ func (*ServerConfig) Descriptor() ([]byte, []int) {
|
|||||||
return file_proxy_hysteria2_config_proto_rawDescGZIP(), []int{2}
|
return file_proxy_hysteria2_config_proto_rawDescGZIP(), []int{2}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (x *ServerConfig) GetPacketEncoding() packetaddr.PacketAddrType {
|
||||||
|
if x != nil {
|
||||||
|
return x.PacketEncoding
|
||||||
|
}
|
||||||
|
return packetaddr.PacketAddrType(0)
|
||||||
|
}
|
||||||
|
|
||||||
var File_proxy_hysteria2_config_proto protoreflect.FileDescriptor
|
var File_proxy_hysteria2_config_proto protoreflect.FileDescriptor
|
||||||
|
|
||||||
var file_proxy_hysteria2_config_proto_rawDesc = []byte{
|
var file_proxy_hysteria2_config_proto_rawDesc = []byte{
|
||||||
0x0a, 0x1c, 0x70, 0x72, 0x6f, 0x78, 0x79, 0x2f, 0x68, 0x79, 0x73, 0x74, 0x65, 0x72, 0x69, 0x61,
|
0x0a, 0x1c, 0x70, 0x72, 0x6f, 0x78, 0x79, 0x2f, 0x68, 0x79, 0x73, 0x74, 0x65, 0x72, 0x69, 0x61,
|
||||||
0x32, 0x2f, 0x63, 0x6f, 0x6e, 0x66, 0x69, 0x67, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x12, 0x1a,
|
0x32, 0x2f, 0x63, 0x6f, 0x6e, 0x66, 0x69, 0x67, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x12, 0x1a,
|
||||||
0x76, 0x32, 0x72, 0x61, 0x79, 0x2e, 0x63, 0x6f, 0x72, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x78, 0x79,
|
0x76, 0x32, 0x72, 0x61, 0x79, 0x2e, 0x63, 0x6f, 0x72, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x78, 0x79,
|
||||||
0x2e, 0x68, 0x79, 0x73, 0x74, 0x65, 0x72, 0x69, 0x61, 0x32, 0x1a, 0x1a, 0x63, 0x6f, 0x6d, 0x6d,
|
0x2e, 0x68, 0x79, 0x73, 0x74, 0x65, 0x72, 0x69, 0x61, 0x32, 0x1a, 0x22, 0x63, 0x6f, 0x6d, 0x6d,
|
||||||
0x6f, 0x6e, 0x2f, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x63, 0x6f, 0x6c, 0x2f, 0x75, 0x73, 0x65, 0x72,
|
0x6f, 0x6e, 0x2f, 0x6e, 0x65, 0x74, 0x2f, 0x70, 0x61, 0x63, 0x6b, 0x65, 0x74, 0x61, 0x64, 0x64,
|
||||||
0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x1a, 0x21, 0x63, 0x6f, 0x6d, 0x6d, 0x6f, 0x6e, 0x2f, 0x70,
|
0x72, 0x2f, 0x63, 0x6f, 0x6e, 0x66, 0x69, 0x67, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x1a, 0x21,
|
||||||
0x72, 0x6f, 0x74, 0x6f, 0x63, 0x6f, 0x6c, 0x2f, 0x73, 0x65, 0x72, 0x76, 0x65, 0x72, 0x5f, 0x73,
|
0x63, 0x6f, 0x6d, 0x6d, 0x6f, 0x6e, 0x2f, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x63, 0x6f, 0x6c, 0x2f,
|
||||||
0x70, 0x65, 0x63, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x1a, 0x20, 0x63, 0x6f, 0x6d, 0x6d, 0x6f,
|
0x73, 0x65, 0x72, 0x76, 0x65, 0x72, 0x5f, 0x73, 0x70, 0x65, 0x63, 0x2e, 0x70, 0x72, 0x6f, 0x74,
|
||||||
0x6e, 0x2f, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x65, 0x78, 0x74, 0x2f, 0x65, 0x78, 0x74, 0x65, 0x6e,
|
0x6f, 0x1a, 0x20, 0x63, 0x6f, 0x6d, 0x6d, 0x6f, 0x6e, 0x2f, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x65,
|
||||||
0x73, 0x69, 0x6f, 0x6e, 0x73, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x22, 0x09, 0x0a, 0x07, 0x41,
|
0x78, 0x74, 0x2f, 0x65, 0x78, 0x74, 0x65, 0x6e, 0x73, 0x69, 0x6f, 0x6e, 0x73, 0x2e, 0x70, 0x72,
|
||||||
0x63, 0x63, 0x6f, 0x75, 0x6e, 0x74, 0x22, 0x6d, 0x0a, 0x0c, 0x43, 0x6c, 0x69, 0x65, 0x6e, 0x74,
|
0x6f, 0x74, 0x6f, 0x22, 0x09, 0x0a, 0x07, 0x41, 0x63, 0x63, 0x6f, 0x75, 0x6e, 0x74, 0x22, 0x6d,
|
||||||
0x43, 0x6f, 0x6e, 0x66, 0x69, 0x67, 0x12, 0x42, 0x0a, 0x06, 0x73, 0x65, 0x72, 0x76, 0x65, 0x72,
|
0x0a, 0x0c, 0x43, 0x6c, 0x69, 0x65, 0x6e, 0x74, 0x43, 0x6f, 0x6e, 0x66, 0x69, 0x67, 0x12, 0x42,
|
||||||
0x18, 0x01, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x2a, 0x2e, 0x76, 0x32, 0x72, 0x61, 0x79, 0x2e, 0x63,
|
0x0a, 0x06, 0x73, 0x65, 0x72, 0x76, 0x65, 0x72, 0x18, 0x01, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x2a,
|
||||||
0x6f, 0x72, 0x65, 0x2e, 0x63, 0x6f, 0x6d, 0x6d, 0x6f, 0x6e, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f,
|
0x2e, 0x76, 0x32, 0x72, 0x61, 0x79, 0x2e, 0x63, 0x6f, 0x72, 0x65, 0x2e, 0x63, 0x6f, 0x6d, 0x6d,
|
||||||
0x63, 0x6f, 0x6c, 0x2e, 0x53, 0x65, 0x72, 0x76, 0x65, 0x72, 0x45, 0x6e, 0x64, 0x70, 0x6f, 0x69,
|
0x6f, 0x6e, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x63, 0x6f, 0x6c, 0x2e, 0x53, 0x65, 0x72, 0x76,
|
||||||
0x6e, 0x74, 0x52, 0x06, 0x73, 0x65, 0x72, 0x76, 0x65, 0x72, 0x3a, 0x19, 0x82, 0xb5, 0x18, 0x15,
|
0x65, 0x72, 0x45, 0x6e, 0x64, 0x70, 0x6f, 0x69, 0x6e, 0x74, 0x52, 0x06, 0x73, 0x65, 0x72, 0x76,
|
||||||
0x0a, 0x08, 0x6f, 0x75, 0x74, 0x62, 0x6f, 0x75, 0x6e, 0x64, 0x12, 0x09, 0x68, 0x79, 0x73, 0x74,
|
0x65, 0x72, 0x3a, 0x19, 0x82, 0xb5, 0x18, 0x15, 0x0a, 0x08, 0x6f, 0x75, 0x74, 0x62, 0x6f, 0x75,
|
||||||
0x65, 0x72, 0x69, 0x61, 0x32, 0x22, 0x28, 0x0a, 0x0c, 0x53, 0x65, 0x72, 0x76, 0x65, 0x72, 0x43,
|
0x6e, 0x64, 0x12, 0x09, 0x68, 0x79, 0x73, 0x74, 0x65, 0x72, 0x69, 0x61, 0x32, 0x22, 0x7c, 0x0a,
|
||||||
0x6f, 0x6e, 0x66, 0x69, 0x67, 0x3a, 0x18, 0x82, 0xb5, 0x18, 0x14, 0x0a, 0x07, 0x69, 0x6e, 0x62,
|
0x0c, 0x53, 0x65, 0x72, 0x76, 0x65, 0x72, 0x43, 0x6f, 0x6e, 0x66, 0x69, 0x67, 0x12, 0x52, 0x0a,
|
||||||
0x6f, 0x75, 0x6e, 0x64, 0x12, 0x09, 0x68, 0x79, 0x73, 0x74, 0x65, 0x72, 0x69, 0x61, 0x32, 0x42,
|
0x0f, 0x70, 0x61, 0x63, 0x6b, 0x65, 0x74, 0x5f, 0x65, 0x6e, 0x63, 0x6f, 0x64, 0x69, 0x6e, 0x67,
|
||||||
0x6f, 0x0a, 0x1e, 0x63, 0x6f, 0x6d, 0x2e, 0x76, 0x32, 0x72, 0x61, 0x79, 0x2e, 0x63, 0x6f, 0x72,
|
0x18, 0x01, 0x20, 0x01, 0x28, 0x0e, 0x32, 0x29, 0x2e, 0x76, 0x32, 0x72, 0x61, 0x79, 0x2e, 0x63,
|
||||||
0x65, 0x2e, 0x70, 0x72, 0x6f, 0x78, 0x79, 0x2e, 0x68, 0x79, 0x73, 0x74, 0x65, 0x72, 0x69, 0x61,
|
0x6f, 0x72, 0x65, 0x2e, 0x6e, 0x65, 0x74, 0x2e, 0x70, 0x61, 0x63, 0x6b, 0x65, 0x74, 0x61, 0x64,
|
||||||
0x32, 0x50, 0x01, 0x5a, 0x2e, 0x67, 0x69, 0x74, 0x68, 0x75, 0x62, 0x2e, 0x63, 0x6f, 0x6d, 0x2f,
|
0x64, 0x72, 0x2e, 0x50, 0x61, 0x63, 0x6b, 0x65, 0x74, 0x41, 0x64, 0x64, 0x72, 0x54, 0x79, 0x70,
|
||||||
0x76, 0x32, 0x66, 0x6c, 0x79, 0x2f, 0x76, 0x32, 0x72, 0x61, 0x79, 0x2d, 0x63, 0x6f, 0x72, 0x65,
|
0x65, 0x52, 0x0e, 0x70, 0x61, 0x63, 0x6b, 0x65, 0x74, 0x45, 0x6e, 0x63, 0x6f, 0x64, 0x69, 0x6e,
|
||||||
0x2f, 0x76, 0x35, 0x2f, 0x70, 0x72, 0x6f, 0x78, 0x79, 0x2f, 0x68, 0x79, 0x73, 0x74, 0x65, 0x72,
|
0x67, 0x3a, 0x18, 0x82, 0xb5, 0x18, 0x14, 0x0a, 0x07, 0x69, 0x6e, 0x62, 0x6f, 0x75, 0x6e, 0x64,
|
||||||
0x69, 0x61, 0x32, 0xaa, 0x02, 0x1a, 0x56, 0x32, 0x52, 0x61, 0x79, 0x2e, 0x43, 0x6f, 0x72, 0x65,
|
0x12, 0x09, 0x68, 0x79, 0x73, 0x74, 0x65, 0x72, 0x69, 0x61, 0x32, 0x42, 0x6f, 0x0a, 0x1e, 0x63,
|
||||||
0x2e, 0x50, 0x72, 0x6f, 0x78, 0x79, 0x2e, 0x48, 0x79, 0x73, 0x74, 0x65, 0x72, 0x69, 0x61, 0x32,
|
0x6f, 0x6d, 0x2e, 0x76, 0x32, 0x72, 0x61, 0x79, 0x2e, 0x63, 0x6f, 0x72, 0x65, 0x2e, 0x70, 0x72,
|
||||||
0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33,
|
0x6f, 0x78, 0x79, 0x2e, 0x68, 0x79, 0x73, 0x74, 0x65, 0x72, 0x69, 0x61, 0x32, 0x50, 0x01, 0x5a,
|
||||||
|
0x2e, 0x67, 0x69, 0x74, 0x68, 0x75, 0x62, 0x2e, 0x63, 0x6f, 0x6d, 0x2f, 0x76, 0x32, 0x66, 0x6c,
|
||||||
|
0x79, 0x2f, 0x76, 0x32, 0x72, 0x61, 0x79, 0x2d, 0x63, 0x6f, 0x72, 0x65, 0x2f, 0x76, 0x35, 0x2f,
|
||||||
|
0x70, 0x72, 0x6f, 0x78, 0x79, 0x2f, 0x68, 0x79, 0x73, 0x74, 0x65, 0x72, 0x69, 0x61, 0x32, 0xaa,
|
||||||
|
0x02, 0x1a, 0x56, 0x32, 0x52, 0x61, 0x79, 0x2e, 0x43, 0x6f, 0x72, 0x65, 0x2e, 0x50, 0x72, 0x6f,
|
||||||
|
0x78, 0x79, 0x2e, 0x48, 0x79, 0x73, 0x74, 0x65, 0x72, 0x69, 0x61, 0x32, 0x62, 0x06, 0x70, 0x72,
|
||||||
|
0x6f, 0x74, 0x6f, 0x33,
|
||||||
}
|
}
|
||||||
|
|
||||||
var (
|
var (
|
||||||
@ -190,14 +206,16 @@ var file_proxy_hysteria2_config_proto_goTypes = []any{
|
|||||||
(*ClientConfig)(nil), // 1: v2ray.core.proxy.hysteria2.ClientConfig
|
(*ClientConfig)(nil), // 1: v2ray.core.proxy.hysteria2.ClientConfig
|
||||||
(*ServerConfig)(nil), // 2: v2ray.core.proxy.hysteria2.ServerConfig
|
(*ServerConfig)(nil), // 2: v2ray.core.proxy.hysteria2.ServerConfig
|
||||||
(*protocol.ServerEndpoint)(nil), // 3: v2ray.core.common.protocol.ServerEndpoint
|
(*protocol.ServerEndpoint)(nil), // 3: v2ray.core.common.protocol.ServerEndpoint
|
||||||
|
(packetaddr.PacketAddrType)(0), // 4: v2ray.core.net.packetaddr.PacketAddrType
|
||||||
}
|
}
|
||||||
var file_proxy_hysteria2_config_proto_depIdxs = []int32{
|
var file_proxy_hysteria2_config_proto_depIdxs = []int32{
|
||||||
3, // 0: v2ray.core.proxy.hysteria2.ClientConfig.server:type_name -> v2ray.core.common.protocol.ServerEndpoint
|
3, // 0: v2ray.core.proxy.hysteria2.ClientConfig.server:type_name -> v2ray.core.common.protocol.ServerEndpoint
|
||||||
1, // [1:1] is the sub-list for method output_type
|
4, // 1: v2ray.core.proxy.hysteria2.ServerConfig.packet_encoding:type_name -> v2ray.core.net.packetaddr.PacketAddrType
|
||||||
1, // [1:1] is the sub-list for method input_type
|
2, // [2:2] is the sub-list for method output_type
|
||||||
1, // [1:1] is the sub-list for extension type_name
|
2, // [2:2] is the sub-list for method input_type
|
||||||
1, // [1:1] is the sub-list for extension extendee
|
2, // [2:2] is the sub-list for extension type_name
|
||||||
0, // [0:1] is the sub-list for field type_name
|
2, // [2:2] is the sub-list for extension extendee
|
||||||
|
0, // [0:2] is the sub-list for field type_name
|
||||||
}
|
}
|
||||||
|
|
||||||
func init() { file_proxy_hysteria2_config_proto_init() }
|
func init() { file_proxy_hysteria2_config_proto_init() }
|
||||||
|
@ -6,11 +6,10 @@ option go_package = "github.com/v2fly/v2ray-core/v5/proxy/hysteria2";
|
|||||||
option java_package = "com.v2ray.core.proxy.hysteria2";
|
option java_package = "com.v2ray.core.proxy.hysteria2";
|
||||||
option java_multiple_files = true;
|
option java_multiple_files = true;
|
||||||
|
|
||||||
import "common/protocol/user.proto";
|
import "common/net/packetaddr/config.proto";
|
||||||
import "common/protocol/server_spec.proto";
|
import "common/protocol/server_spec.proto";
|
||||||
import "common/protoext/extensions.proto";
|
import "common/protoext/extensions.proto";
|
||||||
|
|
||||||
|
|
||||||
message Account {
|
message Account {
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -24,4 +23,6 @@ message ClientConfig {
|
|||||||
message ServerConfig {
|
message ServerConfig {
|
||||||
option (v2ray.core.common.protoext.message_opt).type = "inbound";
|
option (v2ray.core.common.protoext.message_opt).type = "inbound";
|
||||||
option (v2ray.core.common.protoext.message_opt).short_name = "hysteria2";
|
option (v2ray.core.common.protoext.message_opt).short_name = "hysteria2";
|
||||||
|
|
||||||
|
v2ray.core.net.packetaddr.PacketAddrType packet_encoding = 1;
|
||||||
}
|
}
|
||||||
|
@ -185,3 +185,26 @@ func (r *PacketReader) ReadMultiBufferWithMetadata() (*PacketPayload, error) {
|
|||||||
b := buf.FromBytes(data)
|
b := buf.FromBytes(data)
|
||||||
return &PacketPayload{Target: *dest, Buffer: buf.MultiBuffer{b}}, nil
|
return &PacketPayload{Target: *dest, Buffer: buf.MultiBuffer{b}}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type PacketConnectionReader struct {
|
||||||
|
reader *PacketReader
|
||||||
|
payload *PacketPayload
|
||||||
|
}
|
||||||
|
|
||||||
|
func (r *PacketConnectionReader) ReadFrom(p []byte) (n int, addr net.Addr, err error) {
|
||||||
|
if r.payload == nil || r.payload.Buffer.IsEmpty() {
|
||||||
|
r.payload, err = r.reader.ReadMultiBufferWithMetadata()
|
||||||
|
if err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
addr = &net.UDPAddr{
|
||||||
|
IP: r.payload.Target.Address.IP(),
|
||||||
|
Port: int(r.payload.Target.Port),
|
||||||
|
}
|
||||||
|
|
||||||
|
r.payload.Buffer, n = buf.SplitFirstBytes(r.payload.Buffer, p)
|
||||||
|
|
||||||
|
return
|
||||||
|
}
|
||||||
|
@ -13,6 +13,7 @@ import (
|
|||||||
"github.com/v2fly/v2ray-core/v5/common/errors"
|
"github.com/v2fly/v2ray-core/v5/common/errors"
|
||||||
"github.com/v2fly/v2ray-core/v5/common/log"
|
"github.com/v2fly/v2ray-core/v5/common/log"
|
||||||
"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"
|
||||||
udp_proto "github.com/v2fly/v2ray-core/v5/common/protocol/udp"
|
udp_proto "github.com/v2fly/v2ray-core/v5/common/protocol/udp"
|
||||||
"github.com/v2fly/v2ray-core/v5/common/session"
|
"github.com/v2fly/v2ray-core/v5/common/session"
|
||||||
"github.com/v2fly/v2ray-core/v5/common/signal"
|
"github.com/v2fly/v2ray-core/v5/common/signal"
|
||||||
@ -32,14 +33,16 @@ func init() {
|
|||||||
|
|
||||||
// Server is an inbound connection handler that handles messages in protocol.
|
// Server is an inbound connection handler that handles messages in protocol.
|
||||||
type Server struct {
|
type Server struct {
|
||||||
policyManager policy.Manager
|
policyManager policy.Manager
|
||||||
|
packetEncoding packetaddr.PacketAddrType
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewServer creates a new inbound handler.
|
// NewServer creates a new inbound handler.
|
||||||
func NewServer(ctx context.Context, config *ServerConfig) (*Server, error) {
|
func NewServer(ctx context.Context, config *ServerConfig) (*Server, error) {
|
||||||
v := core.MustFromContext(ctx)
|
v := core.MustFromContext(ctx)
|
||||||
server := &Server{
|
server := &Server{
|
||||||
policyManager: v.GetFeature(policy.ManagerType()).(policy.Manager),
|
policyManager: v.GetFeature(policy.ManagerType()).(policy.Manager),
|
||||||
|
packetEncoding: config.PacketEncoding,
|
||||||
}
|
}
|
||||||
return server, nil
|
return server, nil
|
||||||
}
|
}
|
||||||
@ -167,8 +170,14 @@ func (s *Server) handleConnection(ctx context.Context, sessionPolicy policy.Sess
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Server) handleUDPPayload(ctx context.Context, clientReader *PacketReader, clientWriter *PacketWriter, dispatcher routing.Dispatcher) error { // {{{
|
func (s *Server) handleUDPPayload(ctx context.Context, clientReader *PacketReader, clientWriter *PacketWriter, dispatcher routing.Dispatcher) error {
|
||||||
udpDispatcherConstructor := udp.NewSplitDispatcher
|
udpDispatcherConstructor := udp.NewSplitDispatcher
|
||||||
|
switch s.packetEncoding {
|
||||||
|
case packetaddr.PacketAddrType_None:
|
||||||
|
case packetaddr.PacketAddrType_Packet:
|
||||||
|
packetAddrDispatcherFactory := udp.NewPacketAddrDispatcherCreator(ctx)
|
||||||
|
udpDispatcherConstructor = packetAddrDispatcherFactory.NewPacketAddrDispatcher
|
||||||
|
}
|
||||||
|
|
||||||
udpServer := udpDispatcherConstructor(dispatcher, func(ctx context.Context, packet *udp_proto.Packet) {
|
udpServer := udpDispatcherConstructor(dispatcher, func(ctx context.Context, packet *udp_proto.Packet) {
|
||||||
if err := clientWriter.WriteMultiBufferWithMetadata(buf.MultiBuffer{packet.Payload}, packet.Source); err != nil {
|
if err := clientWriter.WriteMultiBufferWithMetadata(buf.MultiBuffer{packet.Payload}, packet.Source); err != nil {
|
||||||
|
Loading…
Reference in New Issue
Block a user