FaceUri::FaceUri(const boost::asio::ip::tcp::endpoint& endpoint, const std::string& scheme)
  : m_scheme(scheme)
{
  m_isV6 = endpoint.address().is_v6();
  m_host = endpoint.address().to_string();
  m_port = boost::lexical_cast<std::string>(endpoint.port());
}
Example #2
0
Sirikata::Network::Address convertEndpointToAddress(const boost::asio::ip::tcp::endpoint&ep) {
    std::ostringstream address;
    address<<ep.address();
    std::ostringstream port;
    port<<ep.port();
    return Address (address.str(),port.str());
}
Example #3
0
void node::on_proxy(
    const std::uint16_t & tid, const boost::asio::ip::tcp::endpoint & ep,
    const std::string & value
    )
{
    stack_impl_.on_proxy(
        tid, ep.address().to_string().c_str(), ep.port(), value
    );
}
		/// Handle completion of a read operation. 
		void handleRead(const boost::system::error_code& error, std::size_t bytes_transferred)
		{

			if (!error){
				readBytes += bytes_transferred;
				readBuff.has_written(bytes_transferred);
				onReadMsg(readBuff, writeBuff);
				readBuff.discard_all();

				reading = false;

				if (writeBuff.readable_bytes()>0){
					//std::cout << "going to send " << writeBuff.readable_bytes() << std::endl;
					//std::cout << writeBuff.as_string() << std::endl;
					LOG_DEBUG << "going to send " << writeBuff.readable_bytes();
					{

						size_t out_put_size = 256;
						if (out_put_size > writeBuff.readable_bytes()){
							out_put_size = writeBuff.readable_bytes();
						}
						
						LOG_DEBUG << writeBuff.as_string(0,out_put_size);
					}
					startWrite();
				}
				else{
					startRead();
				}

			}
			else{
				if (error == boost::asio::error::misc_errors::eof){
					LOG_INFO << " Client disconnectd:" << remoteAddr.address() << "  " << remoteAddr.port();
				}
				else{
					LOG_ERR << remoteAddr.address() << "  " << remoteAddr.port()
						<< ",error =" << error.value()
						<< ",msg=" << error.message();
				}
			}
			reading = false;
		}
void TcpConnectionImpl::connect(boost::asio::ip::tcp::endpoint& endpoint)
{
	if(m_isConnected) return;
	if(m_isClosing) return;

	m_endPoint = endpoint;

	std::cout << "Trying to connect to port " << endpoint.port() << " @ " << endpoint.address().to_string() << std::endl;
	// try to connect, then call handle_connect
    m_socket.async_connect(endpoint, boost::bind(&TcpConnectionImpl::handle_connect, this, boost::asio::placeholders::error));
}
Example #6
0
	server(boost::asio::io_service & io_service,
				const boost::asio::ip::tcp::endpoint & endpoint)
		: io_service_(io_service)
		, acceptor_(io_service_, endpoint)
	{
		std::cout << esc(MAKE_GREEN)
			<< LOG_HEADER
			<< "Echo server is listening on port: "
			<< endpoint.port()
			<< esc(RESET_COLOR)
			<< std::endl;
		start_accept();
	}
    VideoDataHandler(InputStream * is, OutputStream * os, boost::asio::ip::tcp::endpoint e):
    _db(org::esb::hive::DatabaseService::getDatabase())
    {
      _ep=e;
      _os=os;
      _is=is;
      _oos = new io::ObjectOutputStream(os);
      _ois = new io::ObjectInputStream(is);
      _own_id = e.address().to_string();
      _own_id += ":";
      _own_id += StringUtil::toString(e.port());
      shutdown = false;

      LOGDEBUG("endpoint:" << e);
    }
Example #8
0
//////////////////////////////////////////////////////////////////////////
/// Pushes to Lua the data of the endpoint
void Resolver::EndpointToLua(lua_State* L, const boost::asio::ip::tcp::endpoint& endpoint) {
	const boost::asio::ip::address& address = endpoint.address();
	std::string s = endpoint.address().to_string();
	lua_newtable(L);
	lua_pushstring(L, address.to_string().c_str());
	lua_setfield(L, -2, "address");

	lua_pushnumber(L, endpoint.port());
	lua_setfield(L, -2, "port");

	if(endpoint.address().is_v6()) {
		lua_pushnumber(L, 6);
	}
	else if(endpoint.address().is_v4()) {
		lua_pushnumber(L, 4);
	}
	else {
		lua_pushliteral(L, "unknown");
	}
	lua_setfield(L, -2, "family");
}
		/// Handle completion of a write operation.
		void handleWrite(const boost::system::error_code& error, std::size_t bytes_transferred)
		{

			if (!error){
				//
				//std::cout << "send done,bytes_transferred:" << writeBuff.readable_bytes() << bytes_transferred << std::endl;
				LOG_DEBUG << "send done,bytes_transferred:"  << bytes_transferred;
				BOOST_ASSERT(bytes_transferred == writeBuff.readable_bytes());
				writeBytes += bytes_transferred;
				writeBuff.discard_all();
				writing = false;
				startRead();
			}
			else{ 
				LOG_ERR << remoteAddr.address() << "  " << remoteAddr.port()
					<< ",error =" << error.value()
					<< ",msg=" << error.message();
			}
			writing = false;

		}
