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

Function TestTTL

integration/routing_test.go:72–131  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

70}
71
72func TestTTL(t *testing.T) {
73 defer goleak.VerifyNone(t)
74 vh := &VirtualHarness{}
75 vh.UntrackedRouting = true
76 a1 := "192.168.1.1:1234"
77 vh.NewNode("a", "10.0.0.1/32")
78 b1 := "192.168.1.2:1234"
79 vh.NewNode("b", "10.0.0.2/32")
80 c1 := "192.168.1.3:1234"
81 vh.NewNode("c", "10.0.0.3/32")
82 vh.Central.Graph = []string{
83 "a, b",
84 "b, c",
85 }
86 vh.Endpoints = map[string]state.NodeId{
87 a1: "a",
88 b1: "b",
89 c1: "c",
90 }
91 vh.AddLink(a1, b1)
92 vh.AddLink(b1, a1)
93 vh.AddLink(b1, c1)
94 vh.AddLink(c1, b1)
95
96 errs := vh.Start()
97
98 vn := vh.Net
99 cc := make(chan bool, 100)
100
101 vn.SelfHandler = func(node state.NodeId, src, dst netip.Addr, data []byte) bool {
102 if src.String() == "10.0.0.1" && dst.String() == "10.0.0.3" && data[0] == 222 {
103 if node == "c" {
104 panic("c is not supposed to receive this packet")
105 }
106 cc <- true
107 }
108 return true
109 }
110
111 go func() {
112 for {
113 select {
114 case <-vh.Context.Done():
115 return
116 case <-time.After(100 * time.Millisecond):
117 vn.Send("a", "10.0.0.1", "10.0.0.3", []byte{222}, 1)
118 }
119 }
120 }()
121
122 select {
123 case <-cc:
124 t.Log("Got ping!")
125 case <-time.After(10 * time.Second):
126 t.Error("Timed out waiting for ping")
127 case err := <-errs:
128 t.Error(err)
129 }

Callers

nothing calls this directly

Calls 8

NewNodeMethod · 0.95
AddLinkMethod · 0.95
StartMethod · 0.95
StopMethod · 0.95
AfterMethod · 0.80
SendMethod · 0.65
StringMethod · 0.45
ErrorMethod · 0.45

Tested by

no test coverage detected