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

chat with rendezvous #2880

Open
sekomer opened this issue Jul 21, 2024 · 2 comments
Open

chat with rendezvous #2880

sekomer opened this issue Jul 21, 2024 · 2 comments

Comments

@sekomer
Copy link

sekomer commented Jul 21, 2024

hi, im trying to build a toy blockchain to learn fundamentals. I want to use libp2p for communicating nodes. (I tried couple of things, correct me if I tell anything wrong below)

I tried pub/sub example, but that was communicating over a relay node, peers doesn't directly communicating each other but messages coming from a single bootstrapper node.

Then I tried chat with mdns example, I could do the things I want to do using it, but then I realized I cannot use that globally, its only for LAN network.

Then I switched to chat with rendezvous example, it seems like it can solve my problem, but I cannot run the nodes, im getting the following error, immediately after starting the first node.

My question is, for my case, which examples should I rely on for communicating the nodes in my blockchain? And if its the chat with rendezvous example, how I can fix the error below :D

thanks in advance

❯ ./chat -listen /ip4/127.0.0.1/tcp/6660
2024-07-21T10:39:52.993+0300    INFO    rendezvous      chat-with-rendezvous/chat.go:105    Host created. We are:12D3KooWBQ7KY3cVKWkD2RipSnjvyRCLG9K9AnbWGgG1SXvn7JQp
2024-07-21T10:39:52.994+0300    INFO    rendezvous      chat-with-rendezvous/chat.go:106    [/ip4/127.0.0.1/tcp/6660]
2024-07-21T10:39:52.995+0300    WARN    dht/RtRefreshManager    rtrefresh/rt_refresh_manager.go:187  failed when refreshing routing table2 errors occurred:
        * failed to query for self, err=failed to find any peer in table
        * failed to refresh cpl=0, err=failed to find any peer in table


2024-07-21T10:39:53.995+0300    INFO    rendezvous      chat-with-rendezvous/chat.go:139    Announcing ourselves...
2024-07-21T10:39:54.881+0300    WARN    rendezvous      chat-with-rendezvous/chat.go:162    Connection failed:failed to dial: failed to dial 12D3KooWHd3ChdBbiz3QWia88aqKAU96frBUe9oG9ZFisVG43sxg: all dials failed
  * [/ip4/127.0.0.1/tcp/6666] dial tcp4 127.0.0.1:6666: connect: connection refused
2024-07-21T10:39:54.882+0300    WARN    rendezvous      chat-with-rendezvous/chat.go:162    Connection failed:failed to dial: failed to dial 12D3KooWKuEHWABqirJckwjEEYFEovNn8jXGWcM48Q4BRtkwUxH3: all dials failed
  * [/ip4/127.0.0.1/tcp/6661] dial tcp4 127.0.0.1:6661: connect: connection refused
2024-07-21T10:39:54.883+0300    WARN    rendezvous      chat-with-rendezvous/chat.go:162    Connection failed:failed to dial: failed to dial 12D3KooWNLF2ymqWj8vPf2MqJS7DYyJYRFBCdUz1SoYUVnXKtpT9: all dials failed
  * [/ip4/127.0.0.1/tcp/6666] dial tcp4 127.0.0.1:6666: connect: connection refused
2024-07-21T10:39:54.885+0300    WARN    rendezvous      chat-with-rendezvous/chat.go:162    Connection failed:failed to dial: failed to dial 12D3KooWEcWgbFQUK649kU99dPkTtFUhpfr7aqKQUa5sFHE7UDzR: all dials failed
  * [/ip4/127.0.0.1/tcp/6668] failed to negotiate security protocol: peer id mismatch: expected 12D3KooWEcWgbFQUK649kU99dPkTtFUhpfr7aqKQUa5sFHE7UDzR, but remote key matches 12D3KooWPgMWkfKuVF8uzpJKsYqpMozXN6HXzibtHV7KVmdD8z2W
2024-07-21T10:39:55.665+0300    WARN    net/identify    identify/id.go:434      failed to identify 12D3KooWRAchpsWrf4wwpRH7xHgB3HFgWFxz8xc8PcPfMbNJXrj3: Application error 0x1 (remote): conn-161376243: system: cannot reserve inbound connection: resource limit exceeded
2024-07-21T10:39:55.954+0300
@iGwkang
Copy link

iGwkang commented Jul 22, 2024

Hi,
This example uses the default guide node, and the default bootstrap node seems to be unable to connect, which requires self built bootstrap nodes.
This is my example code:

	prvKey, _, err := crypto.GenerateKeyPairWithReader(crypto.RSA, 2048, rand.Reader)
	if err != nil {
		log.Println(err)
		return
	}

	relay1, err := libp2p.New(libp2p.Identity(prvKey), libp2p.ListenAddrStrings("/ip4/0.0.0.0/tcp/9876", "/ip4/0.0.0.0/udp/9876/quic-v1"))
	if err != nil {
		log.Printf("Failed to create relay1: %v", err)
		return
	}

	_, err = relay.New(relay1)
	if err != nil {
		log.Printf("Failed to instantiate the relay: %v", err)
		return
	}
	_, err = dht.New(context.Background(), relay1, dht.Mode(dht.ModeServer)) //
	if err != nil {
		log.Printf("Failed to create DHT: %v", err)
		return
	}
	fmt.Printf("[*] Your Bootstrap ID Is: /ip4/%s/tcp/%v/p2p/%s\n", "0.0.0.0", 9876, relay1.ID().String())

You can specify the bootstrap node by specifying the -peer parameter.
But I found that this example is not have holepunching, even if the EnableHolePunching is added, it will not take effect.
That's what I've been exploring, I'm not sure at the moment why the hole punching isn't working.
#2878
#2761 (comment)
#2761 (comment)

@sekomer
Copy link
Author

sekomer commented Jul 23, 2024

@iGwkang thanks buddy,

I am trying to build a blockchain, therefore each node should be behaving same, when someone wants to join the p2p network, I want each of the nodes to act as a bootstrap node, is this possible with this example and your solution after initial start of the network, and some number of peers are active?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants