void network_throttle::tick()
{
	double time_now = get_time_seconds();
	if (!m_any_packet_yet) m_start_time = time_now; // starting now

	network_time_seconds current_sample_time_slot = time_to_slot( time_now ); // T=13.7 --> 13  (for 1-second smallwindow)
	network_time_seconds last_sample_time_slot = time_to_slot( m_last_sample_time );

	// moving to next position, and filling gaps
	// !! during this loop the m_last_sample_time and last_sample_time_slot mean the variable moved in +1
	// TODO optimize when moving few slots at once
	while ( (!m_any_packet_yet) || (last_sample_time_slot < current_sample_time_slot))
	{
		_dbg3("Moving counter buffer by 1 second " << last_sample_time_slot << " < " << current_sample_time_slot << " (last time " << m_last_sample_time<<")");
		// rotate buffer 
		for (size_t i=m_history.size()-1; i>=1; --i) m_history[i] = m_history[i-1];
		m_history[0] = packet_info();
		if (! m_any_packet_yet) 
		{
			m_last_sample_time = time_now;	
		}
		m_last_sample_time += 1;	last_sample_time_slot = time_to_slot( m_last_sample_time ); // increase and recalculate time, time slot
		m_any_packet_yet=true;
	}
	m_last_sample_time = time_now; // the real exact last time
}
示例#2
0
what_happened	typical_main_program(orders order) {
	what_happened happened{ what_happened::nothing_yet };
	try {
		try {
			happened = start_me(order); // ***
		}
		catch(const err_check_input &ex) {
			happened = what_happened::got_soft_input_error;
		}
		catch(const err_check_soft &ex) {
			happened = what_happened::got_soft_error_some_type;
		}
		_dbg3("Ok program worked");
		return happened; // program worked despite expected soft problems
	}
	catch(const std::exception &) { happened = what_happened::got_std_exception; }
	catch(const example_critical_error &) { happened = what_happened::got_critical_error; }
	catch(...) { happened = what_happened::got_unknown_exception; } // <-- rethrow if not main()
	return happened;
}
示例#3
0
void c_osi2_switch::draw_messages(c_drawtarget &drawtarget, c_layer &layer_any) const {
	_dbg3("draw message");
	auto layer = dynamic_cast<c_layer_allegro &>(layer_any);
	BITMAP *frame = layer.m_frame;
	const auto & gui = * drawtarget.m_gui;
	const int vx = gui.view_x(m_x), vy = gui.view_y(m_y); // position in viewport - because camera position
	t_geo_point send_piont, receive_point, msg_circle;
    //_dbg1(".................VX: " << vx << " ................VY: " << vy);
	for (auto &nic_ptr : m_nic) {
		std::stringstream ss;
		ss << *nic_ptr << std::endl;
		if(m_inbox.size()!=0){
            textout_ex(frame, font, ((std::string)("Data: ")).c_str(), vx+10, vy-20, makecol(255,0,0), -1);
            textout_ex(frame, font, (m_inbox.at(0).m_data).c_str(), vx+10, vy-10, makecol(0,150,255), -1);
            textout_ex(frame, font, ((std::string)("Dest addr: ")).c_str(), vx+10, vy, makecol(255,0,0), -1);
            textout_ex(frame, font, (std::to_string(m_inbox.at(0).m_dst)).c_str(), vx+10, vy+10, makecol(0,150,255), -1);
            textout_ex(frame, font, ((std::string)("Dest src: ")).c_str(), vx+10, vy+20, makecol(255,0,0), -1);
            textout_ex(frame, font, (std::to_string(m_inbox.at(0).m_src)).c_str(), vx+10, vy+30, makecol(0,150,255), -1);
	}
    }
}
示例#4
0
文件: osi2.cpp 项目: antinet/antinet
c_osi2_nic * c_osi2_nic::get_connected_card_or_null(t_osi2_cost &cost) const
{
	_dbg3("Getting connected card, of me = " << (*this) << " first getting the cable");
	if (!m_plug) {
		_dbg3("... I have no connected card (no plug)");
		return nullptr;
	}
	c_osi2_cable_direct & cable = m_plug->m_cable;
	_dbg3("My plug points to cable " << &cable);
	_dbg3("Checking cost of my cable:");
	
	cost = cable.get_cost();
	_dbg3("This cable has cost="<<cost);
	c_osi2_nic * other_nic = & cable.get_other_end(*this);
	_dbg3("This cable shows other_nic = " << other_nic);
	
	return other_nic;
}
示例#5
0
文件: osi2.cpp 项目: antinet/antinet
c_osi2_nic &c_osi2_cable_direct::get_other_end(const c_osi2_nic &other_then_me)
{
	// is this exactly this one object (not just other one that is the same)
	// compare addresses of references objects
	
	_dbg3("I am the cable in "<<this);
	_dbg3("endpoint 0 address: " << & m_endpoint[0]);
	_dbg3("endpoint 1 address: " << & m_endpoint[1]);
	
	_dbg3("endpoint 0 object: " << m_endpoint[0]);
	_dbg3("endpoint 1 object: " << m_endpoint[1]);
	
	c_osi2_nic & endA = m_endpoint[0];
	c_osi2_nic & endB = m_endpoint[1];
	
	_dbg3("endpoint A object: " << endA);
	_dbg3("endpoint B object: " << endB);
	
	if ( & endA == & other_then_me) {
		if ( & endB == & other_then_me) throw std::runtime_error("Invalid cable, both ends are me"); // assert
		return endB;
	}
	return endA;
}
示例#6
0
c_galaxysrv_peers::t_peering_reference_parse c_galaxysrv_peers::parse_peer_reference(const string & simple) const{
	// @TODO not using std::regex since it had compatibility problems. Consider using when possible (bug#J446).
	const char separator='@', group_open='(', group_close=')';
	const string literal_anyone = "anyone";
	reasonable_size(simple);

	_note("Parsing: "<<simple);
	_check_input(simple.size()>=3); // some reasonable sized not-empty string

	size_t pos1 = simple.find(separator); // was there any "@"

	if (pos1 == string::npos) { // must be one-part format "VIRTUAL" (only contains the ID/ipv6, no cables)
		vector<string> ret_id( { simple } ); // e.g. "fd42:f6c4:9d19:f128:30df:b289:aef0:25f5,score=-300"
		vector<string> ret_cable{ };
		// make sure this part does not contain ( or ) etc
		_check_input( string::npos == simple.find(group_open) );
		_check_input( string::npos == simple.find(group_close) );
		_check_input( simple.size()>0 );
		return std::make_pair(std::move(ret_id), std::move(ret_cable));
	}
	else { // format "VIRTUAL@(CABLE)" possibly with more "@(CABLE)"
		string part1 = simple.substr(0,pos1); // the VIRTUAL
		// make sure this part does not contain ( or )
		_check_input( string::npos == part1.find(group_open) );
		_check_input( string::npos == part1.find(group_close) );
		_check_input( part1.size()>0 );
		vector<string> ret_id;
		if (part1 != literal_anyone) {
			ret_id.push_back( part1 ); // e.g. "fd42:f6c4:9d19:f128:30df:b289:aef0:25f5,score=-300"
		} // else, it is 'anyone' VIRTUAL - so it is reported by empty string

		// fd42::25f5@(udp:p.meshnet.pl:9042,cost=500)@(shm:test)@(tcp:[fe80::d44e]:9042)
		//             B
		//             B.............................X
		//                                           X@(B
		//                                              B.......X@
		//                                                      X@(B
		//                                                         B.....................end

		vector<string> ret_cable;
		// will parse additional groups "@(....)" selecting their index posB...posX
		const size_t size = simple.size(), size_before=size-1; _check(size_before < size);
		_check_input(pos1+2 < size);
		_check_input(simple.at(pos1+0)==separator);  // theck the '@' out of "@(" that we just found
		_check_input(simple.at(pos1+1)==group_open); // theck the '(' out of "@(" that we just found
		size_t posB = pos1+2; // begin, poiting after "@("
		_info(join_string_sep(posB," < ",size));
		while (posB < size_before) {
			auto posX = simple.find(group_close,posB); // find ")"
			_dbg3("posX=" << posX << " posB="<<posB);
			if (posX == string::npos) {
				_info("Hit end because posX="<<posX);
				posX = size_before;
			}
			string partX = simple.substr(posB, posX-posB);
			_dbg3("posX=" << posX << " posB="<<posB<<" given " <<partX);
			// make sure this part does not contain ( or ), e.g. "CABLE(" as result of parsing "VIRTUAL@(CABLE(CABLE)"
			_check_input( string::npos == partX.find(group_open) );
			_check_input( string::npos == partX.find(group_close) );
			_check_input( partX.size()>0 );

			ret_cable.push_back( std::move(partX) );
			posB=posX;
			_check_input(simple.at(posB)==group_close); // ")"
			++posB;
			if (!(posB<size)) break; // end is possible after last "....@(...)"
			// otherwise we open new group:
			_check_input(simple.at(posB)==separator); // ")@"
			++posB;
			_check_input(simple.at(posB)==group_open); // ")@(" after this
			++posB;
		}
		return std::make_pair(std::move(ret_id), std::move(ret_cable));
	} // other format
}
示例#7
0
void c_object::draw_opengl(c_drawtarget &drawtarget, c_layer &layer) {
	_dbg3("Drawing (opengl) object (base method used)");
}
示例#8
0
void c_object::draw_allegro(c_drawtarget &drawtarget, c_layer &layer) {
	_dbg3("Drawing (allegro) object (base method used)");
}