Пример #1
0
func (app *App) OpenKV(tx *db.Tx, storage *db.VolumeStorage) (kv.KV, error) {
	var kvstores []kv.KV

	c := storage.Cursor()
	for item := c.First(); item != nil; item = c.Next() {
		backend, err := item.Backend()
		if err != nil {
			return nil, err
		}
		s, err := app.openStorage(backend)
		if err != nil {
			return nil, err
		}

		sharingKeyName, err := item.SharingKeyName()
		if err != nil {
			return nil, err
		}
		sharingKey, err := tx.SharingKeys().Get(sharingKeyName)
		if err != nil {
			return nil, fmt.Errorf("getting sharing key %q: %v", sharingKeyName, err)
		}
		var secret [32]byte
		sharingKey.Secret(&secret)
		s = untrusted.New(s, &secret)

		kvstores = append(kvstores, s)
	}

	return kvmulti.New(kvstores...), nil
}
Пример #2
0
func (v *Volume) bucket(tx *db.Tx) *db.Volume {
	vv, err := tx.Volumes().GetByVolumeID(&v.volID)
	if err != nil {
		log.Printf("volume has disappeared: %v: %v", &v.volID, err)
	}
	return vv
}
Пример #3
0
func checkMakePeer(tx *db.Tx, pub *peer.PublicKey, id peer.ID) error {
	peer, err := tx.Peers().Make(pub)
	if err != nil {
		return fmt.Errorf("unexpected peers.Make error: %v", err)
	}
	if g, e := *peer.Pub(), *pub; g != e {
		return fmt.Errorf("peer pubkey came back wrong: %v != %v", g, e)
	}
	if g, e := peer.ID(), id; g != e {
		return fmt.Errorf("wrong peer ID: %v != %v", g, e)
	}
	return nil
}
Пример #4
0
// caller must hold App.volumes.Mutex
func (app *App) openVolume(tx *db.Tx, id *db.VolumeID) (*fs.Volume, error) {
	v, err := tx.Volumes().GetByVolumeID(id)
	if err != nil {
		return nil, err
	}
	kvstore, err := app.OpenKV(tx, v.Storage())
	if err != nil {
		return nil, err
	}

	chunkStore := kvchunks.New(kvstore)
	vol, err := fs.Open(app.DB, chunkStore, id, (*peer.PublicKey)(app.Keys.Sign.Pub))
	if err != nil {
		return nil, err
	}
	return vol, nil
}