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 authored and michielbdejong committed Aug 17, 2017
1 parent 74959dc commit 7e4189d
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 10 deletions.
4 changes: 4 additions & 0 deletions schemas/RoutingUpdate.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@
"$ref": "IlpAddress.json"
}
},
"request_full_table": {
"description": "On this route broadcast, piggy-back a request for the other peer to send their full table in *their* next route broadcast",
"type": "boolean"
},
"new_routes": {
"description": "A list of Routes that have been added to the sending connector's table since the last update it has sent you. May replace previously broadcast routes.",
"$ref": "Routes.json"
Expand Down
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
14 changes: 10 additions & 4 deletions test/routeBroadcasterSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,7 @@ describe('RouteBroadcaster', function () {
data:
{ hold_down_time: 1234,
unreachable_through_me: [],
request_full_table: false,
new_routes: routesWithSourceLedgerA } },
timeout: undefined
})
Expand All @@ -223,6 +224,7 @@ describe('RouteBroadcaster', function () {
data:
{ hold_down_time: 1234,
unreachable_through_me: [],
request_full_table: false,
new_routes: routesWithSourceLedgerB } },
timeout: undefined
})
Expand Down Expand Up @@ -255,13 +257,15 @@ describe('RouteBroadcaster', function () {
yield messageRouter.receiveRoutes({
new_routes: newRoutes,
hold_down_time: 1234,
unreachable_through_me: []
unreachable_through_me: [],
request_full_table: false
}, ledgerB + 'mark')
assert.equal(this.tables.toJSON(2).length, 5)
yield messageRouter.receiveRoutes({
new_routes: [],
hold_down_time: 1234,
unreachable_through_me: [ledgerD]
unreachable_through_me: [ledgerD],
request_full_table: false
}, ledgerB + 'mark')
assert.equal(this.tables.toJSON(2).length, 4)
})
Expand All @@ -284,7 +288,8 @@ describe('RouteBroadcaster', function () {
yield messageRouter.receiveRoutes({
new_routes: newRoutes,
hold_down_time: 1234,
unreachable_through_me: []
unreachable_through_me: [],
request_full_table: false
}, ledgerB + 'mark')
assert.equal(this.tables.toJSON(2).length, 4)
})
Expand All @@ -307,7 +312,8 @@ describe('RouteBroadcaster', function () {
yield messageRouter.receiveRoutes({
new_routes: newRoutes,
hold_down_time: 1234,
unreachable_through_me: []
unreachable_through_me: [],
request_full_table: false
}, ledgerB + 'mark')
assert.equal(this.tables.toJSON(2).length, 4)
})
Expand Down

0 comments on commit 7e4189d

Please sign in to comment.