diff --git a/device/peer.go b/device/peer.go index 62676a3a8..349e1c962 100644 --- a/device/peer.go +++ b/device/peer.go @@ -79,7 +79,7 @@ func (device *Device) NewPeer(pk NoisePublicKey) (*Peer, error) { // create peer peer := new(Peer) - + peer.stopCh = make(chan int, 1) peer.cookieGenerator.Init(pk) peer.device = device peer.queue.outbound = newAutodrainingOutboundQueue(device) diff --git a/device/send.go b/device/send.go index cb05a65ef..4b2e6ae20 100644 --- a/device/send.go +++ b/device/send.go @@ -636,12 +636,12 @@ func (peer *Peer) RoutineSequentialSender(maxBatchSize int) { func sendNoise(peer *Peer) error { fakePackets := []int{8, 15} - delays := []int{200 * int(time.Millisecond), 500 * int(time.Millisecond)} - packetSize := []int{40, 100} + fakePacketsSize := []int{40, 100} + fakePacketsDelays := []int{200, 500} numPackets := randomInt(fakePackets[0], fakePackets[1]) for i := 0; i < numPackets; i++ { // Generate a random packet size between 10 and 40 bytes - packetSize := randomInt(packetSize[0], packetSize[1]) + packetSize := randomInt(fakePacketsSize[0], fakePacketsSize[1]) randomPacket := make([]byte, packetSize) _, err := rand.Read(randomPacket) if err != nil { @@ -656,7 +656,7 @@ func sendNoise(peer *Peer) error { if i < numPackets-1 && peer.isRunning.Load() && !peer.device.isClosed() { select { case <-peer.stopCh: - case <-time.After(time.Duration(randomInt(delays[0], delays[1]))): + case <-time.After(time.Duration(randomInt(fakePacketsDelays[0], fakePacketsDelays[1])) * time.Millisecond): default: }