routing: add two new methods to filter routes based on node/channel

This commit is contained in:
Olaoluwa Osuntokun 2017-10-10 19:45:38 -07:00
parent f6ac31281b
commit 8d7f3943bb
No known key found for this signature in database
GPG Key ID: 964EA263DD637C21
1 changed files with 40 additions and 0 deletions

View File

@ -886,6 +886,46 @@ type routingMsg struct {
err chan error
}
// pruneNodeFromRoutes accepts set of routes, and returns a new set of routes
// with the target node filtered out.
func pruneNodeFromRoutes(routes []*Route, skipNode vertex) []*Route {
// TODO(roasbeef): pass in slice index?
prunedRoutes := make([]*Route, 0, len(routes))
for _, route := range routes {
if route.containsNode(skipNode) {
continue
}
prunedRoutes = append(prunedRoutes, route)
}
log.Tracef("Filtered out %v routes with node %x",
len(routes)-len(prunedRoutes), skipNode[:])
return prunedRoutes
}
// pruneChannelFromRoutes accepts a set of routes, and returns a new set of
// routes with the target channel filtered out.
func pruneChannelFromRoutes(routes []*Route, skipChan uint64) []*Route {
prunedRoutes := make([]*Route, 0, len(routes))
for _, route := range routes {
if route.containsChannel(skipChan) {
continue
}
prunedRoutes = append(prunedRoutes, route)
}
log.Tracef("Filtered out %v routes with channel %v",
len(routes)-len(prunedRoutes), skipChan)
return prunedRoutes
}
// FindRoutes attempts to query the ChannelRouter for the all available paths
// to a particular target destination which is able to send `amt` after
// factoring in channel capacities and cumulative fees along each route route.