Closed jclab-joseph closed 1 year ago
InMemoryDatastore
you use, mind sharing the code you use?It is the same even if you use Level-DB.
package main
import (
"context"
"encoding/hex"
"github.com/ipfs/go-cid"
leveldb "github.com/ipfs/go-ds-leveldb"
blockstore "github.com/ipfs/go-ipfs-blockstore"
format "github.com/ipfs/go-ipld-format"
"github.com/libp2p/go-libp2p/core/crypto"
"github.com/libp2p/go-libp2p/core/peer"
"github.com/multiformats/go-multiaddr"
"log"
"os"
"path/filepath"
"time"
)
func main() {
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
ds, err := leveldb.NewDatastore("./datastore/", nil)
if err != nil {
log.Fatalln(err)
}
priv, _, err := crypto.GenerateKeyPair(crypto.Ed25519, 0)
if err != nil {
panic(err)
}
listen, _ := multiaddr.NewMultiaddr("/ip4/0.0.0.0/tcp/12345")
psk, _ := hex.DecodeString("...")
h, dht, err := ipfslite.SetupLibp2p(
ctx,
priv,
psk,
[]multiaddr.Multiaddr{listen},
ds,
nil,
nil,
ipfslite.Libp2pOptionsExtra...,
)
if err != nil {
panic(err)
}
lite, err := ipfslite.New(ctx, ds, nil, h, dht, &ipfslite.Config{
//UncachedBlockstore: false,
})
if err != nil {
panic(err)
}
lite.Bootstrap([]peer.AddrInfo{
// ...
})
println("bootstrap end")
go func() {
peerStore := h.Peerstore()
for {
peerIds := peerStore.Peers()
for i, peerId := range peerIds {
peerInfo := peerStore.PeerInfo(peerId)
encoded, err := peerInfo.MarshalJSON()
if err == nil {
log.Printf("PEER[%d]: %s: %s\n", i, peerId.String(), string(encoded))
}
}
log.Printf("-----------")
time.Sleep(time.Second * 1)
}
}()
// It takes an long time on the next line.
c, _ := cid.Decode("QmW6S34r12rr6DCSfVS24jCjx4zagtQvhFmsWS2FV32Gtm")
node, err := lite.Get(ctx, c)
if err != nil {
log.Fatalln(err)
}
}
I have discovered one thing. If you bootstrap with TCP Peer, it will be received normally and quickly. However, bootstrapping with Websocket Peer causes the same problem.
In more detail, the websocket bootstrap node is behind nginx-ingress. Therefore, the Advertise Address and the actual connection address are different.
This was my mistake. The cause was that the ipfs-cluster was configured incorrectly and the pin was not pinned.
Client has only one Bootstrap node connected to it. Interestingly, even if the PeerId is different, the CID requested from the same IP is quickly received. (Block is not stored locally, I used InMemoryDatastore.)
In the log below QmZe65rbJhncNTmaCXMq54FRG69hgJZodyorLKVmBCX2Sx is taking very long. However, the CID can be immediately obtained from the bootstrap node.
Bootstrap node's swarm streams:
Similar Possible Issues: https://github.com/ipfs/kubo/issues/8346
Bootstrap Node:
ipfs version 0.19.2
Client:github.com/ipfs/boxo v0.8.0