Exemple #1
0
/* FIXME: should support return values other than gfarm_error_t too */
void
gfm_async_server_reply_to_gfsd_schedule(struct host *host,
	struct peer *peer, gfp_xdr_xid_t xid,
	gfarm_error_t errcode, int flags, const char *diag)
{
	gfarm_error_t e;
	struct gfm_async_server_reply_to_gfsd_entry *qe;

	GFARM_MALLOC(qe);
	if (qe == NULL) {
		gflog_error(GFARM_MSG_1004031,
		    "%s: %s: no memory for queue entry",
		    host_name(host), diag);
	} else {
		netsendq_entry_init(&qe->qentry,
		    &gfm_async_server_reply_to_gfsd_queue);
		qe->qentry.abhost = host_to_abstract_host(host);
		qe->peer = peer;
		qe->xid = xid;
		qe->errcode = errcode;
		qe->diag = diag;
		e = netsendq_add_entry(host_sendq(host), &qe->qentry, flags);
		if (e != GFARM_ERR_NO_ERROR) {
			gflog_info(GFARM_MSG_1004032,
			    "%s: %s queueing: %s",
			    host_name(host), diag, gfarm_error_string(e));
			if ((flags & NETSENDQ_ADD_FLAG_DETACH_ERROR_HANDLING)
			    == 0)
				free(qe);
		}
	}
}
Exemple #2
0
 std::string batch_environment::host_name(std::string const& def_hpx_name) const
 {
     std::string host = nodes_.empty() ? def_hpx_name : host_name();
     if (debug_)
         std::cerr << "host_name: " << host << std::endl;
     return host;
 }
