Skip to content

Commit

Permalink
feat: resend routes to peer that rebooted
Browse files Browse the repository at this point in the history
  • Loading branch information
Michiel de Jong committed Aug 9, 2017
1 parent 74959dc commit 2aae1ce
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
4 changes: 3 additions & 1 deletion src/lib/message-router.js
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,9 @@ MessageRouter.prototype.receiveRoutes = function * (payload, sender) {
lostLedgerLinks.push(...this.routingTables.invalidateConnectorsRoutesTo(sender, ledger))
}
}

if (payload.request_full_table) {
this.routeBroadcaster.peerEpochs[sender] = -1
}
if (routes.length === 0 && lostLedgerLinks.length === 0) { // just a heartbeat
log.info('got heartbeat from:', sender)
return
Expand Down
11 changes: 6 additions & 5 deletions src/lib/route-broadcaster.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ class RouteBroadcaster {
try {
yield this.reloadLocalRoutes()
yield this.addConfigRoutes()
this.broadcast()
this.broadcast(true)
} catch (e) {
if (e.name === 'SystemError' ||
e.name === 'ServerError') {
Expand Down Expand Up @@ -107,7 +107,7 @@ class RouteBroadcaster {
}.bind(this), this.routeBroadcastInterval)
}

broadcast () {
broadcast (requestFullTable = false) {
const adjacentLedgers = Object.keys(this.peersByLedger)
const routes = this.routingTables.toJSON(SIMPLIFY_POINTS).filter(route => {
const isPeerRoute = (route.destination_ledger.startsWith(PEER_LEDGER_PREFIX))
Expand All @@ -122,15 +122,15 @@ class RouteBroadcaster {

return Promise.all(adjacentLedgers.map((adjacentLedger) => {
const ledgerRoutes = routes.filter((route) => route.source_ledger === adjacentLedger)
return this._broadcastToLedger(adjacentLedger, ledgerRoutes, unreachableLedgers)
return this._broadcastToLedger(adjacentLedger, ledgerRoutes, unreachableLedgers, requestFullTable)
.catch((err) => {
log.warn('broadcasting routes on ledger ' + adjacentLedger + ' failed')
log.debug(err)
})
}))
}

_broadcastToLedger (adjacentLedger, routes, unreachableLedgers) {
_broadcastToLedger (adjacentLedger, routes, unreachableLedgers, requestFullTable) {
const connectors = Object.keys(this.peersByLedger[adjacentLedger])
return Promise.all(connectors.map((account) => {
log.info('broadcasting ' + routes.length + ' routes to ' + account)
Expand All @@ -152,7 +152,8 @@ class RouteBroadcaster {
data: {
new_routes: newRoutes,
hold_down_time: this.holdDownTime,
unreachable_through_me: unreachableLedgers
unreachable_through_me: unreachableLedgers,
request_full_table: requestFullTable
}
},
// timeout the plugin.sendRequest Promise just so we don't have it hanging around forever
Expand Down

0 comments on commit 2aae1ce

Please sign in to comment.