| 208 | } |
| 209 | |
| 210 | func (peer *Peer) Start() { |
| 211 | // should never start a peer on a closed device |
| 212 | if peer.device.isClosed() { |
| 213 | return |
| 214 | } |
| 215 | |
| 216 | // prevent simultaneous start/stop operations |
| 217 | peer.state.Lock() |
| 218 | defer peer.state.Unlock() |
| 219 | |
| 220 | if peer.isRunning.Load() { |
| 221 | return |
| 222 | } |
| 223 | |
| 224 | device := peer.device |
| 225 | device.Log.Verbosef("%v - Starting", peer) |
| 226 | |
| 227 | // reset routine state |
| 228 | peer.stopping.Wait() |
| 229 | peer.stopping.Add(2) |
| 230 | |
| 231 | peer.handshake.mutex.Lock() |
| 232 | peer.handshake.lastSentHandshake = time.Now().Add(-(RekeyTimeout + time.Second)) |
| 233 | peer.handshake.mutex.Unlock() |
| 234 | |
| 235 | peer.device.queue.encryption.wg.Add(1) // keep encryption queue open for our writes |
| 236 | |
| 237 | peer.timersStart() |
| 238 | |
| 239 | device.flushInboundQueue(peer.queue.inbound) |
| 240 | device.flushOutboundQueue(peer.queue.outbound) |
| 241 | |
| 242 | // Use the device batch size, not the bind batch size, as the device size is |
| 243 | // the size of the batch pools. |
| 244 | batchSize := peer.device.BatchSize() |
| 245 | go peer.RoutineSequentialSender(batchSize) |
| 246 | go peer.RoutineSequentialReceiver(batchSize) |
| 247 | |
| 248 | peer.isRunning.Store(true) |
| 249 | } |
| 250 | |
| 251 | func (peer *Peer) ZeroAndFlushAll() { |
| 252 | device := peer.device |