Hi
I am programmatically initializing a ipfs Kubo core. I have managed to create a repo and set the datastore path, but the keystore seems to be separate and I cannot find how I can configure it?
func DefaultDatastoreConfig(options *badger.Options, dsPath string, storageMax string) config.Datastore {
return config.Datastore{
StorageMax: storageMax,
StorageGCWatermark: 90, // 90%
GCPeriod: "1h",
BloomFilterSize: 0,
Spec: BadgerSpec(options, dsPath),
}
}
func BadgerSpec(options *badger.Options, dsPath string) map[string]interface{} {
return map[string]interface{}{
"type": "measure",
"prefix": "badger.datastore",
"child": map[string]interface{}{
"type": "badgerds",
"path": dsPath,
"syncWrites": options.SyncWrites,
"truncate": options.Truncate,
"gcDiscardRatio": options.GcDiscardRatio,
"gcSleep": options.GcSleep.String(),
"gcInterval": options.GcInterval.String(),
},
}
}
func CreateCustomRepo(ctx context.Context, basePath string, h host.Host, options *badger.Options, dsPath string, storageMax string) (repo.Repo, error) {
// Path to the repository
repoPath := filepath.Join(basePath, "ipfs.config")
// Create the repository if it doesn't exist
plugins, err := loader.NewPluginLoader(repoPath)
if err != nil {
panic(fmt.Errorf("error loading plugins: %s", err))
}
if err := plugins.Initialize(); err != nil {
panic(fmt.Errorf("error initializing plugins: %s", err))
}
if err := plugins.Inject(); err != nil {
panic(fmt.Errorf("error initializing plugins: %s", err))
}
if !fsrepo.IsInitialized(repoPath) {
versionFilePath := filepath.Join(repoPath, "version")
versionContent := strconv.Itoa(15)
if err := os.WriteFile(versionFilePath, []byte(versionContent), 0644); err != nil {
return nil, err
}
dataStoreFilePath := filepath.Join(repoPath, "datastore_spec")
datastoreContent := map[string]interface{}{
"type": "badgerds",
"path": dsPath,
}
datastoreContentBytes, err := json.Marshal(datastoreContent)
if err != nil {
panic(err)
}
if err := os.WriteFile(dataStoreFilePath, []byte(datastoreContentBytes), 0644); err != nil {
return nil, err
}
// Extract private key and peer ID from the libp2p host
privKey := h.Peerstore().PrivKey(h.ID())
if privKey == nil {
return nil, fmt.Errorf("private key for host not found")
}
privKeyBytes, err := crypto.MarshalPrivateKey(privKey)
if err != nil {
return nil, err
}
peerID := h.ID().String()
conf := config.Config{
Identity: config.Identity{
PeerID: peerID,
PrivKey: base64.StdEncoding.EncodeToString(privKeyBytes),
},
}
// Set the custom configuration
conf.Bootstrap = append(conf.Bootstrap, app.config.StaticRelays...)
conf.Datastore = DefaultDatastoreConfig(options, dsPath, storageMax)
conf.Experimental.GraphsyncEnabled = true
conf.Addresses.Swarm = app.config.ListenAddrs
conf.Identity.PeerID = h.ID().String()
conf.Identity.PrivKey = app.config.Identity
conf.Swarm.RelayService.Enabled = 1
// Initialize the repo with the configuration
if err := fsrepo.Init(repoPath, &conf); err != nil {
return nil, err
}
}
// Open the repo
repo, err := fsrepo.Open(repoPath)
if err != nil {
return nil, err
}
return repo, nil
}