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()); }
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()); }
void ServicePort::handle(Acceptor_ptr acceptor, boost::asio::ip::tcp::socket* socket, const boost::system::error_code& error) { if(!error) { if(m_services.empty()) { #ifdef __DEBUG_NET__ std::clog << "[Error - ServerPort::handle] No services running!" << std::endl; #endif return; } boost::system::error_code error; const boost::asio::ip::tcp::endpoint ip = socket->remote_endpoint(error); uint32_t remoteIp = 0; if(!error) remoteIp = htonl(ip.address().to_v4().to_ulong()); Connection_ptr connection; if(remoteIp && ConnectionManager::getInstance()->acceptConnection(remoteIp) && (connection = ConnectionManager::getInstance()->createConnection( socket, m_io_service, shared_from_this()))) { if(m_services.front()->isSingleSocket()) connection->handle(m_services.front()->makeProtocol(connection)); else connection->accept(); } else if(socket->is_open()) { boost::system::error_code error; socket->shutdown(boost::asio::ip::tcp::socket::shutdown_both, error); socket->close(error); delete socket; } #ifdef __DEBUG_NET_DETAIL__ std::clog << "handle - OK" << std::endl; #endif accept(acceptor); } else if(error != boost::asio::error::operation_aborted) { PRINT_ASIO_ERROR("Handling"); close(); if(!m_pendingStart) { m_pendingStart = true; Scheduler::getInstance().addEvent(createSchedulerTask(5000, boost::bind( &ServicePort::service, boost::weak_ptr<ServicePort>(shared_from_this()), m_acceptors[acceptor], m_serverPort))); } } #ifdef __DEBUG_NET__ else std::clog << "[Error - ServerPort::handle] Operation aborted." << std::endl; #endif }
void handle_read(const boost::system::error_code& ec, std::size_t sz, const boost::asio::ip::tcp::endpoint& endpoint, const string& request, int rpe, boost::shared_ptr<Socket> socket, boost::shared_ptr<boost::asio::streambuf> buf) { ycout << endpoint.address() << "<< \r\n" << boost::make_iterator_range(boost::asio::buffers_begin(buf->data()), boost::asio::buffers_begin(buf->data()) + sz) << "--"; make_request<Socket>(socket->get_io_service(), endpoint, request, rpe); }
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; }
int Connection::getIp() { boost::system::error_code error; const boost::asio::ip::tcp::endpoint ip = m_socket.remote_endpoint(error); if(!error) return boost::asio::detail::socket_ops::host_to_network_long(ip.address().to_v4().to_ulong()); g_logger.error("Getting remote ip"); return 0; }
uint32_t Connection::getIP() const { //ip is expressed in network byte order boost::system::error_code error; const boost::asio::ip::tcp::endpoint ip = m_socket->remote_endpoint(error); if(!error) return htonl(ip.address().to_v4().to_ulong()); return 0; }
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)); }
////////////////////////////////////////////////////////////////////////// /// 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"); }
void ServicePort::onAccept(boost::asio::ip::tcp::socket* socket, const boost::system::error_code& error) { if(!error) { if(m_services.empty()) { #ifdef __DEBUG_NET__ std::cout << "Error: [ServerPort::accept] No services running!" << std::endl; #endif return; } boost::system::error_code error; const boost::asio::ip::tcp::endpoint endpoint = socket->remote_endpoint(error); uint32_t remote_ip = 0; if(!error) remote_ip = htonl(endpoint.address().to_v4().to_ulong()); if(remote_ip != 0/* && g_bans.acceptConnection(remote_ip)*/) { Connection_ptr connection = ConnectionManager::getInstance()->createConnection(socket, m_io_service, shared_from_this()); if(m_services.front()->is_single_socket()) connection->acceptConnection(m_services.front()->make_protocol(connection)); else connection->acceptConnection(); } else if(socket->is_open()) { boost::system::error_code error; socket->shutdown(boost::asio::ip::tcp::socket::shutdown_both, error); socket->close(error); delete socket; } accept(); } else if(error != boost::asio::error::operation_aborted) { if(!m_pendingStart) { close(); m_pendingStart = true; g_scheduler.addEvent(createSchedulerTask(15000, boost::bind(&ServicePort::openAcceptor, boost::weak_ptr<ServicePort>(shared_from_this()), m_serverPort))); } } else { #ifdef __DEBUG_NET__ std::cout << "Error: [ServicePort::onAccept] Operation aborted." << std::endl; #endif } }
uint32_t Connection::getIP() { std::lock_guard<std::recursive_mutex> lockClass(connectionLock); // IP-address is expressed in network byte order boost::system::error_code error; const boost::asio::ip::tcp::endpoint endpoint = socket.remote_endpoint(error); if (error) { return 0; } return htonl(endpoint.address().to_v4().to_ulong()); }
bool TargetedCertificateManager::isValidTarget(boost::asio::ip::tcp::endpoint &endpoint, bool wildcardOK) { boost::asio::ip::address address = endpoint.address(); std::list<Certificate*>::iterator i = certificates.begin(); std::list<Certificate*>::iterator end = certificates.end(); for ( ; i != end; i++) { if ((*i)->isValidTarget(address, wildcardOK)) return true; } return false; }
uint32_t Connection::getIP() const { //Ip is expressed in network byte order boost::system::error_code error; const boost::asio::ip::tcp::endpoint endpoint = m_socket.remote_endpoint(error); if(!error) return htonl(endpoint.address().to_v4().to_ulong()); else { PRINT_ASIO_ERROR("Getting remote ip"); return 0; } }
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); }
void ServicePort::handle(boost::asio::ip::tcp::socket* socket, const boost::system::error_code& error) { if(!error) { if(m_services.empty()) { return; } boost::system::error_code error; const boost::asio::ip::tcp::endpoint ip = socket->remote_endpoint(error); uint32_t remoteIp = 0; if(!error) remoteIp = htonl(ip.address().to_v4().to_ulong()); Connection_ptr connection; if(remoteIp && ConnectionManager::getInstance()->acceptConnection(remoteIp) && (connection = ConnectionManager::getInstance()->createConnection( socket, m_io_service, shared_from_this()))) { if(m_services.front()->isSingleSocket()) connection->handle(m_services.front()->makeProtocol(connection)); else connection->accept(); } else if(socket->is_open()) { boost::system::error_code error; socket->shutdown(boost::asio::ip::tcp::socket::shutdown_both, error); socket->close(error); delete socket; } accept(); } else if(error != boost::asio::error::operation_aborted) { close(); if(!m_pendingStart) { m_pendingStart = true; server.scheduler().addTask(SchedulerTask::create(Milliseconds(5000), std::bind( &ServicePort::onOpen, std::weak_ptr<ServicePort>(shared_from_this()), m_serverPort))); } } }
/// 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; }
void ServicePort::onAccept(boost::asio::ip::tcp::socket* socket, const boost::system::error_code& error) { if (!error) { if (m_services.empty()) { return; } boost::system::error_code socketError; const boost::asio::ip::tcp::endpoint endpoint = socket->remote_endpoint(socketError); uint32_t remote_ip = 0; if (!socketError) { remote_ip = htonl(endpoint.address().to_v4().to_ulong()); } if (remote_ip != 0 && g_bans.acceptConnection(remote_ip)) { Connection_ptr connection = ConnectionManager::getInstance()->createConnection(socket, m_io_service, shared_from_this()); Service_ptr service = m_services.front(); if (service->is_single_socket()) { connection->acceptConnection(service->make_protocol(connection)); } else { connection->acceptConnection(); } } else if (socket->is_open()) { socket->shutdown(boost::asio::ip::tcp::socket::shutdown_both, socketError); socket->close(socketError); delete socket; } accept(); } else if (error != boost::asio::error::operation_aborted) { if (!m_pendingStart) { close(); m_pendingStart = true; g_scheduler.addEvent(createSchedulerTask(15000, boost::bind(&ServicePort::openAcceptor, boost::weak_ptr<ServicePort>(shared_from_this()), m_serverPort))); } } }
void TargetedCertificateManager::getCertificateForTarget(boost::asio::ip::tcp::endpoint &endpoint, bool wildcardOK, X509 *serverCertificate, Certificate **cert, std::list<Certificate*> **chainList) { boost::asio::ip::address address = endpoint.address(); *chainList = &(this->chainList); // *chain = this->chain; std::list<Certificate*>::iterator i = certificates.begin(); std::list<Certificate*>::iterator end = certificates.end(); for ( ; i != end; i++) { if ((*i)->isValidTarget(address, wildcardOK)) { *cert = (*i); return; } } *cert = NULL; return; }
/** * @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()); }
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); } }
std::string get_endpoint_name(boost::asio::ip::tcp::endpoint const& ep) { return ep.address().to_string(); }
bool AuthorityCertificateManager::isOCSPAddress(boost::asio::ip::tcp::endpoint &endpoint) { boost::asio::ip::address address = endpoint.address(); return this->authority->isOCSPAddress(address); }
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; }
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()); }
bool tcp_connection_manager::connect(const boost::asio::ip::tcp::endpoint & ep) { std::lock_guard<std::recursive_mutex> l1(mutex_tcp_connections_); if (network::instance().is_address_banned(ep.address().to_string())) { log_info( "TCP connection manager tried to connect to a banned address " << ep << "." ); return false; } else if (is_ip_banned(ep.address().to_string())) { log_debug( "TCP connection manager tried to connect to a bad address " << ep << "." ); return false; } else if (m_tcp_connections.find(ep) == m_tcp_connections.end()) { log_none("TCP connection manager is connecting to " << ep << "."); /** * Inform the address_manager. */ stack_impl_.get_address_manager()->on_connection_attempt( protocol::network_address_t::from_endpoint(ep) ); /** * Allocate tcp_transport. */ auto transport = std::make_shared<tcp_transport>(io_service_, strand_); /** * Allocate the tcp_connection. */ auto connection = std::make_shared<tcp_connection> ( io_service_, stack_impl_, tcp_connection::direction_outgoing, transport ); /** * Retain the connection. */ m_tcp_connections[ep] = connection; /** * Start the tcp_connection. */ connection->start(ep); return true; } else { log_none( "TCP connection manager attempted connection to existing " "endpoint = " << ep << "." ); } return false; }