void server::handle_request(boost::asio::ip::tcp::socket& socket,
	const request& req, reply& rep)
{
	using namespace boost::posix_time;
	
	detail::s_log.reset(new ostringstream);
	ptime start = second_clock::local_time();
	
	try
	{
		handle_request(req, rep);
	}
	catch (...)
	{
		rep = reply::stock_reply(internal_server_error);
	}

	// protect the output stream from garbled log messages
	boost::mutex::scoped_lock lock(detail::s_log_lock);
	cout << socket.remote_endpoint().address()
		 << " [" << start << "] "
		 << second_clock::local_time() - start << ' '
		 << rep.status << ' '
		 << detail::s_log->str() << endl;
}
bool TcpProxyServer::GetRemoteAddressAndPort(boost::asio::ip::tcp::socket& clientSocket, boost::asio::ip::address& remoteAddress, unsigned short& remotePort)
{
	boost::asio::ip::tcp::socket::endpoint_type userAgentEnpoint = clientSocket.remote_endpoint();
    unsigned short userAgentPort = userAgentEnpoint.port();
	boost::asio::ip::address userAgentIP = userAgentEnpoint.address();
	if(userAgentIP != boost::asio::ip::address_v4::from_string("127.0.0.1")) {
		return false;
	}

	std::pair<u_long, USHORT> remoteAddressPair = WinsockHooker::GetRemoteAddressPair(userAgentPort);
	
	if(remoteAddressPair.first == 0ul) {
		return false;
	}

	boost::asio::ip::address_v4 remote_address(remoteAddressPair.first);
	unsigned short remote_port = remoteAddressPair.second;
	if(remote_address == boost::asio::ip::address_v4::from_string("127.0.0.1") && remote_port == listen_port)
	{
		return false;
	}
	remoteAddress = remote_address;
	remotePort = remote_port;

	TSINFO4CXX("Connect: IP:" << remoteAddress.to_string() << ", Port: " << remotePort);
	return true;
}
Beispiel #3
0
 void on_connect(boost::asio::ip::tcp::socket &socket) {
     SNOW_LOG_TRACE("new Connection socket fd {}, local addr {}, peer addr {}",
                    socket.native(),
                    socket.local_endpoint(),
                    socket.remote_endpoint());
     std::make_shared<Connection>(socket, m_request_dispatcher, m_pkg_spliter, 100 * 1000)->start();
 }
Beispiel #4
0
 /** Check that local endpoint is loopback
  *
  *  @throws Face::Error if validation failed
  */
 static void
 validateSocket(boost::asio::ip::tcp::socket& socket)
 {
   if (!socket.local_endpoint().address().is_loopback() ||
       !socket.remote_endpoint().address().is_loopback())
     {
       throw Face::Error("TcpLocalFace can be created only on loopback interface");
     }
 }
Beispiel #5
0
void handler::handle_write() {
	dnet_log(m_monitor.node(), DNET_LOG_DEBUG, "monitor: server: send requested statistics: finished: %s:%d", m_remote.c_str(), m_socket.remote_endpoint().port());
	close();
}
Beispiel #6
0
void handler::async_write(std::string data) {
	auto self(shared_from_this());
	m_report = std::move(data);
	dnet_log(m_monitor.node(), DNET_LOG_DEBUG, "monitor: server: send requested statistics: started: %s:%d, size: %lu", m_remote.c_str(), m_socket.remote_endpoint().port(), m_report.size());
	boost::asio::async_write(m_socket, boost::asio::buffer(m_report),
	                         std::bind(&handler::handle_write, self));
}
Beispiel #7
0
void handler::handle_read(const boost::system::error_code &err, size_t size) {
	if (err) {
		close();
		return;
	}

	auto req = parse_request(size);
	std::string content = "";

	if (req > 0) {
		dnet_log(m_monitor.node(), DNET_LOG_DEBUG, "monitor: server: got statistics request for categories: %lx from: %s:%d", req, m_remote.c_str(), m_socket.remote_endpoint().port());
		content = m_monitor.get_statistics().report(req);
	}

	std::string reply = make_reply(req, content);
	async_write(reply);
}
Beispiel #8
0
	size_t hash() const override {
		std::ostringstream stream;
		stream << socket_.remote_endpoint();
		return std::hash<std::string>()(stream.str());
	}