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

Method virtualRouteTable

integration/harness.go:289–327  ·  view source on GitHub ↗
(node state.NodeId, src, dst netip.Addr, data []byte, pkt []byte)

Source from the content-addressed store, hash-verified

287}
288
289func (i *InMemoryNetwork) virtualRouteTable(node state.NodeId, src, dst netip.Addr, data []byte, pkt []byte) bool {
290 curCfg := i.cfg.Central.GetNode(node)
291 if pkt[8] == 0 { // handle self if ttl is 0 as well
292 if i.SelfHandler.TryApply(node, src, dst, data) {
293 return true
294 }
295 }
296 for _, prefix := range curCfg.Prefixes {
297 if prefix.GetPrefix().Contains(dst) {
298 if i.SelfHandler.TryApply(node, src, dst, data) {
299 return true
300 }
301 }
302 }
303 curIdx := i.cfg.IndexOf(node)
304
305 if !i.TransitHandler.TryApply(node, src, dst, data) {
306 // default routing behaviour
307 for _, n := range i.cfg.Central.Routers {
308 if node == n.Id {
309 continue
310 }
311 for _, prefix := range n.Prefixes {
312 if prefix.GetPrefix().Contains(dst) {
313 // route to this node
314 select {
315 case i.virtTun[curIdx].Outbound <- pkt: // send back into our tun to get routed by WireGuard/Polyamide
316 return true
317 default:
318 fmt.Printf("%s's tun is not ready to accept data\n", n.Id)
319 return true
320 }
321 }
322 }
323 }
324 return false
325 }
326 return true
327}
328
329func (i *InMemoryNetwork) virtualInternet(pkt []byte, len int, from, to bindtest.ChannelEndpoint2) {
330 // simulate network conditions

Callers 1

TunMethod · 0.95

Calls 4

TryApplyMethod · 0.80
IndexOfMethod · 0.80
GetPrefixMethod · 0.65
GetNodeMethod · 0.45

Tested by

no test coverage detected