Removed manadory mandatory requirement for Read/Write Timeout

pull/170/head
Shelikhoo 9 years ago
parent 9315bb29fb
commit d0d63ee5b3
No known key found for this signature in database
GPG Key ID: 7791BDB0709ABD21

@ -17,6 +17,7 @@ func (this *Config) Apply() error {
enableKcp = this.enableKcp
if enableKcp {
KcpConfig = this.kcpConfig
connectionReuse = false
}
return nil
}

@ -82,17 +82,10 @@ func DialKCP3(src v2net.Address, dest v2net.Destination, proxyMeta *proxy.Outbou
src = v2net.AnyIP
}
id := src.String() + "-" + dest.NetAddr()
var conn net.Conn
if dest.IsTCP() && transport.IsConnectionReusable() {
conn = globalCache.Get(id)
}
if conn == nil {
var err error
conn, err = DialWithoutCache3(src, dest, proxyMeta)
conn, err := DialWithoutCache3(src, dest, proxyMeta)
if err != nil {
return nil, err
}
}
return &Connection{
dest: id,
conn: conn,

@ -15,6 +15,8 @@ import (
type KCPVlistener struct {
lst *kcp.Listener
conf *kcpv.Config
previousSocketid map[int]uint32
previousSocketid_mapid int
}
func (kvl *KCPVlistener) Accept() (net.Conn, error) {
@ -23,6 +25,28 @@ func (kvl *KCPVlistener) Accept() (net.Conn, error) {
return nil, err
}
if kvl.previousSocketid == nil {
kvl.previousSocketid = make(map[int]uint32)
}
var badbit bool = false
for _, key := range kvl.previousSocketid {
log.Info("kcp: listener testing,", key, ":", conn.GetConv())
if key == conn.GetConv() {
badbit = true
}
}
if badbit {
return nil, errors.New("KCP:ConnDup, Don't worry~")
} else {
kvl.previousSocketid_mapid++
kvl.previousSocketid[kvl.previousSocketid_mapid] = conn.GetConv()
if kvl.previousSocketid_mapid >= 512 {
delete(kvl.previousSocketid, kvl.previousSocketid_mapid-512)
}
}
kcv := &KCPVconn{hc: conn}
kcv.conf = kvl.conf
err = kcv.ApplyConf()

@ -18,5 +18,5 @@ type Config struct {
}
var DefaultAdvancedConfigs = &AdvancedConfig{
Mtu: 1350, Sndwnd: 1024, Rcvwnd: 1024, Fec: 4, Dscp: 0, ReadTimeout: 60, WriteTimeout: 40, Acknodelay: false,
Mtu: 1350, Sndwnd: 1024, Rcvwnd: 1024, Fec: 4, Dscp: 0, ReadTimeout: 18600, WriteTimeout: 18500, Acknodelay: false,
}

Loading…
Cancel
Save