Skip to content
This repository has been archived by the owner on Mar 23, 2023. It is now read-only.

Commit

Permalink
fix: use local seed list if peer discovery fails (#1924)
Browse files Browse the repository at this point in the history
  • Loading branch information
faustbrian authored May 18, 2020
1 parent 6fcf597 commit 1f9ba7f
Show file tree
Hide file tree
Showing 4 changed files with 339 additions and 22 deletions.
21 changes: 21 additions & 0 deletions src/renderer/store/modules/peer/devnet.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
[{
"ip": "167.114.29.51",
"port": 4002
},
{
"ip": "167.114.29.52",
"port": 4002
},
{
"ip": "167.114.29.53",
"port": 4002
},
{
"ip": "167.114.29.54",
"port": 4002
},
{
"ip": "167.114.29.55",
"port": 4002
}
]
4 changes: 4 additions & 0 deletions src/renderer/store/modules/peer/fallback.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export const fallbackSeeds = {
'ark.mainnet': require('./mainnet.json'),
'ark.devnet': require('./devnet.json')
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,37 @@ import i18n from '@/i18n'
import { isEmpty } from '@/utils'
import PeerModel from '@/models/peer'
import Vue from 'vue'
import { fallbackSeeds } from './fallback'

const getBaseUrl = (peer) => {
const scheme = peer.isHttps ? 'https://' : 'http://'

return `${scheme}${peer.ip}:${peer.port}`
}

const discoverPeers = async (peerDiscovery) => {
peerDiscovery.withLatency(300).sortBy('latency')

const peers = await peerDiscovery.findPeersWithPlugin('core-api', {
additional: [
'height',
'latency'
]
})

if (peers && peers.length) {
return peers
}

return peerDiscovery.findPeersWithPlugin('core-wallet-api', {
additional: [
'height',
'latency',
'version'
]
})
}

export default {
namespaced: true,

Expand Down Expand Up @@ -323,35 +347,46 @@ export default {
* Refresh peer list.
* @return {void}
*/
async refresh ({ dispatch }, network = null) {
async refresh ({ dispatch, rootGetters }, network = null) {
let peers = []

try {
const peerDiscovery = await dispatch('getPeerDiscovery', network)
peers = await discoverPeers(await dispatch('getPeerDiscovery', network))

peerDiscovery.withLatency(300)
.sortBy('latency')
throw new Error('xxx')
} catch (error) {
if (!network) {
network = rootGetters['session/network']
}

peers = await peerDiscovery
.findPeersWithPlugin('core-api', {
additional: [
'height',
'latency'
]
})
const networkLookup = {
'ark.mainnet': 'mainnet',
'ark.devnet': 'devnet'
}

if (networkLookup[network.id]) {
console.log('Could not refresh peer list. Using fallback seeds: ', error)

let peerDiscoveryFailed = true

while (peerDiscoveryFailed) {
try {
const seeds = fallbackSeeds[network.id]
const seed = seeds[Math.floor(Math.random() * seeds.length)]
const peerDiscovery = await PeerDiscovery.new({ networkOrHost: `http://${seed.ip}:4003/api/peers` })

peers = await discoverPeers(peerDiscovery)

if (!peers.length) {
peers = await peerDiscovery
.findPeersWithPlugin('core-wallet-api', {
additional: [
'height',
'latency',
'version'
]
})
peerDiscoveryFailed = false
} catch (error) {
peerDiscoveryFailed = true

console.error('Could not refresh peer list:', error)
}
}
} else {
console.error('Could not refresh peer list:', error)
}
} catch (error) {
console.error('Could not refresh peer list:', error)
}

if (!peers.length) {
Expand Down
257 changes: 257 additions & 0 deletions src/renderer/store/modules/peer/mainnet.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,257 @@
[{
"ip": "5.196.105.32",
"port": 4001
},
{
"ip": "5.196.105.33",
"port": 4001
},
{
"ip": "5.196.105.34",
"port": 4001
},
{
"ip": "5.196.105.35",
"port": 4001
},
{
"ip": "5.196.105.36",
"port": 4001
},
{
"ip": "5.196.105.37",
"port": 4001
},
{
"ip": "5.196.105.38",
"port": 4001
},
{
"ip": "5.196.105.39",
"port": 4001
},
{
"ip": "178.32.65.136",
"port": 4001
},
{
"ip": "178.32.65.137",
"port": 4001
},
{
"ip": "178.32.65.138",
"port": 4001
},
{
"ip": "178.32.65.139",
"port": 4001
},
{
"ip": "178.32.65.140",
"port": 4001
},
{
"ip": "178.32.65.141",
"port": 4001
},
{
"ip": "178.32.65.142",
"port": 4001
},
{
"ip": "178.32.65.143",
"port": 4001
},
{
"ip": "5.196.105.40",
"port": 4001
},
{
"ip": "5.196.105.41",
"port": 4001
},
{
"ip": "5.196.105.42",
"port": 4001
},
{
"ip": "5.196.105.43",
"port": 4001
},
{
"ip": "5.196.105.44",
"port": 4001
},
{
"ip": "5.196.105.45",
"port": 4001
},
{
"ip": "5.196.105.46",
"port": 4001
},
{
"ip": "5.196.105.47",
"port": 4001
},
{
"ip": "54.38.120.32",
"port": 4001
},
{
"ip": "54.38.120.33",
"port": 4001
},
{
"ip": "54.38.120.34",
"port": 4001
},
{
"ip": "54.38.120.35",
"port": 4001
},
{
"ip": "54.38.120.36",
"port": 4001
},
{
"ip": "54.38.120.37",
"port": 4001
},
{
"ip": "54.38.120.38",
"port": 4001
},
{
"ip": "54.38.120.39",
"port": 4001
},
{
"ip": "151.80.125.32",
"port": 4001
},
{
"ip": "151.80.125.33",
"port": 4001
},
{
"ip": "151.80.125.34",
"port": 4001
},
{
"ip": "151.80.125.35",
"port": 4001
},
{
"ip": "151.80.125.36",
"port": 4001
},
{
"ip": "151.80.125.37",
"port": 4001
},
{
"ip": "151.80.125.38",
"port": 4001
},
{
"ip": "151.80.125.39",
"port": 4001
},
{
"ip": "213.32.41.104",
"port": 4001
},
{
"ip": "213.32.41.105",
"port": 4001
},
{
"ip": "213.32.41.106",
"port": 4001
},
{
"ip": "213.32.41.107",
"port": 4001
},
{
"ip": "213.32.41.108",
"port": 4001
},
{
"ip": "213.32.41.109",
"port": 4001
},
{
"ip": "213.32.41.110",
"port": 4001
},
{
"ip": "213.32.41.111",
"port": 4001
},
{
"ip": "5.135.22.92",
"port": 4001
},
{
"ip": "5.135.22.93",
"port": 4001
},
{
"ip": "5.135.22.94",
"port": 4001
},
{
"ip": "5.135.22.95",
"port": 4001
},
{
"ip": "5.135.52.96",
"port": 4001
},
{
"ip": "5.135.52.97",
"port": 4001
},
{
"ip": "5.135.52.98",
"port": 4001
},
{
"ip": "5.135.52.99",
"port": 4001
},
{
"ip": "51.255.105.52",
"port": 4001
},
{
"ip": "51.255.105.53",
"port": 4001
},
{
"ip": "51.255.105.54",
"port": 4001
},
{
"ip": "51.255.105.55",
"port": 4001
},
{
"ip": "46.105.160.104",
"port": 4001
},
{
"ip": "46.105.160.105",
"port": 4001
},
{
"ip": "46.105.160.106",
"port": 4001
},
{
"ip": "46.105.160.107",
"port": 4001
}
]

0 comments on commit 1f9ba7f

Please sign in to comment.