Skip to content

Local connection address should not be an unspecified address #1024

@aarshkshah1992

Description

@aarshkshah1992

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 ?

Metadata

Metadata

Labels

kind/bugA bug in existing code (including security flaws)nat-traversal

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions