Ejemplo n.º 1
0
galera::ReplicatorSMM::InitConfig::InitConfig(gu::Config&       conf,
                                              const char* const node_address)
{
    Replicator::register_params(conf);

    std::map<std::string, std::string>::const_iterator i;

    for (i = defaults.map_.begin(); i != defaults.map_.end(); ++i)
    {
        if (i->second.empty())
            conf.add(i->first);
        else
            conf.add(i->first, i->second);
    }

    // what is would be a better protection?
    int const pv(gu::from_string<int>(conf.get(Param::proto_max)));
    if (pv > MAX_PROTO_VER)
    {
        log_warn << "Can't set '" << Param::proto_max << "' to " << pv
                 << ": maximum supported value is " << MAX_PROTO_VER;
        conf.add(Param::proto_max, gu::to_string(MAX_PROTO_VER));
    }

    conf.add(COMMON_BASE_HOST_KEY);
    conf.add(COMMON_BASE_PORT_KEY);

    if (node_address && strlen(node_address) > 0)
    {
        gu::URI na(node_address, false);

        try
        {
            std::string const host = na.get_host();

            if (host == "0.0.0.0" || host == "0:0:0:0:0:0:0:0" || host == "::")
            {
                gu_throw_error(EINVAL) << "Bad value for 'node_address': '"
                                       << host << '\'';
            }

            conf.set(BASE_HOST_KEY, host);
        }
        catch (gu::NotSet& e) {}

        try
        {
            conf.set(BASE_PORT_KEY, na.get_port());
        }
        catch (gu::NotSet& e) {}
    }

    /* register variables and defaults from other modules */
    gcache::GCache::register_params(conf);
    gcs_register_params(reinterpret_cast<gu_config_t*>(&conf));
    Certification::register_params(conf);
    ist::register_params(conf);
}
Ejemplo n.º 2
0
gcomm::AsioProtonet::AsioProtonet(gu::Config& conf, int version)
    :
    gcomm::Protonet(conf, "asio", version),
    mutex_(),
    poll_until_(gu::datetime::Date::max()),
    io_service_(),
    timer_(io_service_),
#ifdef HAVE_ASIO_SSL_HPP
    ssl_context_(io_service_, asio::ssl::context::sslv23),
#endif // HAVE_ASIO_SSL_HPP
    mtu_(1 << 15),
    checksum_(NetHeader::checksum_type(
                  conf.get<int>(gcomm::Conf::SocketChecksum,
                                NetHeader::CS_CRC32C)))
{
    conf.set(gcomm::Conf::SocketChecksum, checksum_);
#ifdef HAVE_ASIO_SSL_HPP
    // use ssl if either private key or cert file is specified
    bool use_ssl(conf_.is_set(gu::conf::ssl_key)  == true ||
                 conf_.is_set(gu::conf::ssl_cert) == true);
    try
    {
        // overrides use_ssl if set explicitly
        use_ssl = conf_.get<bool>(gu::conf::use_ssl);
    }
    catch (gu::NotSet& nf) {}

    if (use_ssl == true)
    {
        conf_.set(gu::conf::use_ssl, true);
        log_info << "initializing ssl context";
        gu::ssl_prepare_context(conf_, ssl_context_);
    }
#endif // HAVE_ASIO_SSL_HPP
}
    Proto(gu::Config&    conf,
          const UUID&    uuid,
          SegmentId      segment,
          const gu::URI& uri = gu::URI("pc://"),
          View*          rst_view = NULL)
        :
        Protolay(conf),
        my_uuid_       (uuid),
        start_prim_    (),
        npvo_          (param<bool>(conf, uri, Conf::PcNpvo, Defaults::PcNpvo)),
        ignore_quorum_ (param<bool>(conf, uri, Conf::PcIgnoreQuorum,
                                    Defaults::PcIgnoreQuorum)),
        ignore_sb_     (param<bool>(conf, uri, Conf::PcIgnoreSb,
                                    gu::to_string(ignore_quorum_))),
        closing_       (false),
        state_         (S_CLOSED),
        last_sent_seq_ (0),
        checksum_      (param<bool>(conf, uri, Conf::PcChecksum,
                                    Defaults::PcChecksum)),
        instances_     (),
        self_i_        (instances_.insert_unique(std::make_pair(uuid, Node()))),
        state_msgs_    (),
        current_view_  (0, V_NONE),
        pc_view_       (0, V_NON_PRIM),
        views_         (),
        mtu_           (std::numeric_limits<int32_t>::max()),
        weight_        (check_range(Conf::PcWeight,
                                    param<int>(conf, uri, Conf::PcWeight,
                                               Defaults::PcWeight),
                                    0, 0xff)),
        rst_view_      ()
    {
        set_weight(weight_);
        NodeMap::value(self_i_).set_segment(segment);
        if (rst_view) {
            set_restored_view(rst_view);
        }

        conf.set(Conf::PcNpvo,         gu::to_string(npvo_));
        conf.set(Conf::PcIgnoreQuorum, gu::to_string(ignore_quorum_));
        conf.set(Conf::PcIgnoreSb,     gu::to_string(ignore_sb_));
        conf.set(Conf::PcChecksum,     gu::to_string(checksum_));
        conf.set(Conf::PcWeight,       gu::to_string(weight_));
    }
Ejemplo n.º 4
0
static std::string
IST_determine_recv_addr (gu::Config& conf)
{
    std::string recv_addr;

    try
    {
        recv_addr = conf.get(galera::ist::Receiver::RECV_ADDR);
    }
    catch (gu::NotFound&)
    {
        try
        {
            recv_addr = conf.get(galera::BASE_HOST_KEY);
        }
        catch (gu::NotSet&)
        {
            gu_throw_error(EINVAL)
                << "Could not determine IST receinve address: '"
                << galera::ist::Receiver::RECV_ADDR << "' not set.";
        }
    }

    /* check if explicit scheme is present */
    if (recv_addr.find("://") == std::string::npos)
    {
        bool ssl(false);

        try
        {
            std::string ssl_key = conf.get(CONF_SSL_KEY);
            if (ssl_key.length() != 0) ssl = true;
        }
        catch (gu::NotFound&) {}

        if (ssl)
            recv_addr.insert(0, "ssl://");
        else
            recv_addr.insert(0, "tcp://");
    }

    gu::URI ra_uri(recv_addr);

    if (!conf.has(galera::BASE_HOST_KEY))
        conf.set(galera::BASE_HOST_KEY, ra_uri.get_host());

    try /* check for explicit port,
           TODO: make it possible to use any free port (explicit 0?) */
    {
        ra_uri.get_port();
    }
    catch (gu::NotSet&) /* use gmcast listen port + 1 */
    {
        int port(0);

        try
        {
            port = gu::from_string<uint16_t>(
//                 gu::URI(conf.get("gmcast.listen_addr")).get_port()
                    conf.get(galera::BASE_PORT_KEY)
                );

        }
        catch (...)
        {
            port = gu::from_string<uint16_t>(galera::BASE_PORT_DEFAULT);
        }

        port += 1;

        recv_addr += ":" + gu::to_string(port);
    }

    return recv_addr;
}