Skip to content

Instantly share code, notes, and snippets.

@gorgonical
Created February 9, 2017 17:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gorgonical/3308d405ccbbc3279c7576e7c7678d7d to your computer and use it in GitHub Desktop.
Save gorgonical/3308d405ccbbc3279c7576e7c7678d7d to your computer and use it in GitHub Desktop.
...
if (route != m_routes.end()) {
NFD_LOG_DEBUG("Attempting to withdraw a route with FaceId: " << routeRef.route->faceId
<< " and origin " << routeRef.route->origin);
// Because they are const in the container, and we can't have a meaningful copy constructor
// because of ScopedEventId, I'm not entirely sure what to do here. Should I pop from the
// container using move semantics?
ReadvertisedRoute* tempRoute = const_cast<ReadvertisedRoute*>(&(*route));
tempRoute->removeRoute(routeRef);
m_routes.replace(route, *tempRoute);
if (tempRoute->getRibRoutes().empty()) {
// Since this call here asks for a ReadvertisedRoute&, but the container only gives us
// const ReadvertisedRoutes&, I don't know how to approach this.
m_destination->withdraw(*route,
[this] {
this->onRouteWithdrawSuccess();
},
[&, this] (const std::string& msg) {
this->onRouteWithdrawFailure(msg, *route,
READVERTISE_DEFAULT_RETRY_BASE_WAIT,
READVERTISE_DEFAULT_RETRY_MAX_WAIT);
});
NFD_LOG_DEBUG("Deleting route: " << route->getPrefix() << " from a readvertise instance.");
m_routes.erase(route);
}
...
class ReadvertisedRoute {
...
public:
const Name m_prefix;
// This is necessary because I could not find a way to make the container
// a friend, and couldn't understand why const_mem_fun for getPrefix wasn't working.
// This was the closest solution that preserves the semantics
}
// Using a unique (ordered is unimportant) index as a member pretty closely mimics the map<Name, ReadvertisedRoute>
// we were using from before.
typedef boost::multi_index_container<
ReadvertisedRoute,
boost::multi_index::indexed_by<
boost::multi_index::ordered_unique<boost::multi_index::member<ReadvertisedRoute, const ndn::Name,
&ReadvertisedRoute::m_prefix>>
>
> route_container;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment