Skip to content
This repository has been archived by the owner on Dec 18, 2024. It is now read-only.

Register databases using names #102

Open
MirceaKitsune opened this issue Oct 13, 2019 · 12 comments
Open

Register databases using names #102

MirceaKitsune opened this issue Oct 13, 2019 · 12 comments

Comments

@MirceaKitsune
Copy link

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
Copy link
Contributor

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
Copy link
Collaborator

aphelionz commented Oct 13, 2019

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
Copy link
Author

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
Copy link
Contributor

tabcat commented Oct 13, 2019

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
Copy link
Author

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
Copy link
Contributor

tabcat commented Oct 13, 2019

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
Copy link
Contributor

tabcat commented Oct 13, 2019

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
Copy link
Collaborator

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
Copy link
Author

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
Copy link
Contributor

tabcat commented Oct 14, 2019

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
Copy link
Author

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
Copy link
Collaborator

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

@aphelionz aphelionz transferred this issue from orbitdb/orbitdb Oct 16, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

4 participants