timeout setting for freedom

pull/298/head^2
v2ray 9 years ago
parent 2f47074c98
commit 47338fba1e

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

@ -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
}

@ -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)

Loading…
Cancel
Save