()
| 368 | } |
| 369 | |
| 370 | func (device *Device) Close() { |
| 371 | device.state.Lock() |
| 372 | defer device.state.Unlock() |
| 373 | device.ipcMutex.Lock() |
| 374 | defer device.ipcMutex.Unlock() |
| 375 | if device.isClosed() { |
| 376 | return |
| 377 | } |
| 378 | device.state.state.Store(uint32(deviceStateClosed)) |
| 379 | device.log.Verbosef("Device closing") |
| 380 | |
| 381 | device.tun.device.Close() |
| 382 | device.downLocked() |
| 383 | |
| 384 | // Remove peers before closing queues, |
| 385 | // because peers assume that queues are active. |
| 386 | device.RemoveAllPeers() |
| 387 | |
| 388 | // We kept a reference to the encryption and decryption queues, |
| 389 | // in case we started any new peers that might write to them. |
| 390 | // No new peers are coming; we are done with these queues. |
| 391 | device.queue.encryption.wg.Done() |
| 392 | device.queue.decryption.wg.Done() |
| 393 | device.queue.handshake.wg.Done() |
| 394 | device.state.stopping.Wait() |
| 395 | |
| 396 | device.rate.limiter.Close() |
| 397 | |
| 398 | device.log.Verbosef("Device closed") |
| 399 | close(device.closed) |
| 400 | } |
| 401 | |
| 402 | func (device *Device) Wait() chan struct{} { |
| 403 | return device.closed |
no test coverage detected