Esempio n. 1
0
    expr visit(expr const & e) {
        switch (e.kind()) {
        case expr_kind::Sort:  case expr_kind::Constant:
        case expr_kind::Var:   case expr_kind::Meta:
        case expr_kind::Local:
            return e;
        default:
            break;
        }

        check_system("unfold macros");
        auto it = m_cache.find(e);
        if (it != m_cache.end())
            return it->second;

        switch (e.kind()) {
        case expr_kind::Sort:  case expr_kind::Constant:
        case expr_kind::Var:   case expr_kind::Meta:
        case expr_kind::Local:
            lean_unreachable();
        case expr_kind::Macro:
            return save_result(e, visit_macro(e));
        case expr_kind::App:
            return save_result(e, visit_app(e));
        case expr_kind::Lambda: case expr_kind::Pi:
            return save_result(e, visit_binding(e));
        }
        lean_unreachable();
    }
Esempio n. 2
0
void aggr_source_discovery::dump_cache(base_stream &out, const cache &c) const {
	time_t now = time(0);

	for (cache::const_iterator i = c.begin(); i != c.end(); ++i) {
		out.xprintf("(%{Addr}, %{Addr}) for %{duration}\n",
			    i->first.second, i->first.first,
			    time_duration((now - i->second) * 1000));
	}
}
Esempio n. 3
0
void aggr_source_discovery::run_gc(cache &c) {
	time_t now = time(0);

	cache::iterator i = c.begin();

	while (i != c.end()) {
		cache::iterator j = i;
		++i;

		if ((now - j->second) > m_keepalive) {
			if (g_mrd->should_log(INTERNAL_FLOW)) {
				g_mrd->log().xprintf("AggrSourceDiscovery "
					"cleaned source (%{Addr}, %{Addr}).\n",
					j->first.second, j->first.first);
			}

			c.erase(j);
		}
	}
}
Esempio n. 4
0
int aggr_source_discovery::add_to_cache(cache &c, int ifindex,
					const inet6_addr &group,
					const inet6_addr &src) {
	sg_pair p(group, src);

	cache::iterator i = c.find(p);

	time_t now = time(0);

	if (i == c.end()) {
		c.insert(std::make_pair(p, now));

		if (g_mrd->should_log(INTERNAL_FLOW)) {
			g_mrd->log().xprintf("AggrSourceDiscovery added source"
					     " (%{Addr}, %{Addr}) to cache.\n",
					     src, group);
		}

		return 1;
	} else {
		if ((now - i->second) > m_keepalive) {
			if (g_mrd->should_log(INTERNAL_FLOW)) {
				g_mrd->log().xprintf("AggrSourceDiscovery "
						     "updated source (%{Addr},"
						     "%{Addr}), cache was old.\n",
						     src, group);
			}

			/* was in the cache but is old */
			source_discovery_origin::discovered_source(ifindex, group, src);

			return 0;
		}

		i->second = now;
	}

	return -1;
}