libp2p / go-libp2p

libp2p implementation in Go
MIT License
6.04k stars 1.07k forks source link

transport: add in memory transport #2293

Open p-shahi opened 1 year ago

p-shahi commented 1 year ago

Add an in memory transport (similar to rust-libp2p) which can be used for testing https://docs.rs/libp2p/latest/libp2p/core/transport/struct.MemoryTransport.html

sukunrt commented 1 year ago

Here is something similar that tailscale does: https://github.com/tailscale/tailscale/blob/main/tstest/natlab/natlab.go#L737

Wondertan commented 1 year ago

Do I understand correctly that this should substitute mocknet ? 😃

marten-seemann commented 1 year ago

Do I understand correctly that this should substitute mocknet ? 😃

Yes indeed. Mocknet shouldn't mock the swarm, only connections / streams.

MarcoPolo commented 1 year ago

We have a lot of open questions, so removing help wanted for now.

sukunrt commented 1 year ago

The requirement is ambiguous.

We need to decide whether we want an in memory transport for testing where we can fake IP address and possibly simulate NAT or we want to implement a /memory transport like the one implemented by rust-libp2p.

/memory is useful for testing protocols which do not depend on specific remote or local addresses but it cannot be used for testing something like AutoNATv2 without changing the /memory multiaddress intention. @mxinden is my understanding correct?

The effort required in both the cases seems similar.

mxinden commented 1 year ago

/memory is useful for testing protocols which do not depend on specific remote or local addresses but it cannot be used for testing something like AutoNATv2 without changing the /memory multiaddress intention. @mxinden is my understanding correct?

That is correct. rust-libp2p's memory transport is very simple with a single uniform address space. It does not have any more complex mechanisms, e.g. NATs.

The effort required in both the cases seems similar.

I would assume the opposite. While I think it is very simple to port rust-libp2p's MemoryTransport to go-libp2p, I expect building a Transport "where we can fake IP address and possibly simulate NAT" is much harder.

sukunrt commented 1 year ago

I expect building a Transport "where we can fake IP address and possibly simulate NAT" is much harder.

I think you're right. I'll change my stance to Building a transport where we fake IP address is a little more work than adding a /memory transport simulating NATs is a lot more work.

MarcoPolo commented 6 months ago

I think a in-memory transport without faking IP addresses or simulating NATs is still useful for testing protocols.

I think simulating NATs should be a separate task.

I'm going to readd the help wanted label since I think we have a clearer idea of what we want here. Which is essentially the equivalent of rust-libp2p's MemoryTransport

pyropy commented 2 weeks ago

Could I claim this issue? I think it would be a good intro for me to start contributing to go-libp2p

(edit: I am part of PLDG cohort 1)

MarcoPolo commented 1 week ago

go for it

pyropy commented 3 days ago

Hey @MarcoPolo could you assign issue on me and maybe refer me to someone who could take a look at this

https://github.com/multiformats/go-multiaddr/pull/256