// Creates a collection with a specific uniq element, used for friend collections func (this *MetaMgr) CreateSpecialCollection(owner *crypto.SecretIdentity, uniq *crypto.Digest) (cid string) { pubkey := owner.Public() cb := &collectionBasis{ Uniq: uniq, Owner: pubkey, } cid = crypto.HashOf(cb.Owner.Fingerprint(), cb.Uniq).String() existing := this.SyncMgr.Get(sync.RTBasis, cid, "$") if existing != nil { return cid } basis := &sync.Record{ RecordType: sync.RTBasis, Topic: cid, Key: "$", Author: pubkey.Fingerprint().String(), Value: transfer.AsBytes(cb), } signRecord(basis, owner) this.SyncMgr.Put(basis) owr := &sync.Record{ RecordType: sync.RTWriter, Topic: cid, Key: pubkey.Fingerprint().String(), Value: transfer.AsBytes(pubkey), } signRecord(owr, owner) this.SyncMgr.Put(owr) return }
// Writes meta-data, may fail if cid does not exist, or writer is not allowed func (this *MetaMgr) Put(cid string, writer *crypto.SecretIdentity, key string, data []byte) error { basisRec := this.SyncMgr.Get(sync.RTBasis, cid, "$") if basisRec == nil { return fmt.Errorf("Unable to write to cid '%s', doesn't exist!", cid) } myFingerprint := writer.Public().Fingerprint().String() myPerm := this.SyncMgr.Get(sync.RTWriter, cid, myFingerprint) if myPerm == nil { return fmt.Errorf("Unable to write to cid '%s', '%s' doesn't have permission", cid, myFingerprint) } old := this.SyncMgr.Get(sync.RTData, cid, key) priority := 0 if old != nil { priority = old.Priority + 1 } rec := &sync.Record{ RecordType: sync.RTData, Topic: cid, Key: key, Value: data, Priority: priority, Author: myFingerprint, } signRecord(rec, writer) if old != nil { this.doCallbacks(cid, key, old.Value, myFingerprint, false) } this.SyncMgr.Put(rec) this.doCallbacks(cid, key, data, myFingerprint, true) return nil }