Skip to content

Instantly share code, notes, and snippets.

View vasco-santos's full-sized avatar
🥁

Vasco Santos vasco-santos

🥁
View GitHub Profile
@vasco-santos
vasco-santos / connection.js
Last active May 13, 2019 15:30
js-libp2p connection
const STATUS = {
OPEN: 0,
CLOSED: 1,
CLOSING: 2,
}
const ROLE = {
INITIATOR: 0,
RESPONDER: 1
}
@vasco-santos
vasco-santos / stream.js
Last active May 13, 2019 15:37
js-libp2p stream
const ROLE = {
INITIATOR: 0,
RESPONDER: 1
}
class Stream {
constructor(iterableDuplex, connection, isInitiator = true) {
/**
* Stream identifier
*/
const promiseToCallback = require('promise-to-callback')
const toPull = require('async-iterator-to-pull-stream')
const encrypt = async (localId, conn, remoteId) => {
// TODO implementation
// ...
pull(
conn,
toPull.duplex(handshake(state, finish)),
@vasco-santos
vasco-santos / pubsub.js
Last active October 15, 2019 10:43
Pubsub base protocol proposal for libp2p refactor
'use strict'
const assert = require('assert')
const debug = require('debug')
const EventEmitter = require('events')
const errcode = require('err-code')
const PeerInfo = require('peer-info')
const message = require('./message')
@vasco-santos
vasco-santos / libp2p-basic-setup.js
Last active September 24, 2020 16:38
Libp2p basic setup
const Libp2p = require('libp2p')
const node = await Libp2p.create({
modules: {
  // Your modules
}
})
@vasco-santos
vasco-santos / libp2p-basic-setup-transport.js
Created September 24, 2020 16:40
libp2p Basic setup transport
const Libp2p = require('libp2p')
const WebSockets = require('libp2p-websockets')
const WebRtcStar = require('libp2p-webrtc-star')
const node = await Libp2p.create({
modules: {
transport: [WebSockets, WebRtcStar]
  // …
}
})
@vasco-santos
vasco-santos / libp2p-basic-setup-crypto.js
Created September 24, 2020 16:44
libp2p Basic setup crypto
const Libp2p = require('libp2p')
const WebSockets = require('libp2p-websockets')
const WebRtcStar = require('libp2p-webrtc-star')
const { NOISE } = require('libp2p-noise')
const node = await Libp2p.create({
modules: {
  transport: [WebSockets, WebRtcStar],
connEncryption: [NOISE]
  }
@vasco-santos
vasco-santos / libp2p-basic-setup-multiplexer.js
Created September 24, 2020 16:46
libp2p Basic setup multiplexer
const Libp2p = require('libp2p')
const WebSockets = require('libp2p-websockets')
const WebRtcStar = require('libp2p-webrtc-star')
const { NOISE } = require('libp2p-noise')
const MPLEX = require('libp2p-mplex')
const node = await Libp2p.create({
modules: {
transport: [WebSockets, WebRtcStar],
connEncryption: [NOISE],
@vasco-santos
vasco-santos / libp2p-basic-setup-running.js
Created September 24, 2020 16:51
libp2p Basic running setup
const Libp2p = require('libp2p')
const WebSockets = require('libp2p-websockets')
const WebRtcStar = require('libp2p-webrtc-star')
const { NOISE } = require('libp2p-noise')
const MPLEX = require('libp2p-mplex')
const node = await Libp2p.create({
modules: {
transport: [WebSockets, WebRtcStar],
connEncryption: [NOISE],
@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'