/* Create the keys we'll be using for the display named NAME. */
static int
make_auth_keys (const char *name)
{
    Xauth auth;
    char key[16];
	
    if (auth_file == NULL)
		return FALSE;
	
    auth.name = "MIT-MAGIC-COOKIE-1";
    auth.name_length = strlen (auth.name);
	
    if (!generate_mit_magic_cookie (key))
    {
		auth_file = NULL;
		return FALSE;
    }
	
    auth.data = key;
    auth.data_length = 16;
	
    set_auth_number (&auth, name);
	
    define_named (&auth, host_name ());
    define_local (&auth);
	
    free (auth.number);
	
    return TRUE;
}
int main(int argc, char *argv[])
{
  // Get a hostname and uri from the user (assume default http port)
  if (argc <= 2)
  {
    std::cout << "Usage: simple_http_client [host] [uri]\n"
              << "E.g. simple_http_client www.boost.org /LICENSE_1_0.txt"
              << std::endl;
    return 1;
  }

  std::string host_name(argv[1]);
  std::string uri(argv[2]);
  std::cout << "HTTP client host: " << host_name
            << " uri: " << uri << std::endl;
  try
  {
    // create an io_service for the tcp port
    boost::asio::io_service io_service;

    // create an http_client
    http_client_type::shared_pointer http_client
        (http_client_type::create(io_service));

    // connect the response and chunk received callback functions
    http_client->response_received_event(response_receiver);
    http_client->chunk_received_event(chunk_receiver);

    // attempt to connect to the host on the standard http port (80)
    if (http_client->connect(host_name))
    {
      // create an http request
      // Note: adds a "connection close" header since we're only sending
      // one request, so we'll get the server to close the connection after
      // it's response
      via::http::tx_request request(via::http::request_method::GET, uri);
      request.add_header(via::http::header_field::CONNECTION, "close");

      // send the request to the host.
      http_client->send(request);

      // run the io_service to start communications
      io_service.run();
    }
    else
    {
      std::cout << "Could not resolve host: " << host_name << std::endl;
      return 1;
    }
  }
  catch (std::exception& e)
  {
    std::cerr << "Exception:"  << e.what() << std::endl;
  }

  return 0;
}
int main(int argc, char *argv[])
{
  std::string app_name(argv[0]);

  // Get a hostname and uri from the user (assume default http port)
  if (argc != 3)
  {
    std::cout << "Usage: " << app_name << " [host] [uri]\n"
              << "E.g. "   << app_name << " localhost /hello"
              << std::endl;
    return 1;
  }

  std::string host_name(argv[1]);
  uri = argv[2];
  std::cout << app_name <<" host: " << host_name
            << " uri: " << uri << std::endl;
  try
  {
    // The asio io_service.
    boost::asio::io_service io_service;

    // Create an http_client and attach the response & chunk handlers
    http_client =
        https_client_type::create(io_service, response_handler, chunk_handler);

    // attach optional handlers
    http_client->connected_event(connected_handler);
    http_client->disconnected_event(disconnected_handler);

    // Set up SSL
    std::string certificate_file = "cacert.pem";
    boost::asio::ssl::context& ssl_context
       (https_client_type::connection_type::ssl_context());
    ssl_context.load_verify_file(certificate_file);

    // attempt to connect to the host on the standard https port (443)
    if (!http_client->connect(host_name, "https"))
    {
      std::cout << "Error, could not resolve host: " << host_name << std::endl;
      return 1;
    }

    // run the io_service to start communications
    io_service.run();

    std::cout << "io_service.run complete, shutdown successful" << std::endl;
  }
  catch (std::exception& e)
  {
    std::cerr << "Exception:"  << e.what() << std::endl;
  }

  return 0;
}
Exemple #6
0
//##############################################################################
//##############################################################################
static std::vector<std::string>
resolve_peer_names(const std::vector<std::string> &addrs)
{
    range::Emitter log { resolve_peer_namesLogModule };
    RANGE_LOG_FUNCTION();

    std::vector<std::string> peer_names;
    boost::asio::io_service io_service;
    for(auto a : addrs) {
        auto addr = boost::asio::ip::address_v4::from_string(a);
        boost::asio::ip::udp::resolver resolver(io_service);
        boost::asio::ip::udp::endpoint ep;
        ep.address(addr);

        for(auto it = resolver.resolve(ep); it != decltype(it)(); ++it) {
            peer_names.push_back(it->host_name());
            LOG(info, "adding_range_peer") << it->host_name();
        }
    }
    return peer_names;
}
Exemple #7
0
void
getouraddr()
{
    char*        hostname = host_name();
    SockAddress  hostaddr;

    our_addr_ip = loopback_addr_ip;

    if (sock_address_init_resolve( &hostaddr, hostname, 0, 0 ) < 0)
        return;

    our_addr_ip = sock_address_get_ip(&hostaddr);
    if (our_addr_ip == (uint32_t)-1)
        our_addr_ip = loopback_addr_ip;
}
/* Add the unix domain auth item. */
static void
define_local (Xauth *auth)
{
    char *host = host_name ();
	
#ifdef DEBUG
    fprintf (stderr, "x11: hostname is %s\n", host);
#endif
	
    auth->family = FamilyLocal;
    auth->address_length = strlen (host);
    auth->address = host;
	
    add_auth_item (auth);
}
Exemple #9
0
static void *
gfm_async_server_reply_to_gfsd(void *arg)
{
	gfarm_error_t e;
	struct gfm_async_server_reply_to_gfsd_entry *qe = arg;
	struct host *host = abstract_host_to_host(qe->qentry.abhost);
	struct netsendq *qhost = abstract_host_get_sendq(qe->qentry.abhost);
	const char *diag = qe->diag;

	e = gfm_async_server_put_reply(host, qe->peer, qe->xid, diag,
	    qe->errcode, "");
	netsendq_entry_was_sent(qhost, &qe->qentry);
	netsendq_remove_entry(qhost, &qe->qentry, e);

	if (e != GFARM_ERR_NO_ERROR)
		gflog_warning(GFARM_MSG_1004030,
		    "%s: %s reply: %s",
		    host_name(host), diag, gfarm_error_string(e));
	return (NULL);
}
void print(const CMPIObjectPath* op)
{
    printf("CMPIObjectPath\n");
    printf("{\n");

    printf("    name_space: \"%s\"\n", name_space(op));
    printf("    class_name: \"%s\"\n", class_name(op));
    printf("    host_name: \"%s\"\n", host_name(op));
    printf("    ---\n");

    for (size_t i = 0, n = CMGetKeyCount(op, NULL); i < n; i++)
    {
        CMPIString* name;
        CMPIData data = CMGetKeyAt(op, i, &name, NULL);

        printf("    %s(%s): ", CMGetCharPtr(name), type_name_of(data.type));
        print(data);
        putchar('\n');
    }

    printf("}\n");
}
Exemple #11
0
 int Cluster::CreateZookeeperPath()
 {
     char hostname[1024]; //_SC_HOST_NAME_MAX = 255 default,
     int hostname_len = gethostname(hostname, sizeof(hostname));
     std::string host_name(hostname, hostname_len);
     cJSON* content = cJSON_CreateObject();
     cJSON_AddItemToObject(content, "uptime", cJSON_CreateNumber(time(NULL)));
     cJSON_AddItemToObject(content, "addr", cJSON_CreateString(host_name.c_str()));
     char* jsonstr = cJSON_Print(content);
     cJSON_Delete(content);
     std::string zk_path = "/" + g_db->GetConf().cluster_name + "/servers/" + host_name + ":" + stringfromll(g_db->GetConf().PrimaryPort());
     int err = zoo_create(m_zk, zk_path.c_str(), jsonstr, strlen(jsonstr), &m_zk_acl, ZOO_EPHEMERAL, "", 0);
     free(jsonstr);
     if (0 == err)
     {
         m_state = ZK_STATE_FETCH_TOPO;
     }
     else
     {
         WARN_LOG("Failed to create path or reason:%s", zerror(err));
     }
     return err;
 }
