-
Notifications
You must be signed in to change notification settings - Fork 106
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat!: use helia router for IPNS put/get (#387)
Uses the configured `.routing` property on the Helia interface to put/get IPNS records by default. Removes the `libp2p` routing as `helia` configures this as a `.routing` implementation and `@helia/http` doesn't have it. Updates the description of the `pubsub` routing to make it's limitations clearer. BREAKING CHANGE: `helia.routing` is the default routing used, the `libp2p` routing has been removed as it is redundant
- Loading branch information
1 parent
3477b27
commit ce74026
Showing
11 changed files
with
187 additions
and
90 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
import { CustomProgressEvent, type ProgressEvent } from 'progress-events' | ||
import type { GetOptions, PutOptions } from './index.js' | ||
import type { IPNSRouting } from '../index.js' | ||
import type { Routing } from '@helia/interface' | ||
|
||
export interface HeliaRoutingComponents { | ||
routing: Routing | ||
} | ||
|
||
export type HeliaRoutingProgressEvents = | ||
ProgressEvent<'ipns:routing:helia:error', Error> | ||
|
||
export class HeliaRouting implements IPNSRouting { | ||
private readonly routing: Routing | ||
|
||
constructor (routing: Routing) { | ||
this.routing = routing | ||
} | ||
|
||
async put (routingKey: Uint8Array, marshaledRecord: Uint8Array, options: PutOptions = {}): Promise<void> { | ||
try { | ||
await this.routing.put(routingKey, marshaledRecord, options) | ||
} catch (err: any) { | ||
options.onProgress?.(new CustomProgressEvent<Error>('ipns:routing:helia:error', err)) | ||
} | ||
} | ||
|
||
async get (routingKey: Uint8Array, options: GetOptions = {}): Promise<Uint8Array> { | ||
try { | ||
return await this.routing.get(routingKey, options) | ||
} catch (err: any) { | ||
options.onProgress?.(new CustomProgressEvent<Error>('ipns:routing:helia:error', err)) | ||
} | ||
|
||
throw new Error('Not found') | ||
} | ||
} | ||
|
||
/** | ||
* The helia routing uses any available Routers configured on the passed Helia | ||
* node. This could be libp2p, HTTP API Delegated Routing, etc. | ||
*/ | ||
export function helia (routing: Routing): IPNSRouting { | ||
return new HeliaRouting(routing) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.