From 8d7f3943bbb0ab8933d6e950fa142dd06e5d080b Mon Sep 17 00:00:00 2001 From: Olaoluwa Osuntokun Date: Tue, 10 Oct 2017 19:45:38 -0700 Subject: [PATCH] routing: add two new methods to filter routes based on node/channel --- routing/router.go | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/routing/router.go b/routing/router.go index 291fd2210..06be0b310 100644 --- a/routing/router.go +++ b/routing/router.go @@ -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.