// =-=-=-=-=-=-=-
// static function to query resource for chosen server to which to redirect
// for a given operation
    error resource_redirect( const std::string&   _oper,
                             rsComm_t*            _comm,
                             dataObjInp_t*        _data_obj_inp,
                             std::string&         _out_hier,
                             rodsServerHost_t*&   _out_host,
                             int&                 _out_flag ) {
        // =-=-=-=-=-=-=-
        // default to local host if there is a failure
        _out_flag = LOCAL_HOST;

        // =-=-=-=-=-=-=-
        // resolve the resource hierarchy for this given operation and dataobjinp
        std::string resc_hier;
        error res_err = resolve_resource_hierarchy(
                            _oper,
                            _comm,
                            _data_obj_inp,
                            resc_hier );
        if ( !res_err.ok() ) {
            std::stringstream msg;
            msg << "resource_redirect - failed to resolve resource hierarchy for [";
            msg << _data_obj_inp->objPath;
            msg << "]";
            return PASSMSG( msg.str(), res_err );

        }

        // =-=-=-=-=-=-=-
        // we may have an empty hier due to special collections and other
        // unfortunate cases which we cannot control, check the hier string
        // and if it is empty return success ( for now )
        if ( resc_hier.empty() ) {
            return SUCCESS();
        }

        // =-=-=-=-=-=-=-
        // parse out the leaf resource for redirection
        std::string last_resc;
        hierarchy_parser parser;
        parser.set_string( resc_hier );
        parser.last_resc( last_resc );

        // =-=-=-=-=-=-=-
        // get the host property from the last resc and get the
        // host name from that host
        rodsServerHost_t* last_resc_host = NULL;
        error err = get_resource_property< rodsServerHost_t* >(
                        last_resc,
                        RESOURCE_HOST,
                        last_resc_host );
        if ( !err.ok() || NULL == last_resc_host ) {
            std::stringstream msg;
            msg << "resource_redirect :: failed in get_resource_property call ";
            msg << "for [" << last_resc << "]";
            return PASSMSG( msg.str(), err );
        }


        // =-=-=-=-=-=-=-
        // get current hostname, which is also done by init local server host
        char host_name_char[ MAX_NAME_LEN ];
        if ( gethostname( host_name_char, MAX_NAME_LEN ) < 0 ) {
            return ERROR( SYS_GET_HOSTNAME_ERR, "failed in gethostname" );

        }

        std::string host_name( host_name_char );

        // =-=-=-=-=-=-=
        // iterate over the list of hostName_t* and see if any match our
        // host name.  if we do, then were local
        bool        match_flg = false;
        hostName_t* tmp_host  = last_resc_host->hostName;
        while ( tmp_host ) {
            std::string name( tmp_host->name );
            if ( name.find( host_name ) != std::string::npos ) {
                match_flg = true;
                break;

            }

            tmp_host = tmp_host->next;

        } // while tmp_host

        // =-=-=-=-=-=-=-
        // are we really, really local?
        if ( match_flg ) {
            _out_hier = resc_hier;
            _out_flag = LOCAL_HOST;
            _out_host = 0;
            return SUCCESS();
        }

        // =-=-=-=-=-=-=-
        // it was not a local resource so then do a svr to svr connection
        int conn_err = svrToSvrConnect( _comm, last_resc_host );
        if ( conn_err < 0 ) {
            return ERROR( conn_err, "failed in svrToSvrConnect" );
        }


        // =-=-=-=-=-=-=-
        // return with a hier string and new connection as remote host
        _out_hier = resc_hier;
        _out_host = last_resc_host;
        _out_flag = REMOTE_HOST;

        return SUCCESS();

    } // resource_redirect
