Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Local connection address should not be an unspecified address #1024

Closed
aarshkshah1992 opened this issue Nov 10, 2020 · 5 comments · Fixed by multiformats/go-multiaddr#135
Closed
Assignees
Labels
kind/bug A bug in existing code (including security flaws) nat-traversal

Comments

@aarshkshah1992
Copy link
Contributor

aarshkshah1992 commented Nov 10, 2020

Given a server:

	
h, err := libp2p.New(ctx, libp2p.NoListenAddrs)
	if err != nil {
		panic(err)
	}

	addr := "/ip4/0.0.0.0/tcp/2001"
	if err := h.Network().Listen(ma.StringCast(addr)); err != nil {
		panic(err)
	}

	sub, err := h.EventBus().Subscribe(new(event.EvtPeerIdentificationCompleted))
	if err != nil {
		panic(err)
	}

	for {
		select {
		case ev := <-sub.Out():
			p := ev.(event.EvtPeerIdentificationCompleted).Peer
			fmt.Println("\n Connected to a new peer")
			fmt.Println("Local addr is", h.Network().ConnsToPeer(p)[0].LocalMultiaddr())
			fmt.Println("Remote Addr is", h.Network().ConnsToPeer(p)[0].RemoteMultiaddr())
		}
	}
}

and then the client code:

func main() {
	ctx := context.Background()

	h, err := libp2p.New(ctx, libp2p.NoListenAddrs)
	if err != nil {
		panic(err)
	}
	sub, err := h.EventBus().Subscribe(new(event.EvtPeerIdentificationCompleted))
	if err != nil {
		panic(err)
	}

	addr := ma.StringCast("/ip4/127.0.0.1/tcp/2001")

	id, err := peer.Decode("QmejUXakpXeDLWjfFkjRGJVQv8RqVuFBCikPyeSUmzixWu")
	if err != nil {
		panic(err)
	}

       h .Connect(ctx, peer.AddrInfo{ID: id, Addrs: []ma.Multiaddr{addr}})

the LocalAddr for the connection on the server i.e. h.Network().ConnsToPeer(p)[0].LocalMultiaddr() shows up as:

Local addr is /ip4/0.0.0.0/tcp/2001

Shouldn't it be /ip4/127.0.0.1/tcp/2001 since the loopback interface would have accepted the connection here ?

@aarshkshah1992 aarshkshah1992 added kind/bug A bug in existing code (including security flaws) nat-traversal labels Nov 10, 2020
@aarshkshah1992 aarshkshah1992 self-assigned this Nov 10, 2020
@aarshkshah1992
Copy link
Contributor Author

cc @Stebalien Any thoughts ?

@Stebalien
Copy link
Member

It should be automatically resolved, I'm not sure why that's not happening. I do know that QUICK had some problems with that because it doesn't have real connections, but I believe we solved that by looking up the relevant routes.

@aarshkshah1992
Copy link
Contributor Author

@marten-seemann Do you see a similar problem in QUIC ?

@Stebalien
Copy link
Member

Issue is libp2p/go-libp2p-quic-transport#123 (which has been fixed).

@aarshkshah1992
Copy link
Contributor Author

I think only TCP suffers from this then. I'lll take a look and get back to this. But. this needs to be fixed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/bug A bug in existing code (including security flaws) nat-traversal
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants