}
queue struct {
+ sync.RWMutex
nonce chan *QueueOutboundElement // nonce / pre-handshake queue
outbound chan *QueueOutboundElement // sequential ordering of work
inbound chan *QueueInboundElement // sequential ordering of work
peer.routines.stopping.Add(PeerRoutineNumber)
// prepare queues
-
+ peer.queue.Lock()
peer.queue.nonce = make(chan *QueueOutboundElement, QueueOutboundSize)
peer.queue.outbound = make(chan *QueueOutboundElement, QueueOutboundSize)
peer.queue.inbound = make(chan *QueueInboundElement, QueueInboundSize)
+ peer.queue.Unlock()
peer.timersInit()
peer.handshake.lastSentHandshake = time.Now().Add(-(RekeyTimeout + time.Second))
// close queues
+ peer.queue.Lock()
close(peer.queue.nonce)
close(peer.queue.outbound)
close(peer.queue.inbound)
+ peer.queue.Unlock()
peer.ZeroAndFlushAll()
}
// add to decryption queues
+ peer.queue.RLock()
if peer.isRunning.Get() {
if device.addToInboundAndDecryptionQueues(peer.queue.inbound, device.queue.decryption, elem) {
buffer = device.GetMessageBuffer()
}
}
+ peer.queue.RUnlock()
continue
/* Queues a keepalive if no packets are queued for peer
*/
func (peer *Peer) SendKeepalive() bool {
+ peer.queue.RLock()
+ defer peer.queue.RUnlock()
if len(peer.queue.nonce) != 0 || peer.queue.packetInNonceQueueIsAwaitingKey.Get() || !peer.isRunning.Get() {
return false
}
// insert into nonce/pre-handshake queue
+ peer.queue.RLock()
if peer.isRunning.Get() {
if peer.queue.packetInNonceQueueIsAwaitingKey.Get() {
peer.SendHandshakeInitiation(false)
addToNonceQueue(peer.queue.nonce, elem, device)
elem = nil
}
+ peer.queue.RUnlock()
}
}