Skip to content

Commit

Permalink
feat: add auto-tls support (#716)
Browse files Browse the repository at this point in the history
Adds a WebSocket listener to libp2p and configures auto-tls to
automatically upgrade it to a secure WebSocket
  • Loading branch information
achingbrain authored Jan 13, 2025
1 parent a7aebd5 commit e45e1de
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 0 deletions.
1 change: 1 addition & 0 deletions packages/helia/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@
"@helia/interface": "^5.1.0",
"@helia/routers": "^2.2.0",
"@helia/utils": "^1.1.0",
"@libp2p/auto-tls": "^1.0.4",
"@libp2p/autonat": "^2.0.12",
"@libp2p/bootstrap": "^11.0.13",
"@libp2p/circuit-relay-v2": "^3.1.3",
Expand Down
6 changes: 6 additions & 0 deletions packages/helia/src/utils/libp2p-defaults.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { noise } from '@chainsafe/libp2p-noise'
import { yamux } from '@chainsafe/libp2p-yamux'
import { createDelegatedRoutingV1HttpApiClient } from '@helia/delegated-routing-v1-http-api-client'
import { delegatedHTTPRoutingDefaults } from '@helia/routers'
import { autoTLS } from '@libp2p/auto-tls'
import { autoNAT } from '@libp2p/autonat'
import { bootstrap } from '@libp2p/bootstrap'
import { circuitRelayTransport, circuitRelayServer, type CircuitRelayService } from '@libp2p/circuit-relay-v2'
Expand All @@ -23,10 +24,12 @@ 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 { AutoTLS } from '@libp2p/auto-tls'
import type { Libp2pOptions } from 'libp2p'

export interface DefaultLibp2pServices extends Record<string, unknown> {
autoNAT: unknown
autoTLS: AutoTLS
dcutr: unknown
delegatedRouting: unknown
dht: KadDHT
Expand All @@ -46,7 +49,9 @@ export function libp2pDefaults (options: Libp2pDefaultsOptions = {}): Libp2pOpti
addresses: {
listen: [
'/ip4/0.0.0.0/tcp/0',
'/ip4/0.0.0.0/tcp/0/ws',
'/ip6/::/tcp/0',
'/ip6/::/tcp/0/ws',
'/p2p-circuit',
'/webrtc'
]
Expand All @@ -72,6 +77,7 @@ export function libp2pDefaults (options: Libp2pDefaultsOptions = {}): Libp2pOpti
],
services: {
autoNAT: autoNAT(),
autoTLS: autoTLS(),
dcutr: dcutr(),
delegatedRouting: () => createDelegatedRoutingV1HttpApiClient('https://delegated-ipfs.dev', delegatedHTTPRoutingDefaults()),
dht: kadDHT({
Expand Down
2 changes: 2 additions & 0 deletions packages/interop/src/fixtures/create-helia.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ export async function createHeliaNode (libp2pOptions?: Libp2pOptions): Promise<H
delete defaults.services.dcutr
// @ts-expect-error services.delegatedRouting is not optional
delete defaults.services.delegatedRouting
// @ts-expect-error services.autoTLS is not optional
delete defaults.services.autoTLS

return createHelia<Libp2p<DefaultLibp2pServices>>({
blockBrokers: [
Expand Down

0 comments on commit e45e1de

Please sign in to comment.