Example #10
0
        void bind(
            boost::asio::ip::tcp::endpoint const & ep
          , boost::system::error_code &ec)
        {
            if(event_channel_)
            {
                HPX_IBVERBS_THROWS_IF(ec, boost::asio::error::already_connected);
            }
            else
            {
                event_channel_ = rdma_create_event_channel();
                if(!event_channel_)
                {
                    int verrno = errno;
                    close(ec);
                    boost::system::error_code err(verrno, boost::system::system_category());
                    HPX_IBVERBS_THROWS_IF(
                        ec
                      , err
                    );
                    return;
                }
                set_nonblocking(event_channel_->fd, ec);
                if(ec)
                {
                    close(ec);
                    return;
                }

                int ret = 0;
                ret = rdma_create_id(event_channel_, &listener_, NULL, RDMA_PS_TCP);

                if(ret)
                {
                    int verrno = errno;
                    close(ec);
                    boost::system::error_code err(verrno, boost::system::system_category());
                    HPX_IBVERBS_THROWS_IF(
                        ec
                      , err
                    );
                    return;
                }

                std::string host = ep.address().to_string();
                std::string port = boost::lexical_cast<std::string>(ep.port());

                addrinfo *addr;

                getaddrinfo(host.c_str(), port.c_str(), NULL, &addr);

                ret = rdma_bind_addr(listener_, addr->ai_addr);

                freeaddrinfo(addr);
                if(ret)
                {
                    int verrno = errno;
                    close(ec);
                    boost::system::error_code err(verrno, boost::system::system_category());
                    HPX_IBVERBS_THROWS_IF(
                        ec
                      , err
                    );
                    return;
                }
                ret = rdma_listen(listener_, 10); /* backlog = 10 is arbitrary */
                if(ret)
                {
                    int verrno = errno;
                    close(ec);
                    boost::system::error_code err(verrno, boost::system::system_category());
                    HPX_IBVERBS_THROWS_IF(
                        ec
                      , err
                    );
                    return;
                }
                HPX_IBVERBS_RESET_EC(ec);
            }
        }
Example #11
0
EndPoint::EndPoint(boost::asio::ip::tcp::endpoint& bEndpoint): _hostName(), _port(static_cast<unsigned short>(bEndpoint.port())), _address(new Address(bEndpoint))
{}
Example #12
0
std::int16_t incentive::calculate_score(
    const boost::asio::ip::tcp::endpoint & ep
    )
{
	std::int16_t ret = -1;

    auto index = utility::find_block_index_by_height(
        globals::instance().best_block_height()
    );
    
    if (index)
    {
        const auto & hash_block = index->get_block_hash();

        /**
         * Get the node endpoint.
         */
        auto node_ep =
            ep.address().to_string() + ":" + std::to_string(ep.port())
        ;
        
        /**
         * Hash the endpoint.
         */
        auto digest1 = hash::sha256d(
            reinterpret_cast<const std::uint8_t *>(node_ep.data()),
            node_ep.size()
        );
        
        /**
         * Hash the hash of the block.
         */
        auto digest2 = hash::sha256d(
            hash_block.digest(), sha256::digest_length
        );
        
        auto hash2 = sha256::from_digest(&digest2[0]);

        auto digest3 = hash::sha256d(
            &digest2[0], &digest2[0] + digest2.size(),
            &digest1[0], &digest1[0] + digest1.size()
        );
        
        auto hash3 = sha256::from_digest(&digest3[0]);
        
        if (hash3 > hash2)
        {
            ret =
                static_cast<std::int16_t> (
                (hash3 - hash2).to_uint64())
            ;
        }
        else
        {
            ret =
                static_cast<std::int16_t> (
                (hash2 - hash3).to_uint64())
            ;
        }
    }

    return ret;
}
Example #13
0
 /**
 * @return the ip address of the endpoint endpoint.
 */
 std::string ip_address(const boost::asio::ip::tcp::endpoint &endpoint)
 {
   return endpoint.address().to_string()
       + ":"
       + boost::lexical_cast<std::string>(endpoint.port());
 }
Example #14
0
uint64 PortalsPeer::makeID(const boost::asio::ip::tcp::endpoint &endpoint)
{
    OS_ASSERT(endpoint.address().is_v4());
    return OS_MAKE_UINT64(endpoint.port(), endpoint.address().to_v4().to_ulong());
}