Hi,
I am under Macosx, behind a firewall (that doesn’t provide upnp), and I would like to create an app (in golang), that start a libp2p node, and is able to publish an IPNS record.
I tried 2 approaches (using kadDHT.PutValue, and using namesys API), but both are stuck when trying to PutValue/Publish (running forever, and in the logs I see “conn-108329063: system: cannot reserve inbound connection: resource limit exceeded”, not sure if it is the root cause.
Anyway, can someone point me what I am doing wrong, or show me a piece of code how to publish an IPNS record in golang?
Here is a piece of the code I am using:
sourceMultiAddr, _ := multiaddr.NewMultiaddr("/ip4/0.0.0.0/tcp/0")
host, err := libp2p.New(
libp2p.ListenAddrs(sourceMultiAddr),
libp2p.Identity(prvKey),
libp2p.EnableRelay(), // Enable relay support
)
if err != nil {
log.Fatalf("not able create node: %v", err)
}
kadDHT, err := dht.New(ctx, host)
if err != nil {
panic("unable to start dht")
}
err = kadDHT.Bootstrap(ctx)
if err != nil {
panic("unable to bootstrap")
}
var bootstrapPeers []multiaddr.Multiaddr
for _, peerAddr := range ipfsBoostrap {
addr, err := multiaddr.NewMultiaddr(peerAddr)
if err != nil {
log.Fatalf("Failed to create multiaddr: %s", err)
}
bootstrapPeers = append(bootstrapPeers, addr)
}
// Connect to the bootstrap nodes
for _, peerAddr := range bootstrapPeers {
peerInfo, _ := peerstore.AddrInfoFromP2pAddr(peerAddr)
if err := host.Connect(ctx, *peerInfo); err != nil {
log.Printf("Failed to connect to bootstrap peer %s: %s", peerInfo.ID, err)
} else {
log.Printf("Connected to bootstrap peer %s", peerInfo.ID)
}
}
path, err := path.NewPath("/ipns/12D3KooWKbZyWQQuhwCW53UVSGxnrsRCMkpAYeuP222mLLepucqX")
if err != nil {
panic(err)
}
validity := time.Now().Add(24 * time.Hour)
sequence := uint64(1)
ttl := time.Hour
// Create IPNS entry
entry, err := ipns.NewRecord(prvKey, path, sequence, validity, ttl, ipns.WithPublicKey(true))
if err != nil {
log.Fatalf("Failed to create IPNS entry: %v", err)
}
ns, err := namesys.NewNameSystem(kadDHT)
if err != nil {
log.Fatalf("Failed to create name system: %v", err)
}
err = ns.Publish(ctx, prvKey, path)
if err != nil {
log.Fatalf("publish failed: %v", err)
}
Thank you!