Skip to content

Commit

Permalink
chore: remove ping, use words
Browse files Browse the repository at this point in the history
  • Loading branch information
achingbrain committed Mar 14, 2024
1 parent 554f412 commit d40e068
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 60 deletions.
101 changes: 50 additions & 51 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,6 @@
"@libp2p/logger": "^4.0.7",
"@libp2p/mplex": "^10.0.16",
"@libp2p/peer-id": "^4.0.7",
"@libp2p/ping": "^1.0.12",
"@libp2p/prometheus-metrics": "^3.0.16",
"@libp2p/tcp": "^9.0.16",
"@libp2p/tls": "^1.0.2",
Expand Down
15 changes: 7 additions & 8 deletions src/getCustomLibp2p.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import { circuitRelayTransport } from '@libp2p/circuit-relay-v2'
import { identify, type Identify } from '@libp2p/identify'
import { type KadDHT, kadDHT, removePrivateAddressesMapper } from '@libp2p/kad-dht'
import { mplex } from '@libp2p/mplex'
import { ping } from '@libp2p/ping'
import { prometheusMetrics } from '@libp2p/prometheus-metrics'
import { tcp } from '@libp2p/tcp'
import { tls } from '@libp2p/tls'
Expand All @@ -18,21 +17,22 @@ import { createLibp2p as create, type Libp2pOptions, type ServiceFactoryMap } fr
import isPrivate from 'private-ip'
import { DELEGATED_ROUTING_V1_HOST, METRICS, USE_DELEGATED_ROUTING } from './constants.js'
import type { Libp2p, ServiceMap } from '@libp2p/interface'
import type { PingService } from '@libp2p/ping'
import type { Multiaddr } from '@multiformats/multiaddr'
import type { HeliaInit } from 'helia'

interface HeliaGatewayLibp2pServices extends ServiceMap {
dht: KadDHT
delegatedRouting: unknown
identify: Identify
ping: PingService
}

interface HeliaGatewayLibp2pOptions extends Pick<HeliaInit, 'datastore'> {

}

const IP4 = 4
const IP6 = 41

export async function getCustomLibp2p ({ datastore }: HeliaGatewayLibp2pOptions): Promise<Libp2p<HeliaGatewayLibp2pServices>> {
const libp2pServices: ServiceFactoryMap = {
identify: identify(),
Expand All @@ -47,8 +47,7 @@ export async function getCustomLibp2p ({ datastore }: HeliaGatewayLibp2pOptions)
selectors: {
ipns: ipnsSelector
}
}),
ping: ping()
})
}

if (USE_DELEGATED_ROUTING) {
Expand Down Expand Up @@ -91,11 +90,11 @@ export async function getCustomLibp2p ({ datastore }: HeliaGatewayLibp2pOptions)
services: libp2pServices,
connectionGater: {
denyDialMultiaddr: async (multiaddr: Multiaddr) => {
const tuples = multiaddr.stringTuples()
const [[proto, address]] = multiaddr.stringTuples()

// deny private ip4/ip6 addresses
if (tuples[0][0] === 4 || tuples[0][0] === 41) {
return Boolean(isPrivate(`${tuples[0][1]}`))
if (proto === IP4 || proto === IP6) {
return Boolean(isPrivate(`${address}`))
}

// all other addresses are ok
Expand Down

0 comments on commit d40e068

Please sign in to comment.