orbitdb / field-manual

The Offical User's Guide to OrbitDB
207 stars 43 forks source link

Register databases using names #102

Open MirceaKitsune opened 4 years ago

MirceaKitsune commented 4 years ago

Revising my idea for a distributed platform in my mind, I was thinking of an approach which would require Orbit to support a specific capability: Identifying databases by name. I wanted to know if this is possible and how close I could get to having such a feature.

When a database is created, it's normally given a string of 32 characters. But what if instead I wanted to manually name it to something like "this_is_my_database"? Could I then use that simple word to fetch the database with that exact name?

If this isn't supported internally, what about manually converting a word to a 32 character string, then creating a database with that name? I assume there should be no issue with using an algorithm that can turn any name into an UID... however would Orbit allow me to create a new database using that specific UUID, rather than generating a random one instead?

phillmac commented 4 years ago

The id is not random, it's the hash of the manifest. You can name the database if you choose. See https://github.com/orbitdb/orbit-db/blob/master/API.md#orbitdbcreatename-type-options

aphelionz commented 4 years ago

The trick to creating a deterministic manifest hash is mainly in the ACL. It generally requires creating a custom access controller but if the ACL hash is the same, then your manifest hash will be the same. If that makes sense I can reply in more detail but let me know if that makes sense. Try using ipfs.dag.get first with the manifest hash and then the ACL hash within to get a sense of what's going on.

MirceaKitsune commented 4 years ago

From what I'm seeing in that example link, I should be able to use names directly. Do they act as sub-databases in a primary database? If so I could just make a default database for the project (can be a random hash) and have the individual ones in that (with exact names).

tabcat commented 4 years ago

names affect the manifest address which is the hash you see in the orbitdb address. the manifest is a core component of orbitdb and represents static data containing important information like name, accessController, and database type. the orbitdb address is also used as a pubsub topic to replicate the specific db with peers over the network. https://github.com/orbitdb/orbit-db/blob/master/GUIDE.md

MirceaKitsune commented 4 years ago

I see. So in the end, can I create an Orbit database by using a word, then anywhere else fetch that database using the exact same word?

tabcat commented 4 years ago

yes, you do this by making sure the hash (i.e. orbitdb address) is the same for any peer that wants to join by configuring name, type, and options. like aphelionz mentioned determining the manifest hash mainly has to do with the accessController, theres a default option for the accessController when creating a db to only allow the creators id. if you change this option, documented in the link phill posted, you simply match the docstore type and name and will have the same orbitdb address.

tabcat commented 4 years ago

if you actually want to grab an orbitdb store from one word you would probably just want to have something pointing to an orbitdb address like a naming system

aphelionz commented 4 years ago

Typically you create a database using a word, which returns the full address. From "elsewhere" i.e. other peers, you would use the address. However, a created database with the same name, database type, and ACL will result in the same address

MirceaKitsune commented 4 years ago

So I only need to worry about predicting what the UID would be. Name and database type would be easy to hard-code in, but if the access key of the owner is also needed that might be a problem since I likely won't know it from the reading end.

I assume it's not possible to have multiple databases under the same ID, even if they're the same type but different owners? Something like:

/orbitdb/QmfY3udPcWUD5NREjrUV351Cia7q4DXNcfyRLJzUPL3wPD/foo /orbitdb/QmfY3udPcWUD5NREjrUV351Cia7q4DXNcfyRLJzUPL3wPD/bar

tabcat commented 4 years ago

correct this is not possible because the name is part of the manifest, any differences in the manifest result in a different manifest hash. its common to set the accessController options to { write: ['*'] } when creating a public db, this allows any id to write to the db and manifest hash depends only on name and type after that. the guide is very very useful in outlining key properties of orbitdb if you havent checked it out already.

MirceaKitsune commented 4 years ago

Oh, it's fine then: The databases in cause are intended to be public. So if I set the access to "*", know the name of the database, and also know the database type... I can work out its full address from anywhere? Is this capability also guaranteed to never break in the future?

aphelionz commented 4 years ago

@MirceaKitsune For all intents and purposes, it's not intended to change