From 81c2d6963b5ee90eb91addc5af247b704415d268 Mon Sep 17 00:00:00 2001 From: xjasonlyu Date: Fri, 1 Apr 2022 22:26:05 +0800 Subject: [PATCH] Chore: reorder const and func --- core/option/option.go | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/core/option/option.go b/core/option/option.go index 43d0d1c..13d04f0 100644 --- a/core/option/option.go +++ b/core/option/option.go @@ -52,13 +52,13 @@ const ( // tcpMaxBufferSize is the maximum permitted size of a send/recv buffer. tcpMaxBufferSize = tcp.MaxBufferSize - // tcpDefaultReceiveBufferSize is the default size of the receive buffer - // for a transport endpoint. - tcpDefaultReceiveBufferSize = stack.DefaultBufferSize - // tcpDefaultBufferSize is the default size of the send buffer for // a transport endpoint. tcpDefaultSendBufferSize = stack.DefaultBufferSize + + // tcpDefaultReceiveBufferSize is the default size of the receive buffer + // for a transport endpoint. + tcpDefaultReceiveBufferSize = stack.DefaultBufferSize ) type Option func(*stack.Stack) error @@ -78,8 +78,8 @@ func WithDefault() Option { // in too large buffers. // // Ref: https://github.com/cloudflare/slirpnetstack/blob/master/stack.go - WithTCPReceiveBufferSizeRange(tcpMinBufferSize, tcpDefaultReceiveBufferSize, tcpMaxBufferSize), WithTCPSendBufferSizeRange(tcpMinBufferSize, tcpDefaultSendBufferSize, tcpMaxBufferSize), + WithTCPReceiveBufferSizeRange(tcpMinBufferSize, tcpDefaultReceiveBufferSize, tcpMaxBufferSize), WithTCPCongestionControl(tcpCongestionControlAlgorithm), WithTCPDelay(tcpDelayEnabled), @@ -159,17 +159,6 @@ func WithICMPLimit(limit rate.Limit) Option { } } -// WithTCPReceiveBufferSizeRange sets the receive buffer size range for TCP. -func WithTCPReceiveBufferSizeRange(a, b, c int) Option { - return func(s *stack.Stack) error { - rcvOpt := tcpip.TCPReceiveBufferSizeRangeOption{Min: a, Default: b, Max: c} - if err := s.SetTransportProtocolOption(tcp.ProtocolNumber, &rcvOpt); err != nil { - return fmt.Errorf("set TCP receive buffer size range: %s", err) - } - return nil - } -} - // WithTCPSendBufferSizeRange sets the send buffer size range for TCP. func WithTCPSendBufferSizeRange(a, b, c int) Option { return func(s *stack.Stack) error { @@ -181,6 +170,17 @@ func WithTCPSendBufferSizeRange(a, b, c int) Option { } } +// WithTCPReceiveBufferSizeRange sets the receive buffer size range for TCP. +func WithTCPReceiveBufferSizeRange(a, b, c int) Option { + return func(s *stack.Stack) error { + rcvOpt := tcpip.TCPReceiveBufferSizeRangeOption{Min: a, Default: b, Max: c} + if err := s.SetTransportProtocolOption(tcp.ProtocolNumber, &rcvOpt); err != nil { + return fmt.Errorf("set TCP receive buffer size range: %s", err) + } + return nil + } +} + // WithTCPCongestionControl sets the current congestion control algorithm. func WithTCPCongestionControl(cc string) Option { return func(s *stack.Stack) error {