From a2abdc3d2fad690347c15c76d36c912d08332c9c Mon Sep 17 00:00:00 2001 From: v2ray Date: Sat, 2 Jul 2016 08:45:31 +0200 Subject: [PATCH] refine mtu settings --- transport/internet/kcp/connection.go | 3 +-- transport/internet/kcp/kcp.go | 10 ++++------ transport/internet/kcp/output.go | 8 ++++++-- 3 files changed, 11 insertions(+), 10 deletions(-) diff --git a/transport/internet/kcp/connection.go b/transport/internet/kcp/connection.go index 214e62cc2..0513b6f7b 100644 --- a/transport/internet/kcp/connection.go +++ b/transport/internet/kcp/connection.go @@ -69,8 +69,7 @@ func NewConnection(conv uint16, writerCloser io.WriteCloser, local *net.UDPAddr, Authenticator: block, Writer: writerCloser, } - mtu := effectiveConfig.Mtu - uint32(block.HeaderSize()) - headerSize - conn.kcp = NewKCP(conv, mtu, effectiveConfig.GetSendingWindowSize(), effectiveConfig.GetReceivingWindowSize(), conn.writeBufferSize, authWriter) + conn.kcp = NewKCP(conv, effectiveConfig.GetSendingWindowSize(), effectiveConfig.GetReceivingWindowSize(), conn.writeBufferSize, authWriter) conn.kcp.NoDelay(effectiveConfig.Tti, 2, effectiveConfig.Congestion) conn.kcp.current = conn.Elapsed() diff --git a/transport/internet/kcp/kcp.go b/transport/internet/kcp/kcp.go index 9368bb349..a8f8631a1 100644 --- a/transport/internet/kcp/kcp.go +++ b/transport/internet/kcp/kcp.go @@ -7,7 +7,6 @@ package kcp import ( "github.com/v2ray/v2ray-core/common/alloc" - v2io "github.com/v2ray/v2ray-core/common/io" "github.com/v2ray/v2ray-core/common/log" ) @@ -46,7 +45,7 @@ type KCP struct { receivingUpdated bool lastPingTime uint32 - mtu, mss uint32 + mss uint32 snd_una, snd_nxt, rcv_nxt uint32 rx_rttvar, rx_srtt, rx_rto uint32 snd_wnd, rcv_wnd, rmt_wnd, cwnd uint32 @@ -66,18 +65,17 @@ type KCP struct { // NewKCP create a new kcp control object, 'conv' must equal in two endpoint // from the same connection. -func NewKCP(conv uint16, mtu uint32, sendingWindowSize uint32, receivingWindowSize uint32, sendingQueueSize uint32, output v2io.Writer) *KCP { +func NewKCP(conv uint16, sendingWindowSize uint32, receivingWindowSize uint32, sendingQueueSize uint32, output *AuthenticationWriter) *KCP { log.Debug("KCP|Core: creating KCP ", conv) kcp := new(KCP) kcp.conv = conv kcp.snd_wnd = sendingWindowSize kcp.rcv_wnd = receivingWindowSize kcp.rmt_wnd = IKCP_WND_RCV - kcp.mtu = mtu - kcp.mss = kcp.mtu - DataSegmentOverhead + kcp.mss = output.Mtu() - DataSegmentOverhead kcp.rx_rto = IKCP_RTO_DEF kcp.interval = IKCP_INTERVAL - kcp.output = NewSegmentWriter(mtu, output) + kcp.output = NewSegmentWriter(output) kcp.rcv_buf = NewReceivingWindow(receivingWindowSize) kcp.snd_queue = NewSendingQueue(sendingQueueSize) kcp.rcv_queue = NewReceivingQueue() diff --git a/transport/internet/kcp/output.go b/transport/internet/kcp/output.go index 8415f0615..12e718e95 100644 --- a/transport/internet/kcp/output.go +++ b/transport/internet/kcp/output.go @@ -15,9 +15,9 @@ type SegmentWriter struct { writer v2io.Writer } -func NewSegmentWriter(mtu uint32, writer v2io.Writer) *SegmentWriter { +func NewSegmentWriter(writer *AuthenticationWriter) *SegmentWriter { return &SegmentWriter{ - mtu: mtu, + mtu: writer.Mtu(), writer: writer, } } @@ -68,3 +68,7 @@ func (this *AuthenticationWriter) Write(payload *alloc.Buffer) error { } func (this *AuthenticationWriter) Release() {} + +func (this *AuthenticationWriter) Mtu() uint32 { + return effectiveConfig.Mtu - uint32(this.Authenticator.HeaderSize()) +}