diff options
author | Jason A. Donenfeld <Jason@zx2c4.com> | 2023-03-13 17:55:05 +0100 |
---|---|---|
committer | Jason A. Donenfeld <Jason@zx2c4.com> | 2023-03-13 17:55:53 +0100 |
commit | 0ad14a89f5f9da577dae6a63ad196015e51a0381 (patch) | |
tree | da74ec4dd4dd79b3577236bc30b42ea999e8516b /device | |
parent | 7d327ed35aef08e2f54c12645a3002c94c6aec91 (diff) |
global: buff -> buf
This always struck me as kind of weird and non-standard.
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
Diffstat (limited to 'device')
-rw-r--r-- | device/bind_test.go | 10 | ||||
-rw-r--r-- | device/device_test.go | 16 | ||||
-rw-r--r-- | device/receive.go | 40 | ||||
-rw-r--r-- | device/send.go | 30 |
4 files changed, 48 insertions, 48 deletions
diff --git a/device/bind_test.go b/device/bind_test.go index 3cbf0ad..302a521 100644 --- a/device/bind_test.go +++ b/device/bind_test.go @@ -26,21 +26,21 @@ func (b *DummyBind) SetMark(v uint32) error { return nil } -func (b *DummyBind) ReceiveIPv6(buff []byte) (int, conn.Endpoint, error) { +func (b *DummyBind) ReceiveIPv6(buf []byte) (int, conn.Endpoint, error) { datagram, ok := <-b.in6 if !ok { return 0, nil, errors.New("closed") } - copy(buff, datagram.msg) + copy(buf, datagram.msg) return len(datagram.msg), datagram.endpoint, nil } -func (b *DummyBind) ReceiveIPv4(buff []byte) (int, conn.Endpoint, error) { +func (b *DummyBind) ReceiveIPv4(buf []byte) (int, conn.Endpoint, error) { datagram, ok := <-b.in4 if !ok { return 0, nil, errors.New("closed") } - copy(buff, datagram.msg) + copy(buf, datagram.msg) return len(datagram.msg), datagram.endpoint, nil } @@ -51,6 +51,6 @@ func (b *DummyBind) Close() error { return nil } -func (b *DummyBind) Send(buff []byte, end conn.Endpoint) error { +func (b *DummyBind) Send(buf []byte, end conn.Endpoint) error { return nil } diff --git a/device/device_test.go b/device/device_test.go index 73891bf..fff172b 100644 --- a/device/device_test.go +++ b/device/device_test.go @@ -428,7 +428,7 @@ func (b *fakeBindSized) Open(port uint16) (fns []conn.ReceiveFunc, actualPort ui } func (b *fakeBindSized) Close() error { return nil } func (b *fakeBindSized) SetMark(mark uint32) error { return nil } -func (b *fakeBindSized) Send(buffs [][]byte, ep conn.Endpoint) error { return nil } +func (b *fakeBindSized) Send(bufs [][]byte, ep conn.Endpoint) error { return nil } func (b *fakeBindSized) ParseEndpoint(s string) (conn.Endpoint, error) { return nil, nil } func (b *fakeBindSized) BatchSize() int { return b.size } @@ -437,15 +437,15 @@ type fakeTUNDeviceSized struct { } func (t *fakeTUNDeviceSized) File() *os.File { return nil } -func (t *fakeTUNDeviceSized) Read(buffs [][]byte, sizes []int, offset int) (n int, err error) { +func (t *fakeTUNDeviceSized) Read(bufs [][]byte, sizes []int, offset int) (n int, err error) { return 0, nil } -func (t *fakeTUNDeviceSized) Write(buffs [][]byte, offset int) (int, error) { return 0, nil } -func (t *fakeTUNDeviceSized) MTU() (int, error) { return 0, nil } -func (t *fakeTUNDeviceSized) Name() (string, error) { return "", nil } -func (t *fakeTUNDeviceSized) Events() <-chan tun.Event { return nil } -func (t *fakeTUNDeviceSized) Close() error { return nil } -func (t *fakeTUNDeviceSized) BatchSize() int { return t.size } +func (t *fakeTUNDeviceSized) Write(bufs [][]byte, offset int) (int, error) { return 0, nil } +func (t *fakeTUNDeviceSized) MTU() (int, error) { return 0, nil } +func (t *fakeTUNDeviceSized) Name() (string, error) { return "", nil } +func (t *fakeTUNDeviceSized) Events() <-chan tun.Event { return nil } +func (t *fakeTUNDeviceSized) Close() error { return nil } +func (t *fakeTUNDeviceSized) BatchSize() int { return t.size } func TestBatchSize(t *testing.T) { d := Device{} diff --git a/device/receive.go b/device/receive.go index aee7864..e24d29f 100644 --- a/device/receive.go +++ b/device/receive.go @@ -80,8 +80,8 @@ func (device *Device) RoutineReceiveIncoming(maxBatchSize int, recv conn.Receive // receive datagrams until conn is closed var ( - buffsArrs = make([]*[MaxMessageSize]byte, maxBatchSize) - buffs = make([][]byte, maxBatchSize) + bufsArrs = make([]*[MaxMessageSize]byte, maxBatchSize) + bufs = make([][]byte, maxBatchSize) err error sizes = make([]int, maxBatchSize) count int @@ -90,21 +90,21 @@ func (device *Device) RoutineReceiveIncoming(maxBatchSize int, recv conn.Receive elemsByPeer = make(map[*Peer]*[]*QueueInboundElement, maxBatchSize) ) - for i := range buffsArrs { - buffsArrs[i] = device.GetMessageBuffer() - buffs[i] = buffsArrs[i][:] + for i := range bufsArrs { + bufsArrs[i] = device.GetMessageBuffer() + bufs[i] = bufsArrs[i][:] } defer func() { for i := 0; i < maxBatchSize; i++ { - if buffsArrs[i] != nil { - device.PutMessageBuffer(buffsArrs[i]) + if bufsArrs[i] != nil { + device.PutMessageBuffer(bufsArrs[i]) } } }() for { - count, err = recv(buffs, sizes, endpoints) + count, err = recv(bufs, sizes, endpoints) if err != nil { if errors.Is(err, net.ErrClosed) { return @@ -130,7 +130,7 @@ func (device *Device) RoutineReceiveIncoming(maxBatchSize int, recv conn.Receive // check size of packet - packet := buffsArrs[i][:size] + packet := bufsArrs[i][:size] msgType := binary.LittleEndian.Uint32(packet[:4]) switch msgType { @@ -166,7 +166,7 @@ func (device *Device) RoutineReceiveIncoming(maxBatchSize int, recv conn.Receive peer := value.peer elem := device.GetInboundElement() elem.packet = packet - elem.buffer = buffsArrs[i] + elem.buffer = bufsArrs[i] elem.keypair = keypair elem.endpoint = endpoints[i] elem.counter = 0 @@ -179,8 +179,8 @@ func (device *Device) RoutineReceiveIncoming(maxBatchSize int, recv conn.Receive elemsByPeer[peer] = elemsForPeer } *elemsForPeer = append(*elemsForPeer, elem) - buffsArrs[i] = device.GetMessageBuffer() - buffs[i] = buffsArrs[i][:] + bufsArrs[i] = device.GetMessageBuffer() + bufs[i] = bufsArrs[i][:] continue // otherwise it is a fixed size & handshake related packet @@ -208,12 +208,12 @@ func (device *Device) RoutineReceiveIncoming(maxBatchSize int, recv conn.Receive select { case device.queue.handshake.c <- QueueHandshakeElement{ msgType: msgType, - buffer: buffsArrs[i], + buffer: bufsArrs[i], packet: packet, endpoint: endpoints[i], }: - buffsArrs[i] = device.GetMessageBuffer() - buffs[i] = buffsArrs[i][:] + bufsArrs[i] = device.GetMessageBuffer() + bufs[i] = bufsArrs[i][:] default: } } @@ -435,7 +435,7 @@ func (peer *Peer) RoutineSequentialReceiver(maxBatchSize int) { }() device.log.Verbosef("%v - Routine: sequential receiver - started", peer) - buffs := make([][]byte, 0, maxBatchSize) + bufs := make([][]byte, 0, maxBatchSize) for elems := range peer.queue.inbound.c { if elems == nil { @@ -507,10 +507,10 @@ func (peer *Peer) RoutineSequentialReceiver(maxBatchSize int) { continue } - buffs = append(buffs, elem.buffer[:MessageTransportOffsetContent+len(elem.packet)]) + bufs = append(bufs, elem.buffer[:MessageTransportOffsetContent+len(elem.packet)]) } - if len(buffs) > 0 { - _, err := device.tun.device.Write(buffs, MessageTransportOffsetContent) + if len(bufs) > 0 { + _, err := device.tun.device.Write(bufs, MessageTransportOffsetContent) if err != nil && !device.isClosed() { device.log.Errorf("Failed to write packets to TUN device: %v", err) } @@ -519,7 +519,7 @@ func (peer *Peer) RoutineSequentialReceiver(maxBatchSize int) { device.PutMessageBuffer(elem.buffer) device.PutInboundElement(elem) } - buffs = buffs[:0] + bufs = bufs[:0] device.PutInboundElementsSlice(elems) } } diff --git a/device/send.go b/device/send.go index b33b9f4..d22bf26 100644 --- a/device/send.go +++ b/device/send.go @@ -120,8 +120,8 @@ func (peer *Peer) SendHandshakeInitiation(isRetry bool) error { return err } - var buff [MessageInitiationSize]byte - writer := bytes.NewBuffer(buff[:0]) + var buf [MessageInitiationSize]byte + writer := bytes.NewBuffer(buf[:0]) binary.Write(writer, binary.LittleEndian, msg) packet := writer.Bytes() peer.cookieGenerator.AddMacs(packet) @@ -151,8 +151,8 @@ func (peer *Peer) SendHandshakeResponse() error { return err } - var buff [MessageResponseSize]byte - writer := bytes.NewBuffer(buff[:0]) + var buf [MessageResponseSize]byte + writer := bytes.NewBuffer(buf[:0]) binary.Write(writer, binary.LittleEndian, response) packet := writer.Bytes() peer.cookieGenerator.AddMacs(packet) @@ -185,8 +185,8 @@ func (device *Device) SendHandshakeCookie(initiatingElem *QueueHandshakeElement) return err } - var buff [MessageCookieReplySize]byte - writer := bytes.NewBuffer(buff[:0]) + var buf [MessageCookieReplySize]byte + writer := bytes.NewBuffer(buf[:0]) binary.Write(writer, binary.LittleEndian, reply) // TODO: allocation could be avoided device.net.bind.Send([][]byte{writer.Bytes()}, initiatingElem.endpoint) @@ -217,7 +217,7 @@ func (device *Device) RoutineReadFromTUN() { batchSize = device.BatchSize() readErr error elems = make([]*QueueOutboundElement, batchSize) - buffs = make([][]byte, batchSize) + bufs = make([][]byte, batchSize) elemsByPeer = make(map[*Peer]*[]*QueueOutboundElement, batchSize) count = 0 sizes = make([]int, batchSize) @@ -226,7 +226,7 @@ func (device *Device) RoutineReadFromTUN() { for i := range elems { elems[i] = device.NewOutboundElement() - buffs[i] = elems[i].buffer[:] + bufs[i] = elems[i].buffer[:] } defer func() { @@ -240,14 +240,14 @@ func (device *Device) RoutineReadFromTUN() { for { // read packets - count, readErr = device.tun.device.Read(buffs, sizes, offset) + count, readErr = device.tun.device.Read(bufs, sizes, offset) for i := 0; i < count; i++ { if sizes[i] < 1 { continue } elem := elems[i] - elem.packet = buffs[i][offset : offset+sizes[i]] + elem.packet = bufs[i][offset : offset+sizes[i]] // lookup peer var peer *Peer @@ -280,7 +280,7 @@ func (device *Device) RoutineReadFromTUN() { } *elemsForPeer = append(*elemsForPeer, elem) elems[i] = device.NewOutboundElement() - buffs[i] = elems[i].buffer[:] + bufs[i] = elems[i].buffer[:] } for peer, elemsForPeer := range elemsByPeer { @@ -483,10 +483,10 @@ func (peer *Peer) RoutineSequentialSender(maxBatchSize int) { }() device.log.Verbosef("%v - Routine: sequential sender - started", peer) - buffs := make([][]byte, 0, maxBatchSize) + bufs := make([][]byte, 0, maxBatchSize) for elems := range peer.queue.outbound.c { - buffs = buffs[:0] + bufs = bufs[:0] if elems == nil { return } @@ -510,13 +510,13 @@ func (peer *Peer) RoutineSequentialSender(maxBatchSize int) { if len(elem.packet) != MessageKeepaliveSize { dataSent = true } - buffs = append(buffs, elem.packet) + bufs = append(bufs, elem.packet) } peer.timersAnyAuthenticatedPacketTraversal() peer.timersAnyAuthenticatedPacketSent() - err := peer.SendBuffers(buffs) + err := peer.SendBuffers(bufs) if dataSent { peer.timersDataSent() } |