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

Method Tun

integration/harness.go:392–433  ·  view source on GitHub ↗
(node state.NodeId)

Source from the content-addressed store, hash-verified

390}
391
392func (i *InMemoryNetwork) Tun(node state.NodeId) tun.Device {
393 i.Lock()
394 defer i.Unlock()
395 const (
396 ipv4Size = 20
397 )
398 bt := tuntest.NewChannelTUN()
399
400 numId := slices.IndexFunc(i.cfg.Central.Routers, func(cfg state.RouterCfg) bool {
401 return cfg.Id == node
402 })
403
404 i.virtTun[numId] = bt
405 go func() {
406 i.WaitForReady()
407 for {
408 select {
409 case <-i.cfg.Context.Done():
410 return
411 case pkt := <-bt.Inbound:
412 // wireguard doesn't actually verify checksum for ip
413 ip := pkt[0:ipv4Size]
414 if pkt[0]>>4 != 4 {
415 panic("unexpected packet, not ipv4")
416 }
417 var src, dst netip.Addr
418 err := src.UnmarshalBinary(ip[12:16])
419 if err != nil {
420 panic(err)
421 }
422 err = dst.UnmarshalBinary(ip[16:20])
423 if err != nil {
424 panic(err)
425 }
426 if !i.virtualRouteTable(node, src, dst, pkt[ipv4Size:], pkt) {
427 panic(fmt.Sprintf("unhandled packet src: %v, dst: %v", src, dst))
428 }
429 }
430 }
431 }()
432 return bt.TUN()
433}
434
435func (i *InMemoryNetwork) Send(node state.NodeId, src, dst string, pkt []byte, ttl byte) {
436 const (

Callers

nothing calls this directly

Calls 4

WaitForReadyMethod · 0.95
virtualRouteTableMethod · 0.95
TUNMethod · 0.95
NewChannelTUNFunction · 0.92

Tested by

no test coverage detected