mirror of
https://github.com/v2fly/v2ray-core.git
synced 2026-01-06 09:15:37 -05:00
massive refactoring for kcp
This commit is contained in:
@@ -6,19 +6,22 @@ import (
|
||||
"github.com/v2ray/v2ray-core/common/log"
|
||||
v2net "github.com/v2ray/v2ray-core/common/net"
|
||||
"github.com/v2ray/v2ray-core/transport"
|
||||
"github.com/v2ray/v2ray-core/transport/internet"
|
||||
)
|
||||
|
||||
type InboundConnectionConfig struct {
|
||||
Port v2net.Port
|
||||
ListenOn v2net.Address
|
||||
Protocol string
|
||||
Settings []byte
|
||||
Port v2net.Port
|
||||
ListenOn v2net.Address
|
||||
StreamSettings *internet.StreamSettings
|
||||
Protocol string
|
||||
Settings []byte
|
||||
}
|
||||
|
||||
type OutboundConnectionConfig struct {
|
||||
Protocol string
|
||||
SendThrough v2net.Address
|
||||
Settings []byte
|
||||
Protocol string
|
||||
SendThrough v2net.Address
|
||||
StreamSettings *internet.StreamSettings
|
||||
Settings []byte
|
||||
}
|
||||
|
||||
type LogConfig struct {
|
||||
@@ -40,19 +43,21 @@ type InboundDetourAllocationConfig struct {
|
||||
}
|
||||
|
||||
type InboundDetourConfig struct {
|
||||
Protocol string
|
||||
PortRange v2net.PortRange
|
||||
ListenOn v2net.Address
|
||||
Tag string
|
||||
Allocation *InboundDetourAllocationConfig
|
||||
Settings []byte
|
||||
Protocol string
|
||||
PortRange v2net.PortRange
|
||||
ListenOn v2net.Address
|
||||
Tag string
|
||||
Allocation *InboundDetourAllocationConfig
|
||||
StreamSettings *internet.StreamSettings
|
||||
Settings []byte
|
||||
}
|
||||
|
||||
type OutboundDetourConfig struct {
|
||||
Protocol string
|
||||
SendThrough v2net.Address
|
||||
Tag string
|
||||
Settings []byte
|
||||
Protocol string
|
||||
SendThrough v2net.Address
|
||||
StreamSettings *internet.StreamSettings
|
||||
Tag string
|
||||
Settings []byte
|
||||
}
|
||||
|
||||
type Config struct {
|
||||
|
||||
@@ -14,6 +14,7 @@ import (
|
||||
"github.com/v2ray/v2ray-core/common/log"
|
||||
v2net "github.com/v2ray/v2ray-core/common/net"
|
||||
"github.com/v2ray/v2ray-core/transport"
|
||||
"github.com/v2ray/v2ray-core/transport/internet"
|
||||
)
|
||||
|
||||
const (
|
||||
@@ -57,10 +58,11 @@ func (this *Config) UnmarshalJSON(data []byte) error {
|
||||
|
||||
func (this *InboundConnectionConfig) UnmarshalJSON(data []byte) error {
|
||||
type JsonConfig struct {
|
||||
Port uint16 `json:"port"`
|
||||
Listen *v2net.AddressJson `json:"listen"`
|
||||
Protocol string `json:"protocol"`
|
||||
Settings json.RawMessage `json:"settings"`
|
||||
Port uint16 `json:"port"`
|
||||
Listen *v2net.AddressJson `json:"listen"`
|
||||
Protocol string `json:"protocol"`
|
||||
StreamSetting *internet.StreamSettings `json:"streamSettings"`
|
||||
Settings json.RawMessage `json:"settings"`
|
||||
}
|
||||
|
||||
jsonConfig := new(JsonConfig)
|
||||
@@ -75,6 +77,9 @@ func (this *InboundConnectionConfig) UnmarshalJSON(data []byte) error {
|
||||
}
|
||||
this.ListenOn = jsonConfig.Listen.Address
|
||||
}
|
||||
if jsonConfig.StreamSetting != nil {
|
||||
this.StreamSettings = jsonConfig.StreamSetting
|
||||
}
|
||||
|
||||
this.Protocol = jsonConfig.Protocol
|
||||
this.Settings = jsonConfig.Settings
|
||||
@@ -83,9 +88,10 @@ func (this *InboundConnectionConfig) UnmarshalJSON(data []byte) error {
|
||||
|
||||
func (this *OutboundConnectionConfig) UnmarshalJSON(data []byte) error {
|
||||
type JsonConnectionConfig struct {
|
||||
Protocol string `json:"protocol"`
|
||||
SendThrough *v2net.AddressJson `json:"sendThrough"`
|
||||
Settings json.RawMessage `json:"settings"`
|
||||
Protocol string `json:"protocol"`
|
||||
SendThrough *v2net.AddressJson `json:"sendThrough"`
|
||||
StreamSetting *internet.StreamSettings `json:"streamSettings"`
|
||||
Settings json.RawMessage `json:"settings"`
|
||||
}
|
||||
jsonConfig := new(JsonConnectionConfig)
|
||||
if err := json.Unmarshal(data, jsonConfig); err != nil {
|
||||
@@ -101,6 +107,9 @@ func (this *OutboundConnectionConfig) UnmarshalJSON(data []byte) error {
|
||||
}
|
||||
this.SendThrough = address
|
||||
}
|
||||
if jsonConfig.StreamSetting != nil {
|
||||
this.StreamSettings = jsonConfig.StreamSetting
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -162,12 +171,13 @@ func (this *InboundDetourAllocationConfig) UnmarshalJSON(data []byte) error {
|
||||
|
||||
func (this *InboundDetourConfig) UnmarshalJSON(data []byte) error {
|
||||
type JsonInboundDetourConfig struct {
|
||||
Protocol string `json:"protocol"`
|
||||
PortRange *v2net.PortRange `json:"port"`
|
||||
ListenOn *v2net.AddressJson `json:"listen"`
|
||||
Settings json.RawMessage `json:"settings"`
|
||||
Tag string `json:"tag"`
|
||||
Allocation *InboundDetourAllocationConfig `json:"allocate"`
|
||||
Protocol string `json:"protocol"`
|
||||
PortRange *v2net.PortRange `json:"port"`
|
||||
ListenOn *v2net.AddressJson `json:"listen"`
|
||||
Settings json.RawMessage `json:"settings"`
|
||||
Tag string `json:"tag"`
|
||||
Allocation *InboundDetourAllocationConfig `json:"allocate"`
|
||||
StreamSetting *internet.StreamSettings `json:"streamSettings"`
|
||||
}
|
||||
jsonConfig := new(JsonInboundDetourConfig)
|
||||
if err := json.Unmarshal(data, jsonConfig); err != nil {
|
||||
@@ -195,15 +205,19 @@ func (this *InboundDetourConfig) UnmarshalJSON(data []byte) error {
|
||||
Refresh: DefaultRefreshMinute,
|
||||
}
|
||||
}
|
||||
if jsonConfig.StreamSetting != nil {
|
||||
this.StreamSettings = jsonConfig.StreamSetting
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (this *OutboundDetourConfig) UnmarshalJSON(data []byte) error {
|
||||
type JsonOutboundDetourConfig struct {
|
||||
Protocol string `json:"protocol"`
|
||||
SendThrough *v2net.AddressJson `json:"sendThrough"`
|
||||
Tag string `json:"tag"`
|
||||
Settings json.RawMessage `json:"settings"`
|
||||
Protocol string `json:"protocol"`
|
||||
SendThrough *v2net.AddressJson `json:"sendThrough"`
|
||||
Tag string `json:"tag"`
|
||||
Settings json.RawMessage `json:"settings"`
|
||||
StreamSetting *internet.StreamSettings `json:"streamSettings"`
|
||||
}
|
||||
jsonConfig := new(JsonOutboundDetourConfig)
|
||||
if err := json.Unmarshal(data, jsonConfig); err != nil {
|
||||
@@ -220,6 +234,10 @@ func (this *OutboundDetourConfig) UnmarshalJSON(data []byte) error {
|
||||
}
|
||||
this.SendThrough = address
|
||||
}
|
||||
|
||||
if jsonConfig.StreamSetting != nil {
|
||||
this.StreamSettings = jsonConfig.StreamSetting
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
|
||||
@@ -26,9 +26,10 @@ func NewInboundDetourHandlerAlways(space app.Space, config *InboundDetourConfig)
|
||||
for i := ports.From; i <= ports.To; i++ {
|
||||
ichConfig := config.Settings
|
||||
ich, err := proxyrepo.CreateInboundHandler(config.Protocol, space, ichConfig, &proxy.InboundHandlerMeta{
|
||||
Address: config.ListenOn,
|
||||
Port: i,
|
||||
Tag: config.Tag})
|
||||
Address: config.ListenOn,
|
||||
Port: i,
|
||||
Tag: config.Tag,
|
||||
StreamSettings: config.StreamSettings})
|
||||
if err != nil {
|
||||
log.Error("Failed to create inbound connection handler: ", err)
|
||||
return nil, err
|
||||
|
||||
@@ -32,9 +32,10 @@ func NewInboundDetourHandlerDynamic(space app.Space, config *InboundDetourConfig
|
||||
|
||||
// To test configuration
|
||||
ich, err := proxyrepo.CreateInboundHandler(config.Protocol, space, config.Settings, &proxy.InboundHandlerMeta{
|
||||
Address: config.ListenOn,
|
||||
Port: 0,
|
||||
Tag: config.Tag})
|
||||
Address: config.ListenOn,
|
||||
Port: 0,
|
||||
Tag: config.Tag,
|
||||
StreamSettings: config.StreamSettings})
|
||||
if err != nil {
|
||||
log.Error("Point: Failed to create inbound connection handler: ", err)
|
||||
return nil, err
|
||||
@@ -99,7 +100,7 @@ func (this *InboundDetourHandlerDynamic) refresh() error {
|
||||
for idx, _ := range newIchs {
|
||||
port := this.pickUnusedPort()
|
||||
ich, err := proxyrepo.CreateInboundHandler(config.Protocol, this.space, config.Settings, &proxy.InboundHandlerMeta{
|
||||
Address: config.ListenOn, Port: port, Tag: config.Tag})
|
||||
Address: config.ListenOn, Port: port, Tag: config.Tag, StreamSettings: config.StreamSettings})
|
||||
if err != nil {
|
||||
log.Error("Point: Failed to create inbound connection handler: ", err)
|
||||
return err
|
||||
|
||||
@@ -93,9 +93,10 @@ func NewPoint(pConfig *Config) (*Point, error) {
|
||||
ichConfig := pConfig.InboundConfig.Settings
|
||||
ich, err := proxyrepo.CreateInboundHandler(
|
||||
pConfig.InboundConfig.Protocol, vpoint.space, ichConfig, &proxy.InboundHandlerMeta{
|
||||
Tag: "system.inbound",
|
||||
Address: pConfig.InboundConfig.ListenOn,
|
||||
Port: vpoint.port})
|
||||
Tag: "system.inbound",
|
||||
Address: pConfig.InboundConfig.ListenOn,
|
||||
Port: vpoint.port,
|
||||
StreamSettings: pConfig.InboundConfig.StreamSettings})
|
||||
if err != nil {
|
||||
log.Error("Failed to create inbound connection handler: ", err)
|
||||
return nil, err
|
||||
@@ -105,8 +106,10 @@ func NewPoint(pConfig *Config) (*Point, error) {
|
||||
ochConfig := pConfig.OutboundConfig.Settings
|
||||
och, err := proxyrepo.CreateOutboundHandler(
|
||||
pConfig.OutboundConfig.Protocol, vpoint.space, ochConfig, &proxy.OutboundHandlerMeta{
|
||||
Tag: "system.outbound",
|
||||
Address: pConfig.OutboundConfig.SendThrough})
|
||||
Tag: "system.outbound",
|
||||
Address: pConfig.OutboundConfig.SendThrough,
|
||||
StreamSettings: pConfig.OutboundConfig.StreamSettings,
|
||||
})
|
||||
if err != nil {
|
||||
log.Error("Failed to create outbound connection handler: ", err)
|
||||
return nil, err
|
||||
@@ -153,8 +156,10 @@ func NewPoint(pConfig *Config) (*Point, error) {
|
||||
for _, detourConfig := range outboundDetours {
|
||||
detourHandler, err := proxyrepo.CreateOutboundHandler(
|
||||
detourConfig.Protocol, vpoint.space, detourConfig.Settings, &proxy.OutboundHandlerMeta{
|
||||
Tag: detourConfig.Tag,
|
||||
Address: detourConfig.SendThrough})
|
||||
Tag: detourConfig.Tag,
|
||||
Address: detourConfig.SendThrough,
|
||||
StreamSettings: detourConfig.StreamSettings,
|
||||
})
|
||||
if err != nil {
|
||||
log.Error("Point: Failed to create detour outbound connection handler: ", err)
|
||||
return nil, err
|
||||
|
||||
Reference in New Issue
Block a user