diff options
Diffstat (limited to 'device/keypair.go')
-rw-r--r-- | device/keypair.go | 12 |
1 files changed, 11 insertions, 1 deletions
diff --git a/device/keypair.go b/device/keypair.go index 9c78fa9..63fe506 100644 --- a/device/keypair.go +++ b/device/keypair.go @@ -8,7 +8,9 @@ package device import ( "crypto/cipher" "sync" + "sync/atomic" "time" + "unsafe" "golang.zx2c4.com/wireguard/replay" ) @@ -35,7 +37,15 @@ type Keypairs struct { sync.RWMutex current *Keypair previous *Keypair - next *Keypair + next unsafe.Pointer // *Keypair, access via LoadNext/StoreNext +} + +func (kp *Keypairs) StoreNext(next *Keypair) { + atomic.StorePointer(&kp.next, (unsafe.Pointer)(next)) +} + +func (kp *Keypairs) LoadNext() *Keypair { + return (*Keypair)(atomic.LoadPointer(&kp.next)) } func (kp *Keypairs) Current() *Keypair { |