/// =-=-=-=-=-=-=-
/// @brief function to handle collecting a vote from a resource
///        for a given operation and fco
    static
    error request_vote_for_file_object(
        rsComm_t*                _comm,
        const std::string&       _oper,
        const std::string&       _resc_name,
        irods::file_object_ptr  _file_obj,
        std::string&             _out_hier,
        float&                   _out_vote ) {
        // =-=-=-=-=-=-=-
        // request the resource by name
        irods::resource_ptr resc;
        error err = resc_mgr.resolve( _resc_name, resc );
        if ( !err.ok() ) {
            return PASSMSG( "failed in resc_mgr.resolve", err );

        }

        // =-=-=-=-=-=-=-
        // if the resource has a parent, bail as this is a grave, terrible error.
        resource_ptr parent;
        error p_err = resc->get_parent( parent );
        if ( p_err.ok() ) {
            return ERROR(
                       DIRECT_CHILD_ACCESS,
                       "attempt to directly address a child resource" );
        }

        // =-=-=-=-=-=-=-
        // get current hostname, which is also done by init local server host
        char host_name_str[ MAX_NAME_LEN ];
        if ( gethostname( host_name_str, MAX_NAME_LEN ) < 0 ) {
            return ERROR( SYS_GET_HOSTNAME_ERR, "failed in gethostname" );

        }
        std::string host_name( host_name_str );

        // =-=-=-=-=-=-=-
        // query the resc given the operation for a hier string which
        // will determine the host
        hierarchy_parser parser;
        float            vote = 0.0;
        first_class_object_ptr ptr = boost::dynamic_pointer_cast< first_class_object >( _file_obj );
        err = resc->call< const std::string*, const std::string*, hierarchy_parser*, float* >(
                  _comm, RESOURCE_OP_RESOLVE_RESC_HIER, ptr, &_oper, &host_name, &parser, &vote );
        if ( !err.ok() || 0.0 == vote ) {
            std::stringstream msg;
            msg << "failed in call to redirect";
            msg << "\thost [" << host_name      << "] ";
            msg << "\thier [" << _out_hier << "]";
            err.status( false );
            if ( err.code() == 0 ) {
                err.code( -1 );
            }
            return PASSMSG( msg.str(), err );
        }

        // =-=-=-=-=-=-=-
        // extract the hier string from the parser, politely.
        parser.str( _out_hier );
        _out_vote = vote;

        return SUCCESS();

    } // request_vote_for_file_object
