Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions conn/batchsize_default.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
//go:build !testsmallbuffers

/* SPDX-License-Identifier: MIT
*
* Copyright (C) 2017-2023 WireGuard LLC. All Rights Reserved.
*/

package conn

const (
IdealBatchSize = 128 // maximum number of packets handled per read and write
)
16 changes: 16 additions & 0 deletions conn/batchsize_testsmall.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
//go:build testsmallbuffers

/* SPDX-License-Identifier: MIT
*
* Copyright (C) 2017-2023 WireGuard LLC. All Rights Reserved.
*
* Modified by Coder for test environments to reduce memory usage.
*/

package conn

// IdealBatchSize is reduced for tests to minimize memory usage.
// In production, this is 128 (see batchsize_default.go), but tests don't need
// the full batch capacity and this significantly reduces memory overhead
// from wireguard buffer pools (~8MB per connection down to ~256KB).
const IdealBatchSize = 4
4 changes: 0 additions & 4 deletions conn/conn.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,6 @@ import (
"strings"
)

const (
IdealBatchSize = 128 // maximum number of packets handled per read and write
)

// A ReceiveFunc receives at least one packet from the network and writes them
// into packets. On a successful read it returns the number of elements of
// sizes, packets, and endpoints that should be evaluated. Some elements of
Expand Down
2 changes: 2 additions & 0 deletions device/queueconstants_android.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
//go:build android && !testsmallbuffers

/* SPDX-License-Identifier: MIT
*
* Copyright (C) 2017-2023 WireGuard LLC. All Rights Reserved.
Expand Down
2 changes: 1 addition & 1 deletion device/queueconstants_default.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//go:build !android && !ios && !windows
//go:build !android && !ios && !windows && !testsmallbuffers

/* SPDX-License-Identifier: MIT
*
Expand Down
2 changes: 1 addition & 1 deletion device/queueconstants_ios.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//go:build ios
//go:build ios && !testsmallbuffers

/* SPDX-License-Identifier: MIT
*
Expand Down
21 changes: 21 additions & 0 deletions device/queueconstants_testsmall.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
//go:build testsmallbuffers

/* SPDX-License-Identifier: MIT
*
* Copyright (C) 2017-2023 WireGuard LLC. All Rights Reserved.
*
* Modified by Coder for test environments to reduce memory usage.
*/

package device

import "github.com/tailscale/wireguard-go/conn"

const (
QueueStagedSize = conn.IdealBatchSize
QueueOutboundSize = 64 // Reduced from 1024 for tests
QueueInboundSize = 64 // Reduced from 1024 for tests
QueueHandshakeSize = 64 // Reduced from 1024 for tests
MaxSegmentSize = 2048 // Reduced from 65535 for tests (enough for typical packets)
PreallocatedBuffersPerPool = 0 // Disable and allow for infinite memory growth
)
2 changes: 2 additions & 0 deletions device/queueconstants_windows.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
//go:build !testsmallbuffers

/* SPDX-License-Identifier: MIT
*
* Copyright (C) 2017-2023 WireGuard LLC. All Rights Reserved.
Expand Down