nonce chan *QueueOutboundElement // nonce / pre-handshake queue
outbound chan *QueueOutboundElement // sequential ordering of work
inbound chan *QueueInboundElement // sequential ordering of work
- packetInNonceQueueIsAwaitingKey bool
+ packetInNonceQueueIsAwaitingKey AtomicBool
}
routines struct {
/* Queues a keepalive if no packets are queued for peer
*/
func (peer *Peer) SendKeepalive() bool {
- if len(peer.queue.nonce) != 0 || peer.queue.packetInNonceQueueIsAwaitingKey || !peer.isRunning.Get() {
+ if len(peer.queue.nonce) != 0 || peer.queue.packetInNonceQueueIsAwaitingKey.Get() || !peer.isRunning.Get() {
return false
}
elem := peer.device.NewOutboundElement()
// insert into nonce/pre-handshake queue
if peer.isRunning.Get() {
- if peer.queue.packetInNonceQueueIsAwaitingKey {
+ if peer.queue.packetInNonceQueueIsAwaitingKey.Get() {
peer.SendHandshakeInitiation(false)
}
addToOutboundQueue(peer.queue.nonce, elem)
defer func() {
logDebug.Println(peer, ": Routine: nonce worker - stopped")
- peer.queue.packetInNonceQueueIsAwaitingKey = false
+ peer.queue.packetInNonceQueueIsAwaitingKey.Set(false)
peer.routines.stopping.Done()
}()
for {
NextPacket:
- peer.queue.packetInNonceQueueIsAwaitingKey = false
+ peer.queue.packetInNonceQueueIsAwaitingKey.Set(false)
select {
case <-peer.routines.stop:
break
}
}
- peer.queue.packetInNonceQueueIsAwaitingKey = true
+ peer.queue.packetInNonceQueueIsAwaitingKey.Set(true)
// no suitable key pair, request for new handshake
return
}
}
- peer.queue.packetInNonceQueueIsAwaitingKey = false
+ peer.queue.packetInNonceQueueIsAwaitingKey.Set(false)
// populate work element