MCPcopy Create free account
hub / github.com/encodeous/nylon / Start

Method Start

polyamide/device/peer.go:210–249  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

208}
209
210func (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
251func (peer *Peer) ZeroAndFlushAll() {
252 device := peer.device

Callers 1

TestNoiseHandshakeFunction · 0.95

Calls 8

timersStartMethod · 0.95
isClosedMethod · 0.80
flushInboundQueueMethod · 0.80
flushOutboundQueueMethod · 0.80
BatchSizeMethod · 0.65
WaitMethod · 0.45

Tested by 1

TestNoiseHandshakeFunction · 0.76