mirror of
https://github.com/kubenetworks/kubevpn.git
synced 2025-12-24 11:51:13 +08:00
70 lines
1.4 KiB
Go
70 lines
1.4 KiB
Go
package util
|
|
|
|
import (
|
|
"net"
|
|
"sync"
|
|
"time"
|
|
)
|
|
|
|
const TrafficManager = "kubevpn.traffic.manager"
|
|
|
|
var CIDR *net.IPNet
|
|
var RouterIP net.IP
|
|
|
|
const (
|
|
s = "223.254.254.100/24"
|
|
)
|
|
|
|
func init() {
|
|
RouterIP, CIDR, _ = net.ParseCIDR(s)
|
|
}
|
|
|
|
// Debug is a flag that enables the debug log.
|
|
var Debug bool
|
|
|
|
var (
|
|
smallBufferSize = 2 * 1024 // 2KB small buffer
|
|
mediumBufferSize = 8 * 1024 // 8KB medium buffer
|
|
largeBufferSize = 32 * 1024 // 32KB large buffer
|
|
)
|
|
|
|
var (
|
|
SPool = sync.Pool{
|
|
New: func() interface{} {
|
|
return make([]byte, smallBufferSize)
|
|
},
|
|
}
|
|
MPool = sync.Pool{
|
|
New: func() interface{} {
|
|
return make([]byte, mediumBufferSize)
|
|
},
|
|
}
|
|
LPool = sync.Pool{
|
|
New: func() interface{} {
|
|
return make([]byte, largeBufferSize)
|
|
},
|
|
}
|
|
)
|
|
|
|
var (
|
|
// KeepAliveTime is the keep alive time period for TCP connection.
|
|
KeepAliveTime = 180 * time.Second
|
|
// DialTimeout is the timeout of dial.
|
|
DialTimeout = 15 * time.Second
|
|
// HandshakeTimeout is the timeout of handshake.
|
|
HandshakeTimeout = 5 * time.Second
|
|
// ConnectTimeout is the timeout for connect.
|
|
ConnectTimeout = 5 * time.Second
|
|
// ReadTimeout is the timeout for reading.
|
|
ReadTimeout = 10 * time.Second
|
|
// WriteTimeout is the timeout for writing.
|
|
WriteTimeout = 10 * time.Second
|
|
)
|
|
|
|
var (
|
|
// network layer ip needs 20 bytes
|
|
// transport layer UDP header needs 8 bytes
|
|
// UDP over TCP header needs 22 bytes
|
|
DefaultMTU = 1500 - 20 - 8 - 21
|
|
)
|