コード例 #1
0
ファイル: private_key.cpp プロジェクト: AshKarath/bumo
	//地址是否合法
	PrivateKey::PrivateKey(SignatureType type) {
		std::string raw_pub_key = "";
		type_ = type;
		if (type_ == SIGNTYPE_ED25519) {
			utils::MutexGuard guard_(lock_);
			// ed25519;
			raw_priv_key_.resize(32);
			//ed25519_randombytes_unsafe((void*)raw_priv_key_.c_str(), 32);
			if (!utils::GetStrongRandBytes(raw_priv_key_)){
				valid_ = false;
				return;
			}
			raw_pub_key.resize(32);
			ed25519_publickey((const unsigned char*)raw_priv_key_.c_str(), (unsigned char*)raw_pub_key.c_str());
		}
		else if (type_ == SIGNTYPE_CFCASM2) {
			utils::EccSm2 key(utils::EccSm2::GetCFCAGroup());
			key.NewRandom();
			raw_priv_key_ = key.getSkeyBin();
			raw_pub_key = key.GetPublicKey();
		}
		else{
			LOG_ERROR("Unknown signature type(%d)", type_);
		}
		pub_key_.Init(raw_pub_key);
		pub_key_.type_ = type_;
		pub_key_.valid_ = true;
		valid_ = true;
	}
コード例 #2
0
actor forwarding_actor_proxy::manager() const {
  actor result;
  {
    shared_lock<detail::shared_spinlock> guard_(manager_mtx_);
    result = manager_;
  }
  return result;
}
コード例 #3
0
ファイル: connection_queue.cpp プロジェクト: BlackYoup/medusa
	void connection_queue::on_timeout(error_code const& e)
	{
		mutex_t::scoped_lock l(m_mutex);

		INVARIANT_CHECK;
#ifdef TORRENT_DEBUG
		function_guard guard_(m_in_timeout_function);
#endif

		TORRENT_ASSERT(!e || e == asio::error::operation_aborted);
		if (e) return;

		ptime next_expire = max_time();
		ptime now = time_now_hires() + milliseconds(100);
		std::list<entry> timed_out;
		for (std::list<entry>::iterator i = m_queue.begin();
			!m_queue.empty() && i != m_queue.end();)
		{
			if (i->connecting && i->expires < now)
			{
				std::list<entry>::iterator j = i;
				++i;
				timed_out.splice(timed_out.end(), m_queue, j, i);
				--m_num_connecting;
				continue;
			}
			if (i->expires < next_expire)
				next_expire = i->expires;
			++i;
		}

		// we don't want to call the timeout callback while we're locked
		// since that is a recepie for dead-locks
		l.unlock();

		for (std::list<entry>::iterator i = timed_out.begin()
			, end(timed_out.end()); i != end; ++i)
		{
#ifndef BOOST_NO_EXCEPTIONS
			try {
#endif
				i->on_timeout();
#ifndef BOOST_NO_EXCEPTIONS
			} catch (std::exception&) {}
#endif
		}
		
		l.lock();
		
		if (next_expire < max_time())
		{
			error_code ec;
			m_timer.expires_at(next_expire, ec);
			m_timer.async_wait(boost::bind(&connection_queue::on_timeout, this, _1));
		}
		try_connect(l);
	}
コード例 #4
0
void forwarding_actor_proxy::forward_msg(const actor_addr& sender,
                                         message_id mid, message msg) {
  BOOST_ACTOR_LOG_TRACE(BOOST_ACTOR_ARG(id()) << ", " << BOOST_ACTOR_TSARG(sender) << ", "
                              << BOOST_ACTOR_MARG(mid, integer_value) << ", "
                              << BOOST_ACTOR_TSARG(msg));
  shared_lock<detail::shared_spinlock> guard_(manager_mtx_);
  if (manager_) manager_->enqueue(invalid_actor_addr, invalid_message_id,
                                  make_message(forward_atom::value, sender,
                                               address(), mid, std::move(msg)),
                                  nullptr);
}
コード例 #5
0
void forwarding_actor_proxy::forward_msg(strong_actor_ptr sender,
                                         message_id mid, message msg,
                                         const forwarding_stack* fwd) {
  CAF_LOG_TRACE(CAF_ARG(id()) << CAF_ARG(sender)
                << CAF_ARG(mid) << CAF_ARG(msg));
  forwarding_stack tmp;
  shared_lock<detail::shared_spinlock> guard_(manager_mtx_);
  if (! manager_.unsafe())
    manager_->enqueue(nullptr, invalid_message_id,
                      make_message(forward_atom::value, std::move(sender),
                                   fwd ? *fwd : tmp,
                                   strong_actor_ptr{ctrl()},
                                   mid, std::move(msg)),
                      nullptr);
}
コード例 #6
0
void connection_queue::on_timeout(error_code const& e)
{
#if defined TORRENT_ASIO_DEBUGGING
    complete_async("connection_queue::on_timeout");
#endif
    mutex_t::scoped_lock l(m_mutex);
    --m_num_timers;

    INVARIANT_CHECK;
#ifdef TORRENT_DEBUG
    function_guard guard_(m_in_timeout_function);
#endif

    TORRENT_ASSERT(!e || e == error::operation_aborted);

    // if there was an error, it's most likely operation aborted,
    // we should just quit. However, in case there are still connections
    // in connecting state, and there are no other timer invocations
    // we need to stick around still.
    if (e && (m_num_connecting == 0 || m_num_timers > 0)) return;

    ptime next_expire = max_time();
    ptime now = time_now_hires() + milliseconds(100);
    std::list<entry> timed_out;
    for (std::list<entry>::iterator i = m_queue.begin();
            !m_queue.empty() && i != m_queue.end();)
    {
        if (i->connecting && i->expires < now)
        {
            std::list<entry>::iterator j = i;
            ++i;
            timed_out.splice(timed_out.end(), m_queue, j, i);
            --m_num_connecting;
            continue;
        }
        if (i->connecting && i->expires < next_expire)
            next_expire = i->expires;
        ++i;
    }

    // we don't want to call the timeout callback while we're locked
    // since that is a recepie for dead-locks
    l.unlock();

    for (std::list<entry>::iterator i = timed_out.begin()
                                        , end(timed_out.end()); i != end; ++i)
    {
        TORRENT_ASSERT(i->connecting);
        TORRENT_ASSERT(i->ticket != -1);
        TORRENT_TRY {
            i->on_timeout();
        } TORRENT_CATCH(std::exception&) {}
    }

    l.lock();

    if (next_expire < max_time())
    {
#if defined TORRENT_ASIO_DEBUGGING
        add_outstanding_async("connection_queue::on_timeout");
#endif
        error_code ec;
        m_timer.expires_at(next_expire, ec);
        m_timer.async_wait(boost::bind(&connection_queue::on_timeout, this, _1));
        ++m_num_timers;
    }
    try_connect(l);
}
コード例 #7
0
void forwarding_actor_proxy::manager(actor new_manager) {
  std::unique_lock<detail::shared_spinlock> guard_(manager_mtx_);
  manager_.swap(new_manager);
}
コード例 #8
0
 bool is_condition_met() const
 {
   return guard_();
 }