device: flush peer queues before starting device
In case some old packets snuck in there before, this flushes before starting afresh. Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
This commit is contained in:
parent
5bf8d73127
commit
484a9fd324
|
@ -83,7 +83,11 @@ func newAutodrainingInboundQueue(device *Device) *autodrainingInboundQueue {
|
||||||
q := &autodrainingInboundQueue{
|
q := &autodrainingInboundQueue{
|
||||||
c: make(chan *QueueInboundElement, QueueInboundSize),
|
c: make(chan *QueueInboundElement, QueueInboundSize),
|
||||||
}
|
}
|
||||||
runtime.SetFinalizer(q, func(q *autodrainingInboundQueue) {
|
runtime.SetFinalizer(q, device.flushInboundQueue)
|
||||||
|
return q
|
||||||
|
}
|
||||||
|
|
||||||
|
func (device *Device) flushInboundQueue(q *autodrainingInboundQueue) {
|
||||||
for {
|
for {
|
||||||
select {
|
select {
|
||||||
case elem := <-q.c:
|
case elem := <-q.c:
|
||||||
|
@ -94,8 +98,6 @@ func newAutodrainingInboundQueue(device *Device) *autodrainingInboundQueue {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
})
|
|
||||||
return q
|
|
||||||
}
|
}
|
||||||
|
|
||||||
type autodrainingOutboundQueue struct {
|
type autodrainingOutboundQueue struct {
|
||||||
|
@ -111,7 +113,11 @@ func newAutodrainingOutboundQueue(device *Device) *autodrainingOutboundQueue {
|
||||||
q := &autodrainingOutboundQueue{
|
q := &autodrainingOutboundQueue{
|
||||||
c: make(chan *QueueOutboundElement, QueueOutboundSize),
|
c: make(chan *QueueOutboundElement, QueueOutboundSize),
|
||||||
}
|
}
|
||||||
runtime.SetFinalizer(q, func(q *autodrainingOutboundQueue) {
|
runtime.SetFinalizer(q, device.flushOutboundQueue)
|
||||||
|
return q
|
||||||
|
}
|
||||||
|
|
||||||
|
func (device *Device) flushOutboundQueue(q *autodrainingOutboundQueue) {
|
||||||
for {
|
for {
|
||||||
select {
|
select {
|
||||||
case elem := <-q.c:
|
case elem := <-q.c:
|
||||||
|
@ -122,6 +128,4 @@ func newAutodrainingOutboundQueue(device *Device) *autodrainingOutboundQueue {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
})
|
|
||||||
return q
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -186,6 +186,8 @@ func (peer *Peer) Start() {
|
||||||
|
|
||||||
peer.timersStart()
|
peer.timersStart()
|
||||||
|
|
||||||
|
device.flushInboundQueue(peer.queue.inbound)
|
||||||
|
device.flushOutboundQueue(peer.queue.outbound)
|
||||||
go peer.RoutineSequentialSender()
|
go peer.RoutineSequentialSender()
|
||||||
go peer.RoutineSequentialReceiver()
|
go peer.RoutineSequentialReceiver()
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue