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

Method Bind

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

Source from the content-addressed store, hash-verified

344}
345
346func (i *InMemoryNetwork) Bind(node state.NodeId) conn.Bind {
347 i.Lock()
348 defer i.Unlock()
349 epSendMapping := func(to bindtest.ChannelEndpoint2) bindtest.ChannelEndpoint2 {
350 return i.EpOutMapping(node, to)
351 }
352 bp := bindtest.NewChannelBind2()
353
354 remote := bp[0] // simulate an actual port opening
355 open, _, err := remote.Open(0)
356 if err != nil {
357 return nil
358 }
359 numId := i.cfg.IndexOf(node)
360 i.binds[numId] = remote
361 go func() {
362 // bind listener routine for packets sent from this node
363 bufSize := remote.BatchSize()
364 pktBuf := make([][]byte, bufSize)
365 pktBuf[0] = make([]byte, device.MaxMessageSize)
366 lenBuf := make([]int, bufSize)
367 epBuf := make([]conn.Endpoint, bufSize)
368 i.WaitForReady()
369 for {
370 for _, recv := range open {
371 n, err := recv(pktBuf, lenBuf, epBuf)
372 if err != nil {
373 if !errors.Is(err, net.ErrClosed) {
374 panic(err)
375 }
376 return
377 }
378 for pi := range n {
379 if lenBuf[pi] == 0 {
380 continue
381 }
382 toIp := epBuf[pi].(bindtest.ChannelEndpoint2)
383 fromIp := epSendMapping(toIp)
384 i.virtualInternet(slices.Clone(pktBuf[pi]), lenBuf[pi], fromIp, toIp)
385 }
386 }
387 }
388 }()
389 return bp[1]
390}
391
392func (i *InMemoryNetwork) Tun(node state.NodeId) tun.Device {
393 i.Lock()

Callers

nothing calls this directly

Calls 7

WaitForReadyMethod · 0.95
virtualInternetMethod · 0.95
NewChannelBind2Function · 0.92
IndexOfMethod · 0.80
CloneMethod · 0.80
OpenMethod · 0.65
BatchSizeMethod · 0.65

Tested by

no test coverage detected