mirror of
https://github.com/v2fly/v2ray-core.git
synced 2025-01-04 16:37:12 -05:00
timeout setting for freedom
This commit is contained in:
parent
2f47074c98
commit
47338fba1e
@ -9,4 +9,5 @@ const (
|
|||||||
|
|
||||||
type Config struct {
|
type Config struct {
|
||||||
DomainStrategy DomainStrategy
|
DomainStrategy DomainStrategy
|
||||||
|
Timeout uint32
|
||||||
}
|
}
|
||||||
|
@ -12,6 +12,7 @@ import (
|
|||||||
func (this *Config) UnmarshalJSON(data []byte) error {
|
func (this *Config) UnmarshalJSON(data []byte) error {
|
||||||
type JsonConfig struct {
|
type JsonConfig struct {
|
||||||
DomainStrategy string `json:"domainStrategy"`
|
DomainStrategy string `json:"domainStrategy"`
|
||||||
|
Timeout uint32 `json:"timeout"`
|
||||||
}
|
}
|
||||||
jsonConfig := new(JsonConfig)
|
jsonConfig := new(JsonConfig)
|
||||||
if err := json.Unmarshal(data, jsonConfig); err != nil {
|
if err := json.Unmarshal(data, jsonConfig); err != nil {
|
||||||
@ -22,6 +23,7 @@ func (this *Config) UnmarshalJSON(data []byte) error {
|
|||||||
if domainStrategy == "useip" {
|
if domainStrategy == "useip" {
|
||||||
this.DomainStrategy = DomainStrategyUseIP
|
this.DomainStrategy = DomainStrategyUseIP
|
||||||
}
|
}
|
||||||
|
this.Timeout = jsonConfig.Timeout
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -21,12 +21,14 @@ import (
|
|||||||
|
|
||||||
type FreedomConnection struct {
|
type FreedomConnection struct {
|
||||||
domainStrategy DomainStrategy
|
domainStrategy DomainStrategy
|
||||||
|
timeout uint32
|
||||||
dns dns.Server
|
dns dns.Server
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewFreedomConnection(config *Config, space app.Space) *FreedomConnection {
|
func NewFreedomConnection(config *Config, space app.Space) *FreedomConnection {
|
||||||
f := &FreedomConnection{
|
f := &FreedomConnection{
|
||||||
domainStrategy: config.DomainStrategy,
|
domainStrategy: config.DomainStrategy,
|
||||||
|
timeout: config.Timeout,
|
||||||
}
|
}
|
||||||
log.Info("Freedom: Domain strategy: ", f.domainStrategy)
|
log.Info("Freedom: Domain strategy: ", f.domainStrategy)
|
||||||
space.InitializeApplication(func() error {
|
space.InitializeApplication(func() error {
|
||||||
@ -111,8 +113,12 @@ func (this *FreedomConnection) Dispatch(destination v2net.Destination, payload *
|
|||||||
|
|
||||||
var reader io.Reader = conn
|
var reader io.Reader = conn
|
||||||
|
|
||||||
|
timeout := this.timeout
|
||||||
if destination.IsUDP() {
|
if destination.IsUDP() {
|
||||||
reader = v2net.NewTimeOutReader(16 /* seconds */, conn)
|
timeout = 16
|
||||||
|
}
|
||||||
|
if timeout > 0 {
|
||||||
|
reader = v2net.NewTimeOutReader(int(timeout) /* seconds */, conn)
|
||||||
}
|
}
|
||||||
|
|
||||||
v2reader := v2io.NewAdaptiveReader(reader)
|
v2reader := v2io.NewAdaptiveReader(reader)
|
||||||
|
Loading…
Reference in New Issue
Block a user