(node state.NodeId)
| 344 | } |
| 345 | |
| 346 | func (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 | |
| 392 | func (i *InMemoryNetwork) Tun(node state.NodeId) tun.Device { |
| 393 | i.Lock() |
nothing calls this directly
no test coverage detected