bool Context::process_object(Object *o, Sources &sset, std::vector<source_t> &lsources, unsigned n) {
    typedef typename std::map<typename Sources::key_type, unsigned> stats_type;
    stats_type sources_stats;

    for(typename Sources::iterator j = sset.begin(); j != sset.end(); ) {
        const typename Sources::key_type &name = j->first;
        Source *s = j->second;
        if (!s->playing()) {
            //LOG_DEBUG(("purging inactive source %s", j->first.c_str()));
            delete j->second;
            sset.erase(j++);
            continue;
        }

        typename stats_type::iterator s_i = sources_stats.find(name);
        unsigned same_sounds_n = (s_i != sources_stats.end())? s_i->second: 0;
        if (lsources.size() < max_sources && same_sounds_n < distance_model.same_sounds_limit) {
            lsources.push_back(source_t(s, _listener->transform(o->_position + s->delta_position), o->_velocity, _listener->_velocity));
            if (same_sounds_n == 0) {
                sources_stats.insert(typename stats_type::value_type(name, 1));
            } else {
                ++s_i->second;
            }
            //LOG_DEBUG(("%u: source: %s", (unsigned)lsources.size(), name.c_str()));
        } else {
            s->_update_position(n);
        }
        ++j;
    }

    if (sset.empty() && o->dead)
        return false;

    return true;
}
Beispiel #2
0
beaconSource &getSource(const address &baddr, const char *name, uint64_t now, uint64_t recvdts, bool rx_local) {
	Sources::iterator i = sources.find(baddr);
	if (i != sources.end()) {
		i->second.lastevent = now;
		if (rx_local)
			i->second.lastlocalevent = now;
		return i->second;
	}

	beaconSource &src = sources[baddr];

	if (verbose) {
		char tmp[64];

		if (name)
			info("Adding source %s [%s]", baddr.to_string(tmp, sizeof(tmp)), name);
		else
			info("Adding source %s", baddr.to_string(tmp, sizeof(tmp)));
	}

	if (name)
		src.setName(name);

	src.creation = now;
	src.lastevent = now;
	if (rx_local)
		src.lastlocalevent = now;

	if (IsSSMEnabled())
		CountSSMJoin(ssmProbeAddr, baddr);

	return src;
}
Beispiel #3
0
void handle_gc() {
	uint64_t now = get_timestamp();

	Sources::iterator i = sources.begin();
	while (i != sources.end()) {
		Sources::iterator k = i;
		i++;

		if (isStillValid(now, k->second.lastevent)) {
			k->second.ASM.s.check_validity(now);
			k->second.SSM.s.check_validity(now);

			beaconSource::ExternalSources::iterator j = k->second.externalSources.begin();
			while (j != k->second.externalSources.end()) {
				beaconSource::ExternalSources::iterator m = j;
				j++;

				if (isStillValid(now, m->second.lastupdate)) {
					m->second.ASM.check_validity(now);
					m->second.SSM.check_validity(now);
				} else {
					k->second.externalSources.erase(m);
				}
			}
		} else {
			removeSource(k->first, true);
		}
	}
}
Beispiel #4
0
void removeSource(const address &baddr, bool timeout) {
	Sources::iterator i = sources.find(baddr);
	if (i != sources.end()) {
		if (verbose) {
			char tmp[64];

			if (i->second.identified) {
				info("Removing source %s [%s]%s",
					baddr.to_string(tmp, sizeof(tmp)), i->second.name.c_str(),
					(timeout ? " by Timeout" : ""));
			} else {
				info("Removing source %s%s",
					baddr.to_string(tmp, sizeof(tmp)), (timeout ? " by Timeout" : ""));
			}
		}

		if (IsSSMEnabled())
			CountSSMLeave(ssmProbeAddr, baddr);

		sources.erase(i);
	}
}
Beispiel #5
0
void do_dump() {
	string tmpf = dumpFile;
	tmpf += ".working";

	FILE *fp = fopen(tmpf.c_str(), "w");
	if (!fp)
		return;

	uint64_t now = get_timestamp();
	uint64_t diff = now - lastDumpDumpBwTS;
	lastDumpDumpBwTS = now;

	double rxRate = dumpBytesReceived * 8 / ((double)diff);
	double txRate = dumpBytesSent * 8 / ((double)diff);
	dumpBytesReceived = 0;
	dumpBytesSent = 0;

	fprintf(fp, "<beacons rxrate=\"%.2f\" txrate=\"%.2f\" versioninfo=\"%s\">\n", rxRate, txRate, versionInfo);

	fprintf(fp, "<group addr=\"%s\"", sessionName);

	char tmp[64];

	if (IsSSMEnabled())
		fprintf(fp, " ssmgroup=\"%s\"", ssmProbeAddr.to_string(tmp, sizeof(tmp)));

	fprintf(fp, " int=\"%.2f\">\n", beacInt);

	if (!probeAddr.is_unspecified()) {
		fprintf(fp, "\t<beacon name=\"%s\" addr=\"%s\"", beaconName.c_str(),
				beaconUnicastAddr.to_string(tmp, sizeof(tmp)));
		if (!adminContact.empty())
			fprintf(fp, " contact=\"%s\"", adminContact.c_str());
		if (!twoLetterCC.empty())
			fprintf(fp, " country=\"%s\"", twoLetterCC.c_str());
		fprintf(fp, " age=\"%lu\" lastupdate=\"0\" rxlocal=\"true\">\n", (now - startTime) / 1000);

		for (uint32_t k = 0; k < KnownFlags; k++) {
			if (flags & (1 << k)) {
				fprintf(fp, "\t\t<flag name=\"%s\" value=\"true\" />\n", Flags[k]);
			}
		}

		for (WebSites::const_iterator j = webSites.begin(); j != webSites.end(); j++) {
			const char *typnam = j->first == T_WEBSITE_GENERIC ?
				"generic" : (j->first == T_WEBSITE_LG ? "lg" : "matrix");
			fprintf(fp, "\t\t<website type=\"%s\" url=\"%s\" />\n", typnam, j->second.c_str());
		}

		fprintf(fp, "\t\t<sources>\n");

		for (Sources::const_iterator i = sources.begin(); i != sources.end(); i++) {
			fprintf(fp, "\t\t\t<source addr=\"%s\"", i->first.to_string(tmp, sizeof(tmp)));
			if (i->second.identified) {
				fprintf(fp, " name=\"%s\"", i->second.name.c_str());
				if (!i->second.adminContact.empty())
					fprintf(fp, " contact=\"%s\"", i->second.adminContact.c_str());
			}

			if (!i->second.CC.empty())
				fprintf(fp, " country=\"%s\"", i->second.CC.c_str());

			fprintf(fp, " age=\"%lu\"", (now - i->second.creation) / 1000);
			fprintf(fp, " lastupdate=\"%lu\">\n", (now - i->second.lastevent) / 1000);

			if (i->second.ASM.s.valid)
				dumpStats(fp, "asm", i->second.ASM.s, now, i->second.sttl, true);

			if (i->second.SSM.s.valid)
				dumpStats(fp, "ssm", i->second.SSM.s, now, i->second.sttl, true);

			fprintf(fp, "\t\t\t</source>\n");
		}

		fprintf(fp, "\t\t</sources>\n");
		fprintf(fp, "\t</beacon>\n");
		fprintf(fp, "\n");
	}

	for (Sources::const_iterator i = sources.begin(); i != sources.end(); i++) {
		fprintf(fp, "\t<beacon");
		if (i->second.identified) {
			fprintf(fp, " name=\"%s\"", i->second.name.c_str());
			if (!i->second.adminContact.empty())
				fprintf(fp, " contact=\"%s\"", i->second.adminContact.c_str());
		}
		fprintf(fp, " addr=\"%s\"", i->first.to_string(tmp, sizeof(tmp)));
		fprintf(fp, " age=\"%lu\"", (now - i->second.creation) / 1000);
		fprintf(fp, " rxlocal=\"%s\"", i->second.rxlocal(now) ? "true" : "false");
		fprintf(fp, " lastupdate=\"%lu\">\n", (now - i->second.lastevent) / 1000);

		for (uint32_t k = 0; k < KnownFlags; k++) {
			if (i->second.Flags & (1 << k)) {
				fprintf(fp, "\t\t<flag name=\"%s\" value=\"true\" />\n", Flags[k]);
			}
		}

		for (WebSites::const_iterator j = i->second.webSites.begin();
						j != i->second.webSites.end(); j++) {
			const char *typnam = j->first == T_WEBSITE_GENERIC ?
				"generic" : (j->first == T_WEBSITE_LG ? "lg" : "matrix");
			fprintf(fp, "\t\t<website type=\"%s\" url=\"%s\" />\n",
						typnam, j->second.c_str());
		}

		fprintf(fp, "\t\t<sources>\n");

		for (beaconSource::ExternalSources::const_iterator j = i->second.externalSources.begin();
				j != i->second.externalSources.end(); j++) {
			fprintf(fp, "\t\t\t<source");
			if (j->second.identified) {
				fprintf(fp, " name=\"%s\"", j->second.name.c_str());
				fprintf(fp, " contact=\"%s\"", j->second.contact.c_str());
			}
			fprintf(fp, " addr=\"%s\"", j->first.to_string(tmp, sizeof(tmp)));
			fprintf(fp, " age=\"%u\">\n", j->second.age);
			if (j->second.ASM.valid)
				dumpStats(fp, "asm", j->second.ASM, now, i->second.sttl, false);
			if (j->second.SSM.valid)
				dumpStats(fp, "ssm", j->second.SSM, now, i->second.sttl, false);
			fprintf(fp, "\t\t\t</source>\n");
		}

		fprintf(fp, "\t\t</sources>\n");
		fprintf(fp, "\t</beacon>\n");
	}

	fprintf(fp, "</group>\n</beacons>\n");

	fclose(fp);

	rename(tmpf.c_str(), dumpFile.c_str());

	if (!launchSomething.empty())
		doLaunchSomething();
}