Skip to content

Instantly share code, notes, and snippets.

View vasco-santos's full-sized avatar
🥁

Vasco Santos vasco-santos

🥁
View GitHub Profile
import { webSockets } from '@libp2p/websockets'
import { mplex } from '@libp2p/mplex'
import { noise } from '@chainsafe/libp2p-noise'
import { createLibp2p } from 'libp2p'
import { MemoryBlockstore } from 'blockstore-core/memory'
import { createBitswap } from 'ipfs-bitswap'
import { CID } from 'multiformats/cid'
import { multiaddr } from '@multiformats/multiaddr'
import { fetch } from '@web-std/fetch'
import { BatchWriteItemCommand, ScanCommand } from '@aws-sdk/client-dynamodb'
import { marshall, unmarshall } from '@aws-sdk/util-dynamodb'
import pWaitFor from 'p-wait-for'
import { AGGREGATE_KEY } from '../stacks/config.js'
import { createCarTable } from '../data/tables/car.js'
import { getCars } from '../data/test/helpers/car.js'
import {
import * as Signer from '@ucanto/principal/ed25519'
import { CAR } from '@ucanto/transport'
import * as CBOR from '@ucanto/transport/cbor'
import * as UcantoClient from '@ucanto/client'
import * as DAGJSON from '@ipld/dag-json'
const uploadService = await Signer.generate()
const alice = await Signer.generate()
const { proof, spaceDid } = await createSpace(alice)
@vasco-santos
vasco-santos / rate-limit-tester.sh
Created October 19, 2022 09:14
Rate Limit testing for w3link
for i in {1..500}; do curl -svo /dev/null/ -H "requestflood: true" -H 'Cache-Control: no-cache' "https://bafkreidyeivj7adnnac6ljvzj2e3rd5xdw3revw4da7mx2ckrstapoupoq.ipfs.w3s.link/" 2>&1 | grep "< HTTP"; done;
@vasco-santos
vasco-santos / web3-storage-catastrophe-recover-repopulate-ipfs-cluster.js
Created September 21, 2021 09:30
Catastrophe recover for web3.storage by repopulating a new ipfs-cluster with backup data stored
import dotenv from 'dotenv'
import {
S3Client,
paginateListObjectsV2,
GetObjectCommand
} from '@aws-sdk/client-s3'
import { Cluster } from '@nftstorage/ipfs-cluster'
dotenv.config({ path: '.env.local' })
@vasco-santos
vasco-santos / libp2p-protocol-setup.js
Last active September 24, 2020 17:33
libp2p protocol setup
const Libp2p = require('libp2p')
const Mplex = require('libp2p-mplex')
const KickoffProtocol = require('./kickoff-protocol')
const node = await Libp2p.create({
  modules: {
// … other required modules
  streamMuxer: [ Mplex ],
  }
})
@vasco-santos
vasco-santos / libp2p-protocol.js
Last active October 6, 2020 08:16
libp2p protocol
const pipe = require('it-pipe')
// The codec of our protocol
const PROTOCOL = '/libp2p/kickoff-app/1.0.0'
/**
 * A simple handler to print incoming messages to the console
 * @param {Object} params
 * @param {Connection} params.connection The connection the stream belongs to
 * @param {Stream} params.stream stream to the peer
@vasco-santos
vasco-santos / libp2p-routing-setup.js
Last active September 24, 2020 17:31
libp2p routing setup
const Libp2p = require('libp2p')
const KadDht = require('libp2p-kad-dht')
const DelegatedContentRouter = require('libp2p-delegated-content-routing')
const DelegatedPeerRouter = require('libp2p-delegated-peer-routing')
const ipfsHttpClient = require('ipfs-http-client')
const PeerId = require('peer-id')
const CID = require('cids')
const peerId = await PeerId.create()
const delegateContentRouter = new DelegatedContentRouter(peerId, ipfsHttpClient({
@vasco-santos
vasco-santos / libp2p-pubsub-setup.js
Last active April 5, 2021 17:20
libp2p pubsub setup
const Libp2p = require('libp2p')
const Gossipsub = require('libp2p-gossipsub')
const node = await Libp2p.create({
modules: {
  // … other required modules
pubsub: Gossipsub
  }
})
@vasco-santos
vasco-santos / libp2p-discovery-setup.js
Last active September 24, 2020 17:28
libp2p discovery setup
const Libp2p = require('libp2p')
const WebSockets = require('libp2p-websockets')
const WebRtcStar = require('libp2p-webrtc-star')
const Bootstrap = require('libp2p-bootstrap')
const Mdns = require('libp2p-mdns')
// Known peers addresses
const bootstrapMultiaddrs = [
 '/dns4/ams-1.bootstrap.libp2p.io/tcp/443/wss/p2p/QmSoLer265NRgSp2LA3dPaeykiS1J6DifTC88f5uVQKNAd',
 '/dns4/lon-1.bootstrap.libp2p.io/tcp/443/wss/p2p/QmSoLMeWqB7YGVLJN3pNLQpmmEk35v6wYtsMGLzSr5QBU3'