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

Method RoutineHandshake

polyamide/device/receive.go:270–426  ·  view source on GitHub ↗

* Handles incoming packets related to handshake */

(id int)

Source from the content-addressed store, hash-verified

268/* Handles incoming packets related to handshake
269 */
270func (device *Device) RoutineHandshake(id int) {
271 defer func() {
272 device.Log.Verbosef("Routine: handshake worker %d - stopped", id)
273 device.queue.encryption.wg.Done()
274 }()
275 device.Log.Verbosef("Routine: handshake worker %d - started", id)
276
277 for elem := range device.queue.handshake.c {
278
279 // handle cookie fields and ratelimiting
280
281 switch elem.msgType {
282
283 case MessageCookieReplyType:
284
285 // unmarshal packet
286
287 var reply MessageCookieReply
288 err := reply.unmarshal(elem.packet)
289 if err != nil {
290 device.Log.Verbosef("Failed to decode cookie reply")
291 goto skip
292 }
293
294 // lookup peer from index
295
296 entry := device.indexTable.Lookup(reply.Receiver)
297
298 if entry.peer == nil {
299 goto skip
300 }
301
302 // consume reply
303
304 if peer := entry.peer; peer.isRunning.Load() {
305 device.Log.Verbosef("Receiving cookie response from %s", elem.endpoint.DstToString())
306 if !peer.cookieGenerator.ConsumeReply(&reply) {
307 device.Log.Verbosef("Could not decrypt invalid cookie response")
308 }
309 }
310
311 goto skip
312
313 case MessageInitiationType, MessageResponseType:
314
315 // check mac fields and maybe ratelimit
316
317 if !device.cookieChecker.CheckMAC1(elem.packet) {
318 device.Log.Verbosef("Received packet with invalid mac1")
319 goto skip
320 }
321
322 // endpoints destination address is the source of the datagram
323
324 if device.IsUnderLoad() {
325
326 // verify MAC2 field
327

Callers 1

NewDeviceFunction · 0.80

Implementers 4

NativeTunpolyamide/tun/tun_linux.go
netTunpolyamide/tun/netstack/tun.go
chTunpolyamide/tun/tuntest/tuntest.go
fakeTUNDeviceSizedpolyamide/device/device_test.go

Calls 15

unmarshalMethod · 0.95
IsUnderLoadMethod · 0.95
SendHandshakeCookieMethod · 0.95
unmarshalMethod · 0.95
PutMessageBufferMethod · 0.95
ConsumeReplyMethod · 0.80
CheckMAC1Method · 0.80
CheckMAC2Method · 0.80
AllowMethod · 0.80

Tested by

no test coverage detected