示例#1
0
void find_operation::on_response(message & msg, const bool & done)
{
    if (state() == state_started)
    {
        /**
         * Inform base class.
         */
        operation::on_response(msg, done);

        /**
         * Check if we've got a response.
         */
        if (msg.header_code() == protocol::message_code_ack)
        {
            /**
             * Increment the number of find responses.
             */
            find_responses_++;

            log_debug(
                "Find operation " << m_transaction_id << " find_responses = " <<
                find_responses_ << ", ep = " << msg.source_endpoint()
            );

            /**
             * If the number of responses is acceptable call stop.
             */
            if (find_responses_ >= max_results_)
            {
                auto elapsed = std::chrono::duration_cast<
                               std::chrono::milliseconds
                               >(std::chrono::steady_clock::now() - uptime_).count();

                log_debug(
                    "Find operation is stopping, probed = " <<
                    probed_.size() << ", find_responses_ = " <<
                    find_responses_ << ", elapsed = " << elapsed << "."
                );

                /**
                 * Stop
                 */
                stop();
            }
        }
    }
}
void store_operation::on_response(message & msg, const bool & done)
{
    if (state() == state_started)
    {
        /**
         * Inform base class.
         */
        operation::on_response(msg, done);
        
        if (msg.header_code() == protocol::message_code_ack)
        {
            /**
             * Increment the number of store responses.
             */
            store_responses_++;
            
            log_debug(
                "store_responses_ = " << store_responses_ << ", ep = " <<
                msg.source_endpoint()
            );

            /**
             * If we've stored at N storage nodes call stop.
             */
            if (
                store_responses_ >=
                (m_query.pairs_public().size() *
                constants::snodes_per_keyword) || store_responses_ >= 128
                )
            {
                log_debug(
                    "Store operation probed " << probed_.size() <<
                    " storage nodes, value stored at " << store_responses_ <<
                    " storage nodes, stopping."
                );
                
                /**
                 * Stop
                 */
                stop();
            }
        }
    }
}