1
0
mirror of https://github.com/v2fly/v2ray-core.git synced 2024-12-22 18:17:52 -05:00

KCP: Moved apply to KCPv

This commit is contained in:
Shelikhoo 2016-06-12 12:24:09 +08:00
parent 0f28c577ce
commit e84d52263d
No known key found for this signature in database
GPG Key ID: 7791BDB0709ABD21

View File

@ -20,31 +20,13 @@ func (kvl *KCPVlistener) Accept() (*KCPVconn, error) {
if err != nil { if err != nil {
return nil, err return nil, err
} }
nodelay, interval, resend, nc := 0, 40, 0, 0
if kvl.conf.Mode != "manual" {
switch kvl.conf.Mode {
case "normal":
nodelay, interval, resend, nc = 0, 30, 2, 1
case "fast":
nodelay, interval, resend, nc = 0, 20, 2, 1
case "fast2":
nodelay, interval, resend, nc = 1, 20, 2, 1
case "fast3":
nodelay, interval, resend, nc = 1, 10, 2, 1
}
} else {
log.Error("kcp: Accepted Unsuccessfully: Manual mode is not supported.(yet!)")
return nil, errors.New("kcp: Manual Not Implemented")
}
conn.SetNoDelay(nodelay, interval, resend, nc)
conn.SetWindowSize(kvl.conf.AdvancedConfigs.Sndwnd, kvl.conf.AdvancedConfigs.Rcvwnd)
conn.SetMtu(kvl.conf.AdvancedConfigs.Mtu)
conn.SetACKNoDelay(kvl.conf.AdvancedConfigs.Acknodelay)
conn.SetDSCP(kvl.conf.AdvancedConfigs.Dscp)
kcv := &KCPVconn{hc: conn} kcv := &KCPVconn{hc: conn}
kcv.conf = kvl.conf kcv.conf = kvl.conf
err = kcv.ApplyConf()
if err != nil {
return nil, err
}
return kcv, nil return kcv, nil
} }
func (kvl *KCPVlistener) Close() error { func (kvl *KCPVlistener) Close() error {
@ -77,6 +59,31 @@ func (kcpvc *KCPVconn) Write(b []byte) (int, error) {
kcpvc.hc.SetDeadline(kcpvc.conntokeep) kcpvc.hc.SetDeadline(kcpvc.conntokeep)
return kcpvc.hc.Write(b) return kcpvc.hc.Write(b)
} }
func (kcpvc *KCPVconn) ApplyConf() error {
nodelay, interval, resend, nc := 0, 40, 0, 0
if kcpvc.conf.Mode != "manual" {
switch kcpvc.conf.Mode {
case "normal":
nodelay, interval, resend, nc = 0, 30, 2, 1
case "fast":
nodelay, interval, resend, nc = 0, 20, 2, 1
case "fast2":
nodelay, interval, resend, nc = 1, 20, 2, 1
case "fast3":
nodelay, interval, resend, nc = 1, 10, 2, 1
}
} else {
log.Error("kcp: Failed to Apply configure: Manual mode is not supported.(yet!)")
return errors.New("kcp: Manual Not Implemented")
}
kcpvc.hc.SetNoDelay(nodelay, interval, resend, nc)
kcpvc.hc.SetWindowSize(kcpvc.conf.AdvancedConfigs.Sndwnd, kcpvc.conf.AdvancedConfigs.Rcvwnd)
kcpvc.hc.SetMtu(kcpvc.conf.AdvancedConfigs.Mtu)
kcpvc.hc.SetACKNoDelay(kcpvc.conf.AdvancedConfigs.Acknodelay)
kcpvc.hc.SetDSCP(kcpvc.conf.AdvancedConfigs.Dscp)
return nil
}
func (kcpvc *KCPVconn) Close() error { func (kcpvc *KCPVconn) Close() error {