mirror of
https://github.com/fluencelabs/js-libp2p
synced 2025-06-13 01:01:23 +00:00
docs: update examples (#271)
* docs: fix examples * chore: remove non jenkins ci files * chore: update libp2p-spdy * chore: update libp2p-spdy * docs: update example language
This commit is contained in:
@ -11,7 +11,7 @@ const defaultsDeep = require('@nodeutils/defaults-deep')
|
||||
const libp2p = require('../../../../')
|
||||
|
||||
// Find this list at: https://github.com/ipfs/js-ipfs/blob/master/src/core/runtime/config-browser.json
|
||||
const bootstrapers = [
|
||||
const bootstrapList = [
|
||||
'/dns4/ams-1.bootstrap.libp2p.io/tcp/443/wss/ipfs/QmSoLer265NRgSp2LA3dPaeykiS1J6DifTC88f5uVQKNAd',
|
||||
'/dns4/sfo-1.bootstrap.libp2p.io/tcp/443/wss/ipfs/QmSoLju6m7xTh3DuokvT3886QRYqxAzb1kShaanJgW36yx',
|
||||
'/dns4/lon-1.bootstrap.libp2p.io/tcp/443/wss/ipfs/QmSoLMeWqB7YGVLJN3pNLQpmmEk35v6wYtsMGLzSr5QBU3',
|
||||
@ -20,8 +20,8 @@ const bootstrapers = [
|
||||
'/dns4/sgp-1.bootstrap.libp2p.io/tcp/443/wss/ipfs/QmSoLSafTMBsPKadTEgaXctDQVcqN88CNLHXMkTNwMKPnu',
|
||||
'/dns4/nyc-1.bootstrap.libp2p.io/tcp/443/wss/ipfs/QmSoLueR4xBeUbY9WZ9xGUUxunbKWcrNFTDAadQJmocnWm',
|
||||
'/dns4/nyc-2.bootstrap.libp2p.io/tcp/443/wss/ipfs/QmSoLV4Bbm51jM9C4gDYZQ9Cy3U6aXMJDAbzgu2fzaDs64',
|
||||
'/dns4/wss0.bootstrap.libp2p.io/tcp/443/wss/ipfs/QmZMxNdpMkewiVZLMRxaNxUeZpDUb34pWjZ1kZvsd16Zic',
|
||||
'/dns4/wss1.bootstrap.libp2p.io/tcp/443/wss/ipfs/Qmbut9Ywz9YEDrz8ySBSgWyJk41Uvm2QJPhwDJzJyGFsD6'
|
||||
'/dns4/node0.preload.ipfs.io/tcp/443/wss/ipfs/QmZMxNdpMkewiVZLMRxaNxUeZpDUb34pWjZ1kZvsd16Zic',
|
||||
'/dns4/node0.preload.ipfs.io/tcp/443/wss/ipfs/Qmbut9Ywz9YEDrz8ySBSgWyJk41Uvm2QJPhwDJzJyGFsD6'
|
||||
]
|
||||
|
||||
class Node extends libp2p {
|
||||
@ -60,7 +60,7 @@ class Node extends libp2p {
|
||||
bootstrap: {
|
||||
interval: 10000,
|
||||
enabled: true,
|
||||
list: bootstrapers
|
||||
list: bootstrapList
|
||||
}
|
||||
},
|
||||
relay: {
|
||||
|
@ -17,24 +17,22 @@ domReady(() => {
|
||||
let connections = {}
|
||||
|
||||
node.on('peer:discovery', (peerInfo) => {
|
||||
console.log('Discovered a peer')
|
||||
const idStr = peerInfo.id.toB58String()
|
||||
console.log('Discovered: ' + idStr)
|
||||
if (connections[idStr]) {
|
||||
// If we're already trying to connect to this peer, dont dial again
|
||||
return
|
||||
}
|
||||
console.log('Discovered a peer:', idStr)
|
||||
|
||||
connections[idStr] = true
|
||||
node.dial(peerInfo, (err, conn) => {
|
||||
let timeToNextDial = 0
|
||||
if (err) {
|
||||
// Prevent immediate connection retries from happening
|
||||
timeToNextDial = 30 * 1000
|
||||
// and include a 10s jitter
|
||||
const timeToNextDial = 25 * 1000 + (Math.random(0) * 10000).toFixed(0)
|
||||
console.log('Failed to dial:', idStr)
|
||||
setTimeout(() => delete connections[idStr], timeToNextDial)
|
||||
}
|
||||
|
||||
setTimeout(() => delete connections[idStr], timeToNextDial)
|
||||
})
|
||||
})
|
||||
|
||||
@ -49,8 +47,10 @@ domReady(() => {
|
||||
|
||||
node.on('peer:disconnect', (peerInfo) => {
|
||||
const idStr = peerInfo.id.toB58String()
|
||||
delete connections[idStr]
|
||||
console.log('Lost connection to: ' + idStr)
|
||||
document.getElementById(idStr).remove()
|
||||
const el = document.getElementById(idStr)
|
||||
el && el.remove()
|
||||
})
|
||||
|
||||
node.start((err) => {
|
||||
|
Reference in New Issue
Block a user