MCPcopy Create free account
hub / github.com/IceFireDB/IceFireDB / Open

Method Open

driver/ipfs/db.go:47–87  ·  view source on GitHub ↗
(path string, cfg *config.Config)

Source from the content-addressed store, hash-verified

45}
46
47func (s Store) Open(path string, cfg *config.Config) (driver.IDB, error) {
48 if err := os.MkdirAll(path, fs.ModePerm); err != nil {
49 return nil, err
50 }
51
52 db := new(DB)
53 db.path = path
54 db.cfg = &cfg.LevelDB
55
56 db.initOpts()
57
58 var err error
59 db.db, err = leveldb.OpenFile(db.path, db.opts)
60
61 if err != nil {
62 return nil, err
63 }
64 if IpfsDefaultConfig.HotCacheSize <= 0 {
65 IpfsDefaultConfig.HotCacheSize = defaultHotCacheSize
66 }
67
68 // here we use default value, later add config support
69 db.cache, err = ristretto.NewCache(&ristretto.Config{
70 MaxCost: IpfsDefaultConfig.HotCacheSize * MB,
71 NumCounters: defaultHotCacheNumCounters,
72 BufferItems: 64,
73 Metrics: true,
74 Cost: func(value any) int64 {
75 return int64(len(value.([]byte)))
76 },
77 })
78
79 if err != nil {
80 return nil, err
81 }
82
83 sh := shell.NewShell(IpfsDefaultConfig.EndPointConnection)
84 db.remoteShell = sh
85
86 return db, nil
87}
88
89func (s Store) Repair(path string, cfg *config.Config) error {
90 db, err := leveldb.RecoverFile(path, newOptions(&cfg.LevelDB))

Callers 1

decryptFunction · 0.45

Calls 1

initOptsMethod · 0.45

Tested by

no test coverage detected