1
0
mirror of https://github.com/v2fly/v2ray-core.git synced 2024-12-30 05:56:54 -05:00

timeout setting for freedom

This commit is contained in:
v2ray 2016-06-02 23:18:44 +02:00
parent 2f47074c98
commit 47338fba1e
3 changed files with 10 additions and 1 deletions

View File

@ -9,4 +9,5 @@ const (
type Config struct {
DomainStrategy DomainStrategy
Timeout uint32
}

View File

@ -12,6 +12,7 @@ import (
func (this *Config) UnmarshalJSON(data []byte) error {
type JsonConfig struct {
DomainStrategy string `json:"domainStrategy"`
Timeout uint32 `json:"timeout"`
}
jsonConfig := new(JsonConfig)
if err := json.Unmarshal(data, jsonConfig); err != nil {
@ -22,6 +23,7 @@ func (this *Config) UnmarshalJSON(data []byte) error {
if domainStrategy == "useip" {
this.DomainStrategy = DomainStrategyUseIP
}
this.Timeout = jsonConfig.Timeout
return nil
}

View File

@ -21,12 +21,14 @@ import (
type FreedomConnection struct {
domainStrategy DomainStrategy
timeout uint32
dns dns.Server
}
func NewFreedomConnection(config *Config, space app.Space) *FreedomConnection {
f := &FreedomConnection{
domainStrategy: config.DomainStrategy,
timeout: config.Timeout,
}
log.Info("Freedom: Domain strategy: ", f.domainStrategy)
space.InitializeApplication(func() error {
@ -111,8 +113,12 @@ func (this *FreedomConnection) Dispatch(destination v2net.Destination, payload *
var reader io.Reader = conn
timeout := this.timeout
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)