Skip to content
This repository has been archived by the owner on Jun 26, 2023. It is now read-only.

feat: add ValueStore interface #108

Merged
merged 4 commits into from
Oct 18, 2021
Merged

Conversation

yusefnapora
Copy link
Contributor

This adds a ContentRoutingStorage interface with put and get methods for storing key/value data either with the DHT or via delegated routing (and maybe pubsub? I'm not sure if pubsub routing has k/v storage).

The idea is that instead of directly hitting the dht in js-libp2p here, we can loop through all the routers and do something like this:

    // try using all routers that support the `put` operation.
    // if more than one support it, the first to resolve will be used
    const promises = []
    for (const router of this.routers) {
      if ('put' in router && typeof router.put === 'function') {
        promises.push(router.put(key, value, options))
      }
    }
    
    return raceToSuccess(promises)

Where raceToSuccess returns the first promise to resolve, or fails if all promises fail. The DHT already conforms to this new interface, and libp2p/js-libp2p-delegated-content-routing#54 will add it to the delegated routing module.

Open to suggestions on the interface name 😄

@yusefnapora yusefnapora changed the title feat: add ContentRoutingStorage interface feat: add ValueStore interface Oct 5, 2021
@yusefnapora
Copy link
Contributor Author

I realized that the dht doesn't return raw Uint8Arrays from get - instead it returns objects like

{
  from: PeerId,
  val: Uint8Array
}

So the last commit adds that to the interface.

Copy link
Member

@vasco-santos vasco-santos left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks good from the interface perspective. Thanks @yusefnapora

We should create an issue to track further improvements by adding the actual test suite

@vasco-santos vasco-santos merged commit 09c6e10 into master Oct 18, 2021
@vasco-santos vasco-santos deleted the feat/content-routing-storage branch October 18, 2021 13:06
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

3 participants