blackhole6 bool
ipv4PC *ipv4.PacketConn
ipv6PC *ipv6.PacketConn
- batchSize int
udpAddrPool sync.Pool
ipv4MsgsPool sync.Pool
ipv6MsgsPool sync.Pool
}
-func NewStdNetBind() Bind { return NewStdNetBindBatch(DefaultBatchSize) }
-
-func NewStdNetBindBatch(maxBatchSize int) Bind {
- if maxBatchSize == 0 {
- maxBatchSize = DefaultBatchSize
- }
+func NewStdNetBind() Bind {
return &StdNetBind{
- batchSize: maxBatchSize,
-
udpAddrPool: sync.Pool{
New: func() any {
return &net.UDPAddr{
ipv4MsgsPool: sync.Pool{
New: func() any {
- msgs := make([]ipv4.Message, maxBatchSize)
+ msgs := make([]ipv4.Message, IdealBatchSize)
for i := range msgs {
msgs[i].Buffers = make(net.Buffers, 1)
msgs[i].OOB = make([]byte, srcControlSize)
ipv6MsgsPool: sync.Pool{
New: func() any {
- msgs := make([]ipv6.Message, maxBatchSize)
+ msgs := make([]ipv6.Message, IdealBatchSize)
for i := range msgs {
msgs[i].Buffers = make(net.Buffers, 1)
msgs[i].OOB = make([]byte, srcControlSize)
return numMsgs, nil
}
+// TODO: When all Binds handle IdealBatchSize, remove this dynamic function and
+// rename the IdealBatchSize constant to BatchSize.
func (s *StdNetBind) BatchSize() int {
- return s.batchSize
+ return IdealBatchSize
}
func (s *StdNetBind) Close() error {
return nil
}
+// TODO: When all Binds handle IdealBatchSize, remove this dynamic function and
+// rename the IdealBatchSize constant to BatchSize.
func (bind *WinRingBind) BatchSize() int {
// TODO: implement batching in and out of the ring
return 1
)
const (
- DefaultBatchSize = 128 // maximum number of packets handled per read and write
+ IdealBatchSize = 128 // maximum number of packets handled per read and write
)
// A ReceiveFunc receives at least one packet from the network and writes them
/* Reduce memory consumption for Android */
const (
- QueueStagedSize = conn.DefaultBatchSize
+ QueueStagedSize = conn.IdealBatchSize
QueueOutboundSize = 1024
QueueInboundSize = 1024
QueueHandshakeSize = 1024
import "golang.zx2c4.com/wireguard/conn"
const (
- QueueStagedSize = conn.DefaultBatchSize
+ QueueStagedSize = conn.IdealBatchSize
QueueOutboundSize = 1024
QueueInboundSize = 1024
QueueHandshakeSize = 1024
func newTCPGROTable() *tcpGROTable {
t := &tcpGROTable{
- itemsByFlow: make(map[flowKey][]tcpGROItem, conn.DefaultBatchSize),
- itemsPool: make([][]tcpGROItem, conn.DefaultBatchSize),
+ itemsByFlow: make(map[flowKey][]tcpGROItem, conn.IdealBatchSize),
+ itemsPool: make([][]tcpGROItem, conn.IdealBatchSize),
}
for i := range t.itemsPool {
- t.itemsPool[i] = make([]tcpGROItem, 0, conn.DefaultBatchSize)
+ t.itemsPool[i] = make([]tcpGROItem, 0, conn.IdealBatchSize)
}
return t
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
- out := make([][]byte, conn.DefaultBatchSize)
- sizes := make([]int, conn.DefaultBatchSize)
+ out := make([][]byte, conn.IdealBatchSize)
+ sizes := make([]int, conn.IdealBatchSize)
for i := range out {
out[i] = make([]byte, 65535)
}
return
}
tun.vnetHdr = true
- tun.batchSize = conn.DefaultBatchSize
+ tun.batchSize = conn.IdealBatchSize
} else {
tun.batchSize = 1
}
statusListenersShutdown: make(chan struct{}),
tcp4GROTable: newTCPGROTable(),
tcp6GROTable: newTCPGROTable(),
- toWrite: make([]int, 0, conn.DefaultBatchSize),
+ toWrite: make([]int, 0, conn.IdealBatchSize),
}
name, err := tun.Name()
errors: make(chan error, 5),
tcp4GROTable: newTCPGROTable(),
tcp6GROTable: newTCPGROTable(),
- toWrite: make([]int, 0, conn.DefaultBatchSize),
+ toWrite: make([]int, 0, conn.IdealBatchSize),
}
name, err := tun.Name()
if err != nil {