summaryrefslogtreecommitdiffhomepage
path: root/src/device.go
diff options
context:
space:
mode:
Diffstat (limited to 'src/device.go')
-rw-r--r--src/device.go22
1 files changed, 21 insertions, 1 deletions
diff --git a/src/device.go b/src/device.go
index b272544..a15961a 100644
--- a/src/device.go
+++ b/src/device.go
@@ -11,7 +11,11 @@ type Device struct {
log *Logger // collection of loggers for levels
idCounter uint // for assigning debug ids to peers
fwMark uint32
- net struct {
+ pool struct {
+ // pools objects for reuse
+ messageBuffers sync.Pool
+ }
+ net struct {
// seperate for performance reasons
mutex sync.RWMutex
addr *net.UDPAddr // UDP source address
@@ -57,6 +61,14 @@ func (device *Device) SetPrivateKey(sk NoisePrivateKey) {
}
}
+func (device *Device) GetMessageBuffer() *[MaxMessageSize]byte {
+ return device.pool.messageBuffers.Get().(*[MaxMessageSize]byte)
+}
+
+func (device *Device) PutMessageBuffer(msg *[MaxMessageSize]byte) {
+ device.pool.messageBuffers.Put(msg)
+}
+
func NewDevice(tun TUNDevice, logLevel int) *Device {
device := new(Device)
@@ -78,6 +90,14 @@ func NewDevice(tun TUNDevice, logLevel int) *Device {
device.net.addr, _ = net.ResolveUDPAddr(addr.Network(), addr.String())
device.net.mutex.Unlock()
+ // setup pools
+
+ device.pool.messageBuffers = sync.Pool{
+ New: func() interface{} {
+ return new([MaxMessageSize]byte)
+ },
+ }
+
// create queues
device.queue.handshake = make(chan QueueHandshakeElement, QueueHandshakeSize)