Exemple #14
0
boost::shared_ptr<Config>
config_builder(const std::string& filename, Consumer type)
{
    (void)(filename);

    Config * cfg; 
    switch (type) {
        case Consumer::CLIENT:
            cfg = new Config();
            break;
        case Consumer::STORED:
            cfg = new StoreDaemonConfig();
            break;
    }

    
    auto db_conf = boost::make_shared<db::ConfigIface>("/var/lib/rangexx", 67108864);
    auto db = range::db::BerkeleyDB::get( db_conf );

    cfg->db_backend(db);
    cfg->db_backend()->register_thread();
    cfg->graph_factory(boost::make_shared<graph::GraphdbConcreteFactory<graph::GraphDB>>());
    cfg->node_factory(boost::make_shared<graph::NodeIfaceConcreteFactory<db::ProtobufNode>>()); 
    cfg->range_symbol_table(build_symtable());
    cfg->stored_mq_name("rangexx_request");
    std::string fqdn;
    {
        std::string node_name = boost::asio::ip::host_name();
        boost::asio::io_service io_service;
        boost::asio::ip::udp::resolver resolver {io_service};
        boost::asio::ip::udp::resolver::query query {node_name, ""};
        try {
            for(auto it = resolver.resolve(query); it != decltype(it)(); ++it) {
                boost::asio::ip::udp::endpoint ep;
                ep.address(it->endpoint().address());
                boost::asio::ip::udp::resolver rev_resolver {io_service};
                try {
                    for (auto r_it = rev_resolver.resolve(ep); r_it != decltype(r_it)(); ++r_it) {
                        if (r_it->host_name().size() > fqdn.size()) {
                            fqdn = r_it->host_name();
                        }
                    }
                } catch (boost::system::system_error &e) { }
            }
        } catch (boost::system::system_error &e) { }
    }

    cfg->node_id(fqdn);

    switch (type) {
        case Consumer::CLIENT:
            cfg->use_stored(true);
            cfg->stored_request_timeout(30000);
            cfg->reader_ack_timeout(30000);
            break;
        case Consumer::STORED:
            cfg->use_stored(false);
            cfg->stored_request_timeout(5000);
            cfg->reader_ack_timeout(5000);
            dynamic_cast<StoreDaemonConfig*>(cfg)->initial_peers(
                    { 
                        "ubuntu14-04-1.jamiebeverly.net",
                        "ubuntu14-04-2.jamiebeverly.net",
                        "ubuntu14-04-3.jamiebeverly.net"
                    }
                );
            dynamic_cast<StoreDaemonConfig*>(cfg)->heartbeat_timeout(1000);
            dynamic_cast<StoreDaemonConfig*>(cfg)->port(5444);
            dynamic_cast<StoreDaemonConfig*>(cfg)->range_cell_name("testcell");
            break;
    }

    std::map<std::string, bool> instances { {"primary", false}, {"dependency", false} };

    for (auto g : cfg->db_backend()->listGraphInstances()) {
        instances[g] = true;
    }

    if(!instances["primary"]) {
        cfg->db_backend()->createGraphInstance("primary");
    }
    if(!instances["dependency"]) {
        cfg->db_backend()->createGraphInstance("dependency");
    }

    ::range::config = boost::shared_ptr<Config>(cfg);
    return config;
}
inline std::string host_name()
{
  return host_name(asio::throw_error());
}
Exemple #16
0
static gfarm_error_t
gfm_server_switch_back_channel_common(
	struct peer *peer, gfp_xdr_xid_t xid, size_t *sizep,
	int from_client,
	int version, const char *diag, struct relayed_request *relay)
{
	gfarm_error_t e = GFARM_ERR_NO_ERROR, e2;
	struct host *host;
	gfp_xdr_async_peer_t async = NULL;
	struct local_peer *local_peer = NULL;
	int is_direct_connection;
	int i = 0;

#ifdef __GNUC__ /* workaround gcc warning: might be used uninitialized */
	host = NULL;
#endif
	is_direct_connection = (peer_get_parent(peer) == NULL);

	giant_lock();

	if (from_client) {
		gflog_debug(GFARM_MSG_1001995,
		    "Operation not permitted: from_client");
		e = GFARM_ERR_OPERATION_NOT_PERMITTED;
	} else if ((host = peer_get_host(peer)) == NULL) {
		gflog_debug(GFARM_MSG_1001996,
		    "Operation not permitted: peer_get_host() failed");
		e = GFARM_ERR_OPERATION_NOT_PERMITTED;
	} else if (is_direct_connection &&
	    (e = gfp_xdr_async_peer_new(&async)) != GFARM_ERR_NO_ERROR) {
		gflog_error(GFARM_MSG_1002288,
		    "%s: gfp_xdr_async_peer_new(): %s",
		    diag, gfarm_error_string(e));
	}
	giant_unlock();

	e2 = gfm_server_relay_put_reply(peer, xid, sizep, relay,
	    diag, &e,  "i", &i/*XXX FIXME*/);
	if (e2 != GFARM_ERR_NO_ERROR)
		return (e2);
	if (debug_mode)
		gflog_debug(GFARM_MSG_1000404, "gfp_xdr_flush");
	e2 = gfp_xdr_flush(peer_get_conn(peer));
	if (e2 != GFARM_ERR_NO_ERROR) {
		gflog_warning(GFARM_MSG_1000405,
		    "%s: protocol flush: %s",
		    diag, gfarm_error_string(e2));
		return (e2);
	} else if (e != GFARM_ERR_NO_ERROR)
		return (e2);

	if (is_direct_connection) {
		local_peer = peer_to_local_peer(peer);
		local_peer_set_async(local_peer, async); /* XXXRELAY */
		local_peer_set_readable_watcher(local_peer,
		    back_channel_recv_watcher);
	}

	if (host_is_up(host)) /* throw away old connetion */ {
		gflog_warning(GFARM_MSG_1002440,
		    "back_channel(%s): switching to new connection",
		    host_name(host));
		host_disconnect_request(host, NULL);
	}

	giant_lock();
	peer_set_peer_type(peer, peer_type_back_channel);
	abstract_host_set_peer(host_to_abstract_host(host), peer, version);
	giant_unlock();

	if (is_direct_connection) {
		local_peer_watch_readable(local_peer);
		gfarm_thr_statewait_signal(
		    local_peer_get_statewait(local_peer), e2, diag);
	}

	callout_setfunc(host_status_callout(host),
	    NULL /* or, use back_channel_send_manager thread pool? */,
	    gfs_client_status_callout, host);
	gfs_client_status_schedule(host, 1);
	gflog_info(GFARM_MSG_1004035,
	    "back_channel(%s): started", host_name(host));

	return (e2);
}
Exemple #17
0
static void
gfs_client_status_schedule(struct host *host, int first_attempt)
{
	gfarm_error_t e;
	struct gfs_client_status_entry *qe;
	enum { stop_callout, do_next, do_retry } callout_next = do_next;
	const char diag[] = "GFS_PROTO_STATUS";

	GFARM_MALLOC(qe);
	if (qe == NULL) {
		callout_next = do_retry;
		gflog_error(GFARM_MSG_1004026,
		    "%s: %s: no memory for queue entry",
		    host_name(host), diag);
	} else {
		netsendq_entry_init(&qe->qentry, &gfs_proto_status_queue);
		qe->qentry.abhost = host_to_abstract_host(host);
		e = netsendq_add_entry(host_sendq(host), &qe->qentry,
		    NETSENDQ_ADD_FLAG_DETACH_ERROR_HANDLING);
		if (e == GFARM_ERR_NO_ERROR) {
			/* OK */
		} else if (first_attempt && e == GFARM_ERR_DEVICE_BUSY) {
			/*
			 * if this is first attempt just after
			 * the back channel connection is made,
			 * it's possible previous callout remains
			 * with the following scenario:
			 * 1. gfs_client_status_callout() thread begins to run
			 * 2. host_unset_peer() calls callout_stop()
			 * 3. netsendq_host_becomes_down() clears readyq
			 * 4. the gfs_client_status_callout() thread in 1
			 *    adds an entry to workq and readyq
			 */
			gflog_info(GFARM_MSG_1004027,
			    "%s: %s queueing conflict", host_name(host), diag);
		} else {
			/* increment refcount */
			struct peer *peer = host_get_peer(host);

			callout_next = stop_callout;
			gflog_info(GFARM_MSG_1004028,
			    "%s: %s queueing: %s",
			    host_name(host), diag, gfarm_error_string(e));
			/* `qe' is be freed by gfs_client_status_finalize() */
			if (peer == NULL) {
				gflog_info(GFARM_MSG_1004029,
				    "%s: %s: already disconnected",
				    host_name(host), diag);
			} else {
				gfs_client_status_disconnect_or_message(host,
				    peer, diag, "queueing",
				    gfarm_error_string(e));
				 /* decrement refcount */
				host_put_peer(host, peer);
			}
		}
	}
	switch (callout_next) {
	case stop_callout:
		/* do nothing */
		break;
	case do_next:
		callout_schedule(host_status_callout(host),
		    gfarm_metadb_heartbeat_interval * 1000000);
		break;
	case do_retry:
		callout_schedule(host_status_callout(host),
		    gfarm_metadb_heartbeat_interval * 1000000 / 10);
		break;
	}
}