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

Method BindUpdate

polyamide/device/device.go:490–548  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

488}
489
490func (device *Device) BindUpdate() error {
491 device.net.Lock()
492 defer device.net.Unlock()
493
494 // close existing sockets
495 if err := closeBindLocked(device); err != nil {
496 return err
497 }
498
499 // open new sockets
500 if !device.isUp() {
501 return nil
502 }
503
504 // bind to new port
505 var err error
506 var recvFns []conn.ReceiveFunc
507 netc := &device.net
508
509 recvFns, netc.port, err = netc.bind.Open(netc.port)
510 if err != nil {
511 netc.port = 0
512 return err
513 }
514
515 netc.netlinkCancel, err = device.startRouteListener(netc.bind)
516 if err != nil {
517 netc.bind.Close()
518 netc.port = 0
519 return err
520 }
521
522 // set fwmark
523 if netc.fwmark != 0 {
524 err = netc.bind.SetMark(netc.fwmark)
525 if err != nil {
526 return err
527 }
528 }
529
530 // clear cached source addresses
531 device.peers.RLock()
532 for _, peer := range device.peers.keyMap {
533 peer.markEndpointSrcForClearing()
534 }
535 device.peers.RUnlock()
536
537 // start receiving routines
538 device.net.stopping.Add(len(recvFns))
539 device.queue.decryption.wg.Add(len(recvFns)) // each RoutineReceiveIncoming goroutine writes to device.queue.decryption
540 device.queue.handshake.wg.Add(len(recvFns)) // each RoutineReceiveIncoming goroutine writes to device.queue.handshake
541 batchSize := netc.bind.BatchSize()
542 for _, fn := range recvFns {
543 go device.RoutineReceiveIncoming(batchSize, fn)
544 }
545
546 device.Log.Verbosef("UDP bind has been updated")
547 return nil

Callers 3

upLockedMethod · 0.95
handleDeviceLineMethod · 0.95
TestConcurrencySafetyFunction · 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 9

isUpMethod · 0.95
startRouteListenerMethod · 0.95
closeBindLockedFunction · 0.85
OpenMethod · 0.65
CloseMethod · 0.65
SetMarkMethod · 0.65
BatchSizeMethod · 0.65

Tested by 1

TestConcurrencySafetyFunction · 0.64