From 8c5d1fdf2b2edde0abf6f7427574c6851c10566a Mon Sep 17 00:00:00 2001 From: Steffen Vogel Date: Wed, 16 Nov 2022 10:50:39 +0200 Subject: [PATCH] Fix Typos Fix Typos --- connctx/connctx_test.go | 8 +++--- packetio/buffer.go | 38 +++++++++++++-------------- packetio/buffer_test.go | 6 ++--- packetio/hardlimit.go | 2 +- packetio/no_hardlimit.go | 2 +- replaydetector/replaydetector.go | 2 +- replaydetector/replaydetector_test.go | 2 +- test/bridge_test.go | 2 +- test/util.go | 8 +++--- vnet/chunk_test.go | 4 +-- vnet/conn.go | 2 +- vnet/delay_filter_test.go | 4 +-- vnet/nat_test.go | 8 +++--- vnet/resolver.go | 4 +-- vnet/router.go | 2 +- vnet/tbf.go | 2 +- vnet/tbf_test.go | 2 +- vnet/udpproxy_direct_test.go | 2 +- vnet/udpproxy_test.go | 2 +- 19 files changed, 51 insertions(+), 51 deletions(-) diff --git a/connctx/connctx_test.go b/connctx/connctx_test.go index 4f9b1b6..01a6159 100644 --- a/connctx/connctx_test.go +++ b/connctx/connctx_test.go @@ -56,7 +56,7 @@ func TestReadTImeout(t *testing.T) { b := make([]byte, 100) n, err := c.ReadContext(ctx, b) if err == nil { - t.Error("Read unexpectedly successed") + t.Error("Read unexpectedly succeeded") } if n != 0 { t.Errorf("Wrong data length, expected %d, got %d", 0, n) @@ -79,7 +79,7 @@ func TestReadCancel(t *testing.T) { b := make([]byte, 100) n, err := c.ReadContext(ctx, b) if err == nil { - t.Error("Read unexpectedly successed") + t.Error("Read unexpectedly succeeded") } if n != 0 { t.Errorf("Wrong data length, expected %d, got %d", 0, n) @@ -151,7 +151,7 @@ func TestWriteTimeout(t *testing.T) { b := make([]byte, 100) n, err := c.WriteContext(ctx, b) if err == nil { - t.Error("Write unexpectedly successed") + t.Error("Write unexpectedly succeeded") } if n != 0 { t.Errorf("Wrong data length, expected %d, got %d", 0, n) @@ -174,7 +174,7 @@ func TestWriteCancel(t *testing.T) { b := make([]byte, 100) n, err := c.WriteContext(ctx, b) if err == nil { - t.Error("Write unexpectedly successed") + t.Error("Write unexpectedly succeeded") } if n != 0 { t.Errorf("Wrong data length, expected %d, got %d", 0, n) diff --git a/packetio/buffer.go b/packetio/buffer.go index 97d86f8..77b9d8d 100644 --- a/packetio/buffer.go +++ b/packetio/buffer.go @@ -77,42 +77,42 @@ func (b *Buffer) available(size int) bool { // grow increases the size of the buffer. If it returns nil, then the // buffer has been grown. It returns ErrFull if hits a limit. func (b *Buffer) grow() error { - var newsize int + var newSize int if len(b.data) < cutoffSize { - newsize = 2 * len(b.data) + newSize = 2 * len(b.data) } else { - newsize = 5 * len(b.data) / 4 + newSize = 5 * len(b.data) / 4 } - if newsize < minSize { - newsize = minSize + if newSize < minSize { + newSize = minSize } - if (b.limitSize <= 0 || sizeHardlimit) && newsize > maxSize { - newsize = maxSize + if (b.limitSize <= 0 || sizeHardLimit) && newSize > maxSize { + newSize = maxSize } // one byte slack - if b.limitSize > 0 && newsize > b.limitSize+1 { - newsize = b.limitSize + 1 + if b.limitSize > 0 && newSize > b.limitSize+1 { + newSize = b.limitSize + 1 } - if newsize <= len(b.data) { + if newSize <= len(b.data) { return ErrFull } - newdata := make([]byte, newsize) + newData := make([]byte, newSize) var n int if b.head <= b.tail { // data was contiguous - n = copy(newdata, b.data[b.head:b.tail]) + n = copy(newData, b.data[b.head:b.tail]) } else { - // data was discontiguous - n = copy(newdata, b.data[b.head:]) - n += copy(newdata[n:], b.data[:b.tail]) + // data was discontinuous + n = copy(newData, b.data[b.head:]) + n += copy(newData[n:], b.data[:b.tail]) } b.head = 0 b.tail = n - b.data = newdata + b.data = newData return nil } @@ -329,9 +329,9 @@ func (b *Buffer) size() int { // Causes Write to return ErrFull when this limit is reached. // A zero value means 4MB since v0.11.0. // -// User can set packetioSizeHardlimit build tag to enable 4MB hardlimit. -// When packetioSizeHardlimit build tag is set, SetLimitSize exceeding -// the hardlimit will be silently discarded. +// User can set packetioSizeHardLimit build tag to enable 4MB hard limit. +// When packetioSizeHardLimit build tag is set, SetLimitSize exceeding +// the hard limit will be silently discarded. func (b *Buffer) SetLimitSize(limit int) { b.mutex.Lock() defer b.mutex.Unlock() diff --git a/packetio/buffer_test.go b/packetio/buffer_test.go index 85fea8a..d2dd804 100644 --- a/packetio/buffer_test.go +++ b/packetio/buffer_test.go @@ -321,8 +321,8 @@ func TestBufferLimitSize(t *testing.T) { } func TestBufferLimitSizes(t *testing.T) { - if sizeHardlimit { - t.Skip("skipping since packetioSizeHardlimit is enabled") + if sizeHardLimit { + t.Skip("skipping since packetioSizeHardLimit is enabled") } sizes := []int{ 128 * 1024, @@ -337,7 +337,7 @@ func TestBufferLimitSizes(t *testing.T) { size := size name := "default" if size > 0 { - name = fmt.Sprintf("%dkbytes", size/1024) + name = fmt.Sprintf("%dkBytes", size/1024) } t.Run(name, func(t *testing.T) { diff --git a/packetio/hardlimit.go b/packetio/hardlimit.go index 5ddacc7..b902ef9 100644 --- a/packetio/hardlimit.go +++ b/packetio/hardlimit.go @@ -2,4 +2,4 @@ package packetio -const sizeHardlimit = true +const sizeHardLimit = true diff --git a/packetio/no_hardlimit.go b/packetio/no_hardlimit.go index ccbb615..869e0b6 100644 --- a/packetio/no_hardlimit.go +++ b/packetio/no_hardlimit.go @@ -3,4 +3,4 @@ package packetio -const sizeHardlimit = false +const sizeHardLimit = false diff --git a/replaydetector/replaydetector.go b/replaydetector/replaydetector.go index d942002..297f9f3 100644 --- a/replaydetector/replaydetector.go +++ b/replaydetector/replaydetector.go @@ -55,7 +55,7 @@ func (d *slidingWindowDetector) Check(seq uint64) (accept func(), ok bool) { } // WithWrap creates ReplayDetector allowing sequence wrapping. -// This is suitable for short bitwidth counter like SRTP and SRTCP. +// This is suitable for short bit width counter like SRTP and SRTCP. func WithWrap(windowSize uint, maxSeq uint64) ReplayDetector { return &wrappedSlidingWindowDetector{ maxSeq: maxSeq, diff --git a/replaydetector/replaydetector_test.go b/replaydetector/replaydetector_test.go index 33ca22c..7b57766 100644 --- a/replaydetector/replaydetector_test.go +++ b/replaydetector/replaydetector_test.go @@ -94,7 +94,7 @@ func TestReplayDetector(t *testing.T) { []uint64{24, 32, 40, 48, 56, 64, 72, 80, 88, 96, 104, 112, 120, 128}, nil, }, - "ContinuouesReplayed": { + "ContinuousReplayed": { 8, 0x0000FFFFFFFFFFFF, []uint64{16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25}, []bool{ diff --git a/test/bridge_test.go b/test/bridge_test.go index 47748e5..073cf59 100644 --- a/test/bridge_test.go +++ b/test/bridge_test.go @@ -469,7 +469,7 @@ func TestNetTest(t *testing.T) { return &closePropagator{conn0, conn1}, &closePropagator{conn1, conn0}, func() { // RacyRead test leave receive buffer filled. - // As net.Conn.Read() shoud return received data even after Close()-ed, + // As net.Conn.Read() should return received data even after Close()-ed, // queue must be cleared explicitly. br.clear() _ = conn0.Close() diff --git a/test/util.go b/test/util.go index 8924d4c..48906d7 100644 --- a/test/util.go +++ b/test/util.go @@ -85,17 +85,17 @@ func GatherErrs(c chan error) []error { // FlattenErrs flattens a slice of errors into a single error func FlattenErrs(errs []error) error { - var errstrings []string + var errStrings []string for _, err := range errs { if err != nil { - errstrings = append(errstrings, err.Error()) + errStrings = append(errStrings, err.Error()) } } - if len(errstrings) == 0 { + if len(errStrings) == 0 { return nil } - return fmt.Errorf("%w %s", errFlattenErrs, strings.Join(errstrings, "\n")) + return fmt.Errorf("%w %s", errFlattenErrs, strings.Join(errStrings, "\n")) } diff --git a/vnet/chunk_test.go b/vnet/chunk_test.go index fff5f77..e5ab1eb 100644 --- a/vnet/chunk_test.go +++ b/vnet/chunk_test.go @@ -67,7 +67,7 @@ func TestChunk(t *testing.T) { assert.Equal(t, uc.tag, uc.Tag(), "should match") // Verify cloned chunk was not affected by the changes to original chunk - uc.userData[0] = []byte("!")[0] // oroginal: "Hello" -> "Hell!" + uc.userData[0] = []byte("!")[0] // original: "Hello" -> "Hell!" assert.Equal(t, "Hello", string(cloned.userData), "should match") assert.Equal(t, "192.168.0.2:1234", cloned.SourceAddr().String()) assert.True(t, cloned.getSourceIP().Equal(src.IP), "ip should match") @@ -117,7 +117,7 @@ func TestChunk(t *testing.T) { assert.Equal(t, tc.tag, tc.Tag(), "should match") // Verify cloned chunk was not affected by the changes to original chunk - tc.userData[0] = []byte("!")[0] // oroginal: "Hello" -> "Hell!" + tc.userData[0] = []byte("!")[0] // original: "Hello" -> "Hell!" assert.Equal(t, "Hello", string(cloned.userData), "should match") assert.Equal(t, "192.168.0.2:1234", cloned.SourceAddr().String()) assert.True(t, cloned.getSourceIP().Equal(src.IP), "ip should match") diff --git a/vnet/conn.go b/vnet/conn.go index f4b8b92..6aa788b 100644 --- a/vnet/conn.go +++ b/vnet/conn.go @@ -38,7 +38,7 @@ type connObserver interface { } // UDPConn is the implementation of the Conn and PacketConn interfaces for UDP network connections. -// comatible with net.PacketConn and net.Conn +// compatible with net.PacketConn and net.Conn type UDPConn struct { locAddr *net.UDPAddr // read-only remAddr *net.UDPAddr // read-only diff --git a/vnet/delay_filter_test.go b/vnet/delay_filter_test.go index e6874a5..1571f25 100644 --- a/vnet/delay_filter_test.go +++ b/vnet/delay_filter_test.go @@ -73,7 +73,7 @@ func TestDelayFilter(t *testing.T) { } } - // schedula 100 chunks + // schedule 100 chunks sent := time.Now() for i := 0; i < 100; i++ { df.onInboundChunk(&chunkUDP{ @@ -82,7 +82,7 @@ func TestDelayFilter(t *testing.T) { }) } - // receive 100 chunks with deay>10ms + // receive 100 chunks with delay>10ms for i := 0; i < 100; i++ { select { case c := <-receiveCh: diff --git a/vnet/nat_test.go b/vnet/nat_test.go index 175493a..b101b3e 100644 --- a/vnet/nat_test.go +++ b/vnet/nat_test.go @@ -16,7 +16,7 @@ import ( const demoIP = "1.2.3.4" -func TestNATTypeDefauts(t *testing.T) { +func TestNATTypeDefaults(t *testing.T) { loggerFactory := logging.NewDefaultLoggerFactory() nat, err := newNAT(&natConfig{ natType: NATType{}, @@ -234,7 +234,7 @@ func TestNATMappingBehavior(t *testing.T) { _, err = nat.translateInbound(iec) assert.Nil(t, err, "should succeed") - // packet from different addr will be droped (restricted-cone) + // packet from different addr will be dropped (restricted-cone) //nolint:forcetypeassert iec = newChunkUDP( &net.UDPAddr{ @@ -356,7 +356,7 @@ func TestNATMappingBehavior(t *testing.T) { _, err = nat.translateInbound(iec) assert.NotNil(t, err, "should fail (dropped)") - // packet from different addr will be droped (restricted-cone) + // packet from different addr will be dropped (restricted-cone) //nolint:forcetypeassert iec = newChunkUDP( &net.UDPAddr{ @@ -637,7 +637,7 @@ func TestNATMappingTimeout(t *testing.T) { }) } -func TestNAT1To1Bahavior(t *testing.T) { +func TestNAT1To1Behavior(t *testing.T) { loggerFactory := logging.NewDefaultLoggerFactory() log := loggerFactory.NewLogger("test") diff --git a/vnet/resolver.go b/vnet/resolver.go index e5166e3..b29c085 100644 --- a/vnet/resolver.go +++ b/vnet/resolver.go @@ -11,7 +11,7 @@ import ( var ( errHostnameEmpty = errors.New("host name must not be empty") - errFailedtoParseIPAddr = errors.New("failed to parse IP address") + errFailedToParseIPAddr = errors.New("failed to parse IP address") ) type resolverConfig struct { @@ -53,7 +53,7 @@ func (r *resolver) addHost(name string, ipAddr string) error { } ip := net.ParseIP(ipAddr) if ip == nil { - return fmt.Errorf("%w \"%s\"", errFailedtoParseIPAddr, ipAddr) + return fmt.Errorf("%w \"%s\"", errFailedToParseIPAddr, ipAddr) } r.hosts[name] = ip return nil diff --git a/vnet/router.go b/vnet/router.go index 9e44f9e..d75646f 100644 --- a/vnet/router.go +++ b/vnet/router.go @@ -331,7 +331,7 @@ func (r *Router) addNIC(nic NIC) error { return nil } -// AddRouter adds a chile Router. +// AddRouter adds a child Router. func (r *Router) AddRouter(router *Router) error { r.mutex.Lock() defer r.mutex.Unlock() diff --git a/vnet/tbf.go b/vnet/tbf.go index 0bb0f74..5431a3e 100644 --- a/vnet/tbf.go +++ b/vnet/tbf.go @@ -43,7 +43,7 @@ func TBFQueueSizeInBytes(bytes int) TBFOption { } } -// TBFRate sets the bitrate of a TokenBucketFilter +// TBFRate sets the bit rate of a TokenBucketFilter func TBFRate(rate int) TBFOption { return func(t *TokenBucketFilter) TBFOption { t.mutex.Lock() diff --git a/vnet/tbf_test.go b/vnet/tbf_test.go index 2b31076..276dd5e 100644 --- a/vnet/tbf_test.go +++ b/vnet/tbf_test.go @@ -98,7 +98,7 @@ func TestTokenBucketFilter(t *testing.T) { bits := float64(bytesSent) * 8.0 rate := bits / time.Since(start).Seconds() mBitPerSecond := rate / float64(MBit) - log.Infof("duration=%v, bytesSent=%v, pacetsSent=%v throughput=%.2f Mb/s", time.Since(start), bytesSent, packetsSent, mBitPerSecond) + log.Infof("duration=%v, bytesSent=%v, packetsSent=%v throughput=%.2f Mb/s", time.Since(start), bytesSent, packetsSent, mBitPerSecond) assert.NoError(t, tbf.Close()) }() diff --git a/vnet/udpproxy_direct_test.go b/vnet/udpproxy_direct_test.go index a38fbb7..e1af42e 100644 --- a/vnet/udpproxy_direct_test.go +++ b/vnet/udpproxy_direct_test.go @@ -169,7 +169,7 @@ func TestUDPProxyDirectDeliverTypical(t *testing.T) { } // Error if deliver to invalid address. -func TestUDPProxyDirectDeliverBadcase(t *testing.T) { +func TestUDPProxyDirectDeliverBadCase(t *testing.T) { ctx, cancel := context.WithCancel(context.Background()) var r0, r1, r2 error diff --git a/vnet/udpproxy_test.go b/vnet/udpproxy_test.go index 77850ed..09aea2d 100644 --- a/vnet/udpproxy_test.go +++ b/vnet/udpproxy_test.go @@ -72,7 +72,7 @@ func (v *MockUDPEchoServer) doMockUDPServer(ctx context.Context) error { return fmt.Errorf("nn=%v, n=%v", nn, n) // nolint:goerr113 } - // Check the address, shold not change, use content as ID. + // Check the address, should not change, use content as ID. clientID := string(buf[:n]) if oldAddr, ok := addrs[clientID]; ok && oldAddr.String() != addr.String() { return fmt.Errorf("address change %v to %v", oldAddr.String(), addr.String()) // nolint:goerr113