Esempio n. 1
0
static void on_session_established(const std::string& name, fscp::server& server, const fscp::server::ep_type& host, bool is_new, const fscp::cipher_suite_type& cs, const fscp::elliptic_curve_type& ec)
{
	mutex::scoped_lock lock(output_mutex);

	std::cout << "[" << name << "] Session established with " << host << std::endl;
	std::cout << "[" << name << "] New session: " << is_new << std::endl;
	std::cout << "[" << name << "] Cipher suite: " << cs << std::endl;
	std::cout << "[" << name << "] Elliptic curve: " << ec << std::endl;

	static const std::string HELLO = "Hello you !";

	server.async_send_data(host, fscp::CHANNEL_NUMBER_3, boost::asio::buffer(HELLO), boost::bind(&simple_handler, name, "async_send_data()", _1));

	if (name == "alice")
	{
		using cryptoplus::file;

		cryptoplus::x509::certificate cert = cryptoplus::x509::certificate::from_certificate(file::open("chris.crt", "r"));

		fscp::hash_list_type hash_list;
		hash_list.insert(fscp::get_certificate_hash(cert));

		server.async_send_contact_request(host, hash_list, boost::bind(&simple_handler, name, "async_send_contact_request()", _1));
	}
}
Esempio n. 2
0
static void on_data(const std::string& name, fscp::server& server, const fscp::server::ep_type& sender, fscp::channel_number_type channel_number, fscp::server::shared_buffer_type, boost::asio::const_buffer data)
{
	static_cast<void>(server);

	static std::atomic<int> send_counter;

	if (channel_number == fscp::CHANNEL_NUMBER_3) {
		const std::string str_data(boost::asio::buffer_cast<const char*>(data), boost::asio::buffer_size(data));

		mutex::scoped_lock lock(output_mutex);

		std::cout << "[" << name << "] Received DATA on channel " << static_cast<unsigned int>(channel_number) << " from " << sender << ": " << str_data << std::endl;

	} else if (channel_number == fscp::CHANNEL_NUMBER_4) {

		const int receive_counter = *boost::asio::buffer_cast<const int*>(data);

		mutex::scoped_lock lock(output_mutex);

		std::cout << "[" << name << "] Received DATA on channel " << static_cast<unsigned int>(channel_number) << " from " << sender << ": #" << receive_counter << std::endl;
	}

	if ((name == "alice") || (name == "chris")) {
		const boost::shared_ptr<int> local_counter(new int(send_counter++));

		server.async_send_data(
			sender,
			fscp::CHANNEL_NUMBER_4,
			boost::asio::buffer(local_counter.get(), sizeof(int)),
			[name, local_counter](const boost::system::error_code& ec) {
				simple_handler(name, "async_send_data()", ec);
			}
		);
	}
}
Esempio n. 3
0
static bool on_session(const std::string& name, fscp::server& server, const fscp::server::ep_type& sender, bool default_accept)
{
	std::cout << "[" << name << "] Received SESSION from " << sender << std::endl;

	server.async_send_data(sender, fscp::CHANNEL_NUMBER_3, boost::asio::buffer(std::string("Hello ! I'm " + name)));

	return default_accept;
}