void PacketLengthCovertChannel::sendMessage(std::string message){
		std::vector<unsigned int> packetLengths = m_coder->encodeMessage(message);
		m_send(m_get_packet(8 + m_baselength + packetLengths.size()));
		for (unsigned int i = 0; i < packetLengths.size(); i++){
			m_send(m_get_packet(packetLengths[i]));
		}
	}
Exemplo n.º 2
0
	void TimingCovertChannel::sendDelays(vector<unsigned int> delays) {
		m_mutex_sending.lock();
		chrono::time_point<chrono::system_clock> sending_time;
		m_send(m_getPacket(port()));
		chrono::time_point<chrono::system_clock> start = chrono::system_clock::now();
		for (vector<unsigned int>::iterator it = delays.begin(); it != delays.end(); it++) {
			UdpPacket packet = m_getPacket(port());
			sending_time = start + chrono::milliseconds(*it);
			this_thread::sleep_until(sending_time);
			m_send(packet);
			start = chrono::system_clock::now();
		}
		this_thread::sleep_for(chrono::milliseconds(m_timeout));
		m_mutex_sending.unlock();
	}
Exemplo n.º 3
0
void node_impl::incoming_request(const kad2_bootstrap_req& req, udp::endpoint target) {
    kad2_bootstrap_res p;
    p.client_info.kid = m_id;
    p.client_info.tcp_port = 4661;
    p.client_info.version = KADEMLIA_VERSION;
    udp_message msg = make_udp_message(p);
    m_send(m_userdata, msg, target, 0);
}
Exemplo n.º 4
0
void node_impl::incoming_request(const kademlia2_req& req, udp::endpoint target) {
    kademlia2_res p;
    int count = req.search_type;
    std::vector<node_entry> res;
    m_table.find_node(req.kid_target, res, routing_table::include_failed, count);
    std::transform(res.begin(), res.end(), std::back_inserter(p.results.m_collection), boost::bind(&entry_to_emule, _1));
    udp_message msg = make_udp_message(p);
    m_send(m_userdata, msg, target, 0);
}
Exemplo n.º 5
0
void node_impl::incoming_request(const kad2_hello_req& req, udp::endpoint target) {
    kad2_hello_res p;
    p.client_info.kid = m_id;
    p.client_info.tcp_port = m_port;
    p.client_info.version = KADEMLIA_VERSION;
    udp_message msg = make_udp_message(p);
    m_send(m_userdata, msg, target, 0);
    // try to add node to our table - will add if it is new node
    add_node(target, req.client_info.kid);
}
Exemplo n.º 6
0
Arquivo: friend.c Projeto: fbbs/fbbs
static tui_list_handler_t following_list_handler(tui_list_t *p, int key)
{
	switch (key) {
		case 'a':
			if (tui_follow() > 0)
				p->valid = false;
			else
				return MINIUPDATE;
			break;
		case 'd':
			if (tui_unfollow(following_list_get_id(p->data, p->cur)) > 0)
				p->valid = false;
			else
				return MINIUPDATE;
			break;
		case 'm':
			m_send(following_list_get_name(p->data, p->cur));
			break;
		case 'E':
			if (tui_edit_followed_note(following_list_get_id(p->data, p->cur),
						following_list_get_notes(p->data, p->cur)) == DONOTHING ) {
				return MINIUPDATE;
			} else {
				p->valid = false;
			}
			break;
		case KEY_RIGHT:
		case '\r':
		case '\n':
			following_list_query(p);
			return DONOTHING;
		case 'h':
			show_help("help/friendshelp");
			return FULLUPDATE;
		default:
			return READ_AGAIN;
	}
	return DONOTHING;
}
Exemplo n.º 7
0
bool rpc_manager::invoke(entry& e, udp::endpoint target_addr
	, observer_ptr o)
{
	INVARIANT_CHECK;

	if (m_destructing) return false;

	e["y"] = "q";
	entry& a = e["a"];
	add_our_id(a);

	std::string transaction_id;
	transaction_id.resize(2);
	char* out = &transaction_id[0];
	int tid = rand() ^ (rand() << 5);
	io::write_uint16(tid, out);
	e["t"] = transaction_id;
		
	o->set_target(target_addr);
	o->set_transaction_id(tid);

#ifdef TORRENT_DHT_VERBOSE_LOGGING
	TORRENT_LOG(rpc) << "[" << o->m_algorithm.get() << "] invoking "
		<< e["q"].string() << " -> " << target_addr;
#endif

	if (m_send(m_userdata, e, target_addr, 1))
	{
		m_transactions.push_back(o);
#if defined TORRENT_DEBUG || TORRENT_RELEASE_ASSERTS
		o->m_was_sent = true;
#endif
		return true;
	}
	return false;
}
Exemplo n.º 8
0
Arquivo: online.c Projeto: fbbs/fbbs
static tui_list_handler_t online_users_handler(tui_list_t *p, int ch)
{
	online_users_t *up = p->data;
	online_user_info_t *ip = up->users + p->cur;
	p->valid = false;

	char buf[STRLEN];
	switch (ch) {
		case 'h': case 'H':
			show_help("help/userlisthelp");
			return FULLUPDATE;
		case 'm': case 'M':
			if (!HAS_PERM(PERM_MAIL))
				return DONOTHING;
			m_send(ip->name);
			return FULLUPDATE;
		case 's': case 'S':
			if (streq(currentuser.userid, "guest") || !HAS_PERM(PERM_TALK)
					|| !session_msgable(ip))
				return DONOTHING;
			tui_send_msg(ip->name);
			return FULLUPDATE;
		case 'o': case 'O':
			return tui_follow_uname(ip->name);
		case 'd': case 'D':
			if (streq(currentuser.userid, "guest"))
				return DONOTHING;
			//% "确定不再关注 %s 吗?"
			snprintf(buf, sizeof(buf), "\xc8\xb7\xb6\xa8\xb2\xbb\xd4\xd9"
					"\xb9\xd8\xd7\xa2 %s \xc2\xf0?", ip->name);
			if (!askyn(buf, false, true))
				return MINIUPDATE;
			{
				user_id_t uid = get_user_id(ip->name);
				if (uid > 0 && unfollow(session_get_user_id(), uid)) {
					//% "已取消关注 %s"
					snprintf(buf, sizeof(buf), "\xd2\xd1\xc8\xa1\xcf\xfb"
							"\xb9\xd8\xd7\xa2 %s", ip->name);
					presskeyfor(buf, -1);
					return PARTUPDATE;
				}
			}		
			return MINIUPDATE;
	}
	if (p->in_query)
		return READ_AGAIN;

	switch (ch) {
		case 'Y':
			if (HAS_PERM(PERM_CLOAK)) {
				x_cloak();
				up->uptime = 0;
				return PARTUPDATE;
			}
			return DONOTHING;
		case 'C': case 'c':
			return alter_nick(up);
		case 'k': case 'K':
			return kick_out(up, ip);
		case 'f': case 'F':
			up->follow = !up->follow;
			if (up->follow)
				set_user_status(ST_FRIEND);
			else
				set_user_status(ST_LUSERS);
			up->uptime = 0;
			return FULLUPDATE;
		case 'W': case 'w':
			if (streq(currentuser.userid, "guest"))
				return DONOTHING;
			up->show_note = !up->show_note;
			return PARTUPDATE;
#if 0
		case KEY_TAB:	
			if (HAS_PERM(PERM_OCHAT)) {
				if (++(up->sort) > USRSORT_STATUS)
					up->sort = USRSORT_USERID;
				up->uptime = 0;
				return FULLUPDATE;
			}
			return DONOTHING;
#endif
		case '\r': case '\n': case KEY_RIGHT:
			online_users_query(p);
			return DONOTHING;
		default:
			return READ_AGAIN;
	}
}
Exemplo n.º 9
0
	void m_bang() { m_send(true); }
Exemplo n.º 10
0
bool rpc_manager::incoming(msg const& m, node_id* id)
{
	INVARIANT_CHECK;

	if (m_destructing) return false;

	// we only deal with replies, not queries
	TORRENT_ASSERT(m.message.dict_find_string_value("y") == "r");

	// if we don't have the transaction id in our
	// request list, ignore the packet

	std::string transaction_id = m.message.dict_find_string_value("t");

	std::string::const_iterator i = transaction_id.begin();	
	int tid = transaction_id.size() != 2 ? -1 : io::read_uint16(i);

	observer_ptr o;

	for (transactions_t::iterator i = m_transactions.begin()
		, end(m_transactions.end()); i != end; ++i)
	{
		TORRENT_ASSERT(*i);
		if ((*i)->transaction_id() != tid) continue;
		if (m.addr.address() != (*i)->target_addr()) continue;
		o = *i;
		m_transactions.erase(i);
		break;
	}

	if (!o)
	{
#ifdef TORRENT_DHT_VERBOSE_LOGGING
		TORRENT_LOG(rpc) << "Reply with invalid transaction id size: " 
			<< transaction_id.size() << " from " << m.addr;
#endif
		entry e;
		incoming_error(e, "invalid transaction id");
		m_send(m_userdata, e, m.addr, 0);
		return false;
	}

#ifdef TORRENT_DHT_VERBOSE_LOGGING
	std::ofstream reply_stats("round_trip_ms.log", std::ios::app);
	reply_stats << m.addr << "\t" << total_milliseconds(time_now_hires() - o->sent())
		<< std::endl;
#endif

	lazy_entry const* ret_ent = m.message.dict_find_dict("r");
	if (ret_ent == 0)
	{
		entry e;
		incoming_error(e, "missing 'r' key");
		m_send(m_userdata, e, m.addr, 0);
		return false;
	}

	lazy_entry const* node_id_ent = ret_ent->dict_find_string("id");
	if (node_id_ent == 0 || node_id_ent->string_length() != 20)
	{
		entry e;
		incoming_error(e, "missing 'id' key");
		m_send(m_userdata, e, m.addr, 0);
		return false;
	}

	lazy_entry const* ext_ip = ret_ent->dict_find_string("ip");
	if (ext_ip && ext_ip->string_length() == 4)
	{
		// this node claims we use the wrong node-ID!
		address_v4::bytes_type b;
		memcpy(&b[0], ext_ip->string_ptr(), 4);
		m_ext_ip(address_v4(b), aux::session_impl::source_dht, m.addr.address());
	}
#if TORRENT_USE_IPV6
	else if (ext_ip && ext_ip->string_length() == 16)
	{
		// this node claims we use the wrong node-ID!
		address_v6::bytes_type b;
		memcpy(&b[0], ext_ip->string_ptr(), 16);
		m_ext_ip(address_v6(b), aux::session_impl::source_dht, m.addr.address());
	}
#endif

#ifdef TORRENT_DHT_VERBOSE_LOGGING
	TORRENT_LOG(rpc) << "[" << o->m_algorithm.get() << "] Reply with transaction id: " 
		<< tid << " from " << m.addr;
#endif
	o->reply(m);
	*id = node_id(node_id_ent->string_ptr());

	// we found an observer for this reply, hence the node is not spoofing
	// add it to the routing table
	return m_table.node_seen(*id, m.addr);
}
Exemplo n.º 11
0
/**
 * Send a POST request.
 */
bool ESP_RestClient::post(const char *payload) {
	m_commandType = POST;
	return m_send(payload);
} // End of post
Exemplo n.º 12
0
/**
 * Send a GET request.
 */
bool ESP_RestClient::get() {
	m_commandType = GET;
	return m_send(NULL);
} // End of get
Exemplo n.º 13
0
void node_impl::incoming_request(const kad_firewalled_req& req, udp::endpoint target) {
    kad_firewalled_res p;
    p.ip = address2int(target.address());
    udp_message msg = make_udp_message(p);
    m_send(m_userdata, msg, target, 0);
}
Exemplo n.º 14
0
void node_impl::incoming_request(const kad2_ping& req, udp::endpoint target) {
    kad2_pong p;
    p.udp_port = m_port;
    udp_message msg = make_udp_message(p);
    m_send(m_userdata, msg, target, 0);
}