From c70d08bbe1cfabe037d067ba01083318df971bd8 Mon Sep 17 00:00:00 2001 From: Daniel N <2color@users.noreply.github.com> Date: Fri, 21 Jun 2024 11:57:18 +0200 Subject: [PATCH 1/4] fix: pass options to subclass pass down trustless gateway option to session subclass --- packages/block-brokers/src/trustless-gateway/broker.ts | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/packages/block-brokers/src/trustless-gateway/broker.ts b/packages/block-brokers/src/trustless-gateway/broker.ts index ec566a90f..310adbf5c 100644 --- a/packages/block-brokers/src/trustless-gateway/broker.ts +++ b/packages/block-brokers/src/trustless-gateway/broker.ts @@ -90,6 +90,10 @@ export class TrustlessGatewayBlockBroker implements BlockBroker Date: Fri, 21 Jun 2024 11:58:27 +0200 Subject: [PATCH 2/4] test: add test to ensure correct filtering of maddrs --- .../test/trustless-gateway-utils.spec.ts | 30 +++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 packages/block-brokers/test/trustless-gateway-utils.spec.ts diff --git a/packages/block-brokers/test/trustless-gateway-utils.spec.ts b/packages/block-brokers/test/trustless-gateway-utils.spec.ts new file mode 100644 index 000000000..8a2a42130 --- /dev/null +++ b/packages/block-brokers/test/trustless-gateway-utils.spec.ts @@ -0,0 +1,30 @@ +import { uriToMultiaddr } from '@multiformats/uri-to-multiaddr' +import { expect } from 'aegir/chai' +import { filterNonHTTPMultiaddrs } from '../src/trustless-gateway/utils.js' + +describe('trustless-gateway-block-broker-utils', () => { + it('filterNonHTTPMultiaddrs respects allowInsecure multiaddrs correctly', async function () { + const nonSecureMaddr = uriToMultiaddr('http://mygw.com') + const secureMaddr = uriToMultiaddr('https://mygw.com') + + const filtered = filterNonHTTPMultiaddrs([nonSecureMaddr, secureMaddr], true, true) + + expect(filtered.length).to.deep.equal(2) + }) + + it('filterNonHTTPMultiaddrs filters local multiaddrs correctly', async function () { + const localMaddr = uriToMultiaddr('http://localhost') + + const filtered = filterNonHTTPMultiaddrs([localMaddr], true, true) + + expect(filtered.length).to.deep.equal(1) + }) + + it('filterNonHTTPMultiaddrs filters multiaddrs correctly', async function () { + const localMaddr = uriToMultiaddr('http://localhost') + + const filtered = filterNonHTTPMultiaddrs([localMaddr], false, false) + + expect(filtered.length).to.deep.equal(0) + }) +}) From cccdd52693de6e2c06c01b49fb041467668363d4 Mon Sep 17 00:00:00 2001 From: Daniel N <2color@users.noreply.github.com> Date: Fri, 21 Jun 2024 13:26:58 +0200 Subject: [PATCH 3/4] chore: use servicemap from libp2p --- packages/helia/src/utils/libp2p-defaults.browser.ts | 3 ++- packages/helia/src/utils/libp2p-defaults.ts | 3 ++- packages/helia/src/utils/libp2p.ts | 6 +++--- 3 files changed, 7 insertions(+), 5 deletions(-) diff --git a/packages/helia/src/utils/libp2p-defaults.browser.ts b/packages/helia/src/utils/libp2p-defaults.browser.ts index 524094e93..9a8e0670d 100644 --- a/packages/helia/src/utils/libp2p-defaults.browser.ts +++ b/packages/helia/src/utils/libp2p-defaults.browser.ts @@ -19,9 +19,10 @@ import * as libp2pInfo from 'libp2p/version' import { name, version } from '../version.js' import { bootstrapConfig } from './bootstrappers.js' import type { Libp2pDefaultsOptions } from './libp2p.js' +import type { ServiceMap } from '@libp2p/interface' import type { Libp2pOptions } from 'libp2p' -export interface DefaultLibp2pServices extends Record { +export interface DefaultLibp2pServices extends ServiceMap { autoNAT: unknown dcutr: unknown delegatedRouting: unknown diff --git a/packages/helia/src/utils/libp2p-defaults.ts b/packages/helia/src/utils/libp2p-defaults.ts index 3d698facb..b7bfa1707 100644 --- a/packages/helia/src/utils/libp2p-defaults.ts +++ b/packages/helia/src/utils/libp2p-defaults.ts @@ -21,9 +21,10 @@ import * as libp2pInfo from 'libp2p/version' import { name, version } from '../version.js' import { bootstrapConfig } from './bootstrappers.js' import type { Libp2pDefaultsOptions } from './libp2p.js' +import type { ServiceMap } from '@libp2p/interface' import type { Libp2pOptions } from 'libp2p' -export interface DefaultLibp2pServices extends Record { +export interface DefaultLibp2pServices extends ServiceMap { autoNAT: unknown dcutr: unknown delegatedRouting: unknown diff --git a/packages/helia/src/utils/libp2p.ts b/packages/helia/src/utils/libp2p.ts index f5597e08e..7b55ced22 100644 --- a/packages/helia/src/utils/libp2p.ts +++ b/packages/helia/src/utils/libp2p.ts @@ -4,13 +4,13 @@ import { Key } from 'interface-datastore' import { createLibp2p as create } from 'libp2p' import { libp2pDefaults } from './libp2p-defaults.js' import type { DefaultLibp2pServices } from './libp2p-defaults.js' -import type { ComponentLogger, Libp2p, PeerId } from '@libp2p/interface' +import type { ComponentLogger, Libp2p, PeerId, ServiceMap } from '@libp2p/interface' import type { Keychain, KeychainInit } from '@libp2p/keychain' import type { DNS } from '@multiformats/dns' import type { Datastore } from 'interface-datastore' import type { Libp2pOptions } from 'libp2p' -export interface CreateLibp2pOptions> { +export interface CreateLibp2pOptions { datastore: Datastore libp2p?: Libp2pOptions logger?: ComponentLogger @@ -24,7 +24,7 @@ export interface Libp2pDefaultsOptions { dns?: DNS } -export async function createLibp2p = DefaultLibp2pServices> (options: CreateLibp2pOptions): Promise> { +export async function createLibp2p (options: CreateLibp2pOptions): Promise> { const peerId = options.libp2p?.peerId const logger = options.logger ?? defaultLogger() const selfKey = new Key('/pkcs8/self') From c9c7b2cb943dec60e3da1f1c165ccc37b444b81d Mon Sep 17 00:00:00 2001 From: achingbrain Date: Thu, 25 Jul 2024 18:33:23 +0100 Subject: [PATCH 4/4] chore: revert service map changes --- packages/helia/src/utils/libp2p-defaults.browser.ts | 3 +-- packages/helia/src/utils/libp2p-defaults.ts | 3 +-- packages/helia/src/utils/libp2p.ts | 6 +++--- 3 files changed, 5 insertions(+), 7 deletions(-) diff --git a/packages/helia/src/utils/libp2p-defaults.browser.ts b/packages/helia/src/utils/libp2p-defaults.browser.ts index 091d7fb7b..85cd58391 100644 --- a/packages/helia/src/utils/libp2p-defaults.browser.ts +++ b/packages/helia/src/utils/libp2p-defaults.browser.ts @@ -19,10 +19,9 @@ import * as libp2pInfo from 'libp2p/version' import { name, version } from '../version.js' import { bootstrapConfig } from './bootstrappers.js' import type { Libp2pDefaultsOptions } from './libp2p.js' -import type { ServiceMap } from '@libp2p/interface' import type { Libp2pOptions } from 'libp2p' -export interface DefaultLibp2pServices extends ServiceMap { +export interface DefaultLibp2pServices extends Record { autoNAT: unknown dcutr: unknown delegatedRouting: unknown diff --git a/packages/helia/src/utils/libp2p-defaults.ts b/packages/helia/src/utils/libp2p-defaults.ts index 8d026cd50..b7c6b8ab6 100644 --- a/packages/helia/src/utils/libp2p-defaults.ts +++ b/packages/helia/src/utils/libp2p-defaults.ts @@ -21,10 +21,9 @@ import * as libp2pInfo from 'libp2p/version' import { name, version } from '../version.js' import { bootstrapConfig } from './bootstrappers.js' import type { Libp2pDefaultsOptions } from './libp2p.js' -import type { ServiceMap } from '@libp2p/interface' import type { Libp2pOptions } from 'libp2p' -export interface DefaultLibp2pServices extends ServiceMap { +export interface DefaultLibp2pServices extends Record { autoNAT: unknown dcutr: unknown delegatedRouting: unknown diff --git a/packages/helia/src/utils/libp2p.ts b/packages/helia/src/utils/libp2p.ts index 7b55ced22..f5597e08e 100644 --- a/packages/helia/src/utils/libp2p.ts +++ b/packages/helia/src/utils/libp2p.ts @@ -4,13 +4,13 @@ import { Key } from 'interface-datastore' import { createLibp2p as create } from 'libp2p' import { libp2pDefaults } from './libp2p-defaults.js' import type { DefaultLibp2pServices } from './libp2p-defaults.js' -import type { ComponentLogger, Libp2p, PeerId, ServiceMap } from '@libp2p/interface' +import type { ComponentLogger, Libp2p, PeerId } from '@libp2p/interface' import type { Keychain, KeychainInit } from '@libp2p/keychain' import type { DNS } from '@multiformats/dns' import type { Datastore } from 'interface-datastore' import type { Libp2pOptions } from 'libp2p' -export interface CreateLibp2pOptions { +export interface CreateLibp2pOptions> { datastore: Datastore libp2p?: Libp2pOptions logger?: ComponentLogger @@ -24,7 +24,7 @@ export interface Libp2pDefaultsOptions { dns?: DNS } -export async function createLibp2p (options: CreateLibp2pOptions): Promise> { +export async function createLibp2p = DefaultLibp2pServices> (options: CreateLibp2pOptions): Promise> { const peerId = options.libp2p?.peerId const logger = options.logger ?? defaultLogger() const selfKey = new Key('/pkcs8/self')