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

feat: filter origins & delegates #13

Merged
merged 4 commits into from
Feb 7, 2024
Merged

feat: filter origins & delegates #13

merged 4 commits into from
Feb 7, 2024

Conversation

SgtPooki
Copy link
Member

@SgtPooki SgtPooki commented Sep 13, 2023

This PR adds more configuration options and no longer merges origins by default.

New configuration options:

  • mergeOrigins: boolean
  • filterOrigins: (origins: string[]) => string[]
  • filterDelegates: (delegates: string[]) => string[]

New functionality:

  • only merge origins if mergeOrigins option is true
  • returned origins have providedOrigins appearing earlier in origins array than helia.libp2p.getMultiaddrs() origins.

only merge origins if mergeOrigins option is true
Copy link

@whizzzkid whizzzkid left a comment

Choose a reason for hiding this comment

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

Approved with nits.

constructor (private readonly heliaInstance: Helia, private readonly remotePinningClient: RemotePinningServiceClient, config?: HeliaRemotePinnerConfig) {
this.config = {
mergeOrigins: config?.mergeOrigins ?? false,

Choose a reason for hiding this comment

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

aren't these set as Required? does nullish check still apply?

Copy link
Member Author

Choose a reason for hiding this comment

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

ah.. yes, I should remove from the Pick<Required. good catch

Copy link
Member Author

Choose a reason for hiding this comment

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

wait, no, the this.config is the only place it's required. the passed in options are all optional.

Copy link
Member Author

Choose a reason for hiding this comment

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

which means, in the constructor, we have to set the required options on this.config, but user doesn't need to pass anything.

Copy link
Member Author

Choose a reason for hiding this comment

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

fixed an issue though: f0bf463

Comment on lines 89 to 90
const nodeOrigins = multiaddrs.map(multiaddr => multiaddr.toString())
const filteredOrigins = this.config.filterOrigins?.(nodeOrigins) ?? nodeOrigins

Choose a reason for hiding this comment

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

can we call const nodeOrigins something else? in fact since this assignment is only used in case this.config.filterOrigins?.(nodeOrigins) ?? why spend time converting all multiaddrs.toString()?

Copy link
Member Author

Choose a reason for hiding this comment

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

because filterOrigins takes an array of strings.. though it should probably take an array of Multiaddrs

src/heliaRemotePinner.ts Outdated Show resolved Hide resolved
src/heliaRemotePinner.ts Show resolved Hide resolved
*
* @default (origins) => origins
*/
filterOrigins?: (origins: string[]) => string[]

Choose a reason for hiding this comment

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

wondering if there is a need support regexp.

Copy link
Member Author

Choose a reason for hiding this comment

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

filtering multiaddrs with regex can be done in user provided function if they desire. full customization owned by fn caller

@SgtPooki
Copy link
Member Author

FYI: I have some additional updates here that i added while working on ipfs-examples/helia-examples#147 that I want to be sure are looked at, will update when i unblock ipfs-desktop and ipfs-webui issues

Copy link
Contributor

github-actions bot commented Feb 7, 2024

🎉 This PR is included in version 1.2.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants