Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

@web5/agent Adding DwnServerInfo to RPC Clients #489

Merged
merged 12 commits into from
May 7, 2024

Conversation

LiranCohen
Copy link
Member

@LiranCohen LiranCohen commented Apr 11, 2024

  • Added a DwnServerInfo HTTP client to get info from the dwn-server's /info endpoint
export type ServerInfo = {
  /** the maximum file size the user can request to store */
  maxFileSize: number,
  /**
   * an array of strings representing the server's registration requirements.
   *
   * ie. ['proof-of-work-sha256-v0', 'terms-of-service']
   * */
  registrationRequirements: string[],
  /** whether web socket support is enabled on this server */
  webSocketSupport: boolean,
}

This is helpful for retrieving registration requirements and whether the server supports sockets.

It uses a TTLCache memory cache as the currently implemented and default, however additional caches can be easily added if necessary.

Copy link

changeset-bot bot commented Apr 11, 2024

🦋 Changeset detected

Latest commit: 1fbb6b5

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 4 packages
Name Type
@web5/agent Patch
@web5/identity-agent Patch
@web5/proxy-agent Patch
@web5/user-agent Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@LiranCohen LiranCohen changed the title Adding DwnServerInfo to RPC Clients @web5/agent Adding DwnServerInfo to RPC Clients Apr 11, 2024
Copy link
Contributor

github-actions bot commented Apr 11, 2024

TBDocs Report

✅ No errors or warnings

@web5/api

  • Project entry file: packages/api/src/index.ts

@web5/crypto

  • Project entry file: packages/crypto/src/index.ts

@web5/crypto-aws-kms

  • Project entry file: packages/crypto-aws-kms/src/index.ts

@web5/dids

  • Project entry file: packages/dids/src/index.ts

@web5/credentials

  • Project entry file: packages/credentials/src/index.ts

TBDocs Report Updated at 2024-05-02T21:24:04Z 1fbb6b5

@LiranCohen LiranCohen marked this pull request as ready for review April 11, 2024 02:42
@codecov-commenter
Copy link

codecov-commenter commented Apr 12, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 91.03%. Comparing base (1d59f71) to head (1fbb6b5).

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #489      +/-   ##
==========================================
+ Coverage   90.81%   91.03%   +0.21%     
==========================================
  Files         116      116              
  Lines       29442    29526      +84     
  Branches     2156     2174      +18     
==========================================
+ Hits        26739    26878     +139     
+ Misses       2668     2613      -55     
  Partials       35       35              
Components Coverage Δ
agent 80.62% <100.00%> (+0.72%) ⬆️
api 97.92% <ø> (ø)
common 98.68% <ø> (ø)
credentials 95.26% <ø> (ø)
crypto 93.81% <ø> (ø)
dids 97.66% <ø> (ø)
identity-agent 96.70% <ø> (ø)
crypto-aws-kms 100.00% <ø> (ø)
proxy-agent 96.70% <ø> (ø)
user-agent 96.70% <ø> (ø)

@LiranCohen LiranCohen force-pushed the lirancohen/dwn-server-info branch from b2116ea to 9a402a0 Compare May 1, 2024 14:14
@LiranCohen LiranCohen requested a review from shamilovtim as a code owner May 1, 2024 14:14
@LiranCohen LiranCohen force-pushed the lirancohen/dwn-server-info branch from 9a402a0 to 4461f5b Compare May 1, 2024 15:21
Copy link
Contributor

@shamilovtim shamilovtim left a comment

Choose a reason for hiding this comment

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

Could the two caches somehow reuse the MemoryStore or LevelStore interfaces? It seems like we've written that same API a handful of time already in web5 SDK

@LiranCohen LiranCohen force-pushed the lirancohen/dwn-server-info branch from 2536cb4 to 1fbb6b5 Compare May 2, 2024 21:20
@LiranCohen LiranCohen requested a review from thehenrytsai as a code owner May 2, 2024 21:20
@LiranCohen
Copy link
Member Author

@shamilovtim good call outs on the unnecessary caching implementations. We can add ones if there is a need but I think a memory TTL cache is all that we currently need.

Could the two caches somehow reuse the MemoryStore or LevelStore interfaces? It seems like we've written that same API a handful of time already in web5 SDK

The MemoryStore is simply a map where as the TTLCache has a bit more logic to evict data once a size is hit.
I would like to create an issue to create an AsyncTTLCache or something of that nature that would fit an async interface better, effectively a generic version of what DwnServerInfoCacheMemory is doing. We could create that in @web5/common and then replace some of these other wrappers that are just doing the same thing by extending the AsyncTTLCache.

Let me know what you think about the approach and I'll create an issue.

@LiranCohen LiranCohen requested a review from shamilovtim May 2, 2024 21:41
Copy link
Contributor

@thehenrytsai thehenrytsai left a comment

Choose a reason for hiding this comment

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

Looks good! Couple of comments.

it('returns undefined after ttl', async function () {
// skip this test in the browser, sinon fake timers don't seem to work here
// with a an await setTimeout in the test, it passes.
if (!isNode) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Sanity: this would be the first precedence that it doesn't work in browser right? Have you tried passing number instead of string to tickAsync()?

Copy link
Member Author

Choose a reason for hiding this comment

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

It's really strange that it doesn't work. I just tried a number instead of string and get the same behavior because I didn't think to try that before. But still fails in the browsers.

ttl?: string;
}

export class DwnServerInfoCacheMemory implements DwnServerInfoCache {
Copy link
Contributor

@thehenrytsai thehenrytsai May 6, 2024

Choose a reason for hiding this comment

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

Consider turning this into generic, seems low hanging fruit.

Suggested change
export class DwnServerInfoCacheMemory implements DwnServerInfoCache {
export class MemoryCache<T> implements GenericCache<T> {

Copy link
Contributor

Choose a reason for hiding this comment

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

The thing about this is we already have one called MemoryStore which is why his is more specific. Maybe MemoryStoreAsync? Unsure

Copy link
Member Author

Choose a reason for hiding this comment

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

@thehenrytsai Yeah @shamilovtim called out something similar and I was considering this, but figured we could do a separate PR to add TTLCacheAsync or something of that sort to @web5/common because we are doing this same wrapper in a couple of places to conform with an async interface.

@LiranCohen LiranCohen merged commit eabe5ca into main May 7, 2024
11 checks passed
@LiranCohen LiranCohen deleted the lirancohen/dwn-server-info branch May 7, 2024 17:57
@github-actions github-actions bot mentioned this pull request May 7, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants