diff --git a/transport/config.go b/transport/config.go index 1e05004c..18205c1c 100644 --- a/transport/config.go +++ b/transport/config.go @@ -17,6 +17,7 @@ func (this *Config) Apply() error { enableKcp = this.enableKcp if enableKcp { KcpConfig = this.kcpConfig + connectionReuse = false } return nil } diff --git a/transport/hub/dialer.go b/transport/hub/dialer.go index add425b9..e4c73c06 100644 --- a/transport/hub/dialer.go +++ b/transport/hub/dialer.go @@ -82,16 +82,9 @@ 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) - if err != nil { - return nil, err - } + conn, err := DialWithoutCache3(src, dest, proxyMeta) + if err != nil { + return nil, err } return &Connection{ dest: id, diff --git a/transport/hub/kcp.go b/transport/hub/kcp.go index eb62da3e..e5a7ef96 100644 --- a/transport/hub/kcp.go +++ b/transport/hub/kcp.go @@ -13,8 +13,10 @@ import ( ) type KCPVlistener struct { - lst *kcp.Listener - conf *kcpv.Config + 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() diff --git a/transport/hub/kcpv/config.go b/transport/hub/kcpv/config.go index c304e566..348b31de 100644 --- a/transport/hub/kcpv/config.go +++ b/transport/hub/kcpv/config.go @@ -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, }