Skip to content

network/result_aggregation.hpp

Timeout-bounded collection of swarm node responses (PTDS §4.2) More...

Namespaces

Name
sgns
sgns::neoswarm
sgns::neoswarm::network

Classes

Name
class sgns::neoswarm::network::ResultAggregation
Collects NodeOutput responses from swarm peers with a timeout.
struct sgns::neoswarm::network::ResultAggregation::Config

Detailed Description

Timeout-bounded collection of swarm node responses (PTDS §4.2)

Date: 2026-05-06

Source code

#ifndef NEOSWARM_NETWORK_RESULTAGGREGATION_HPP
#define NEOSWARM_NETWORK_RESULTAGGREGATION_HPP

#include "common/error.hpp"
#include "common/types.hpp"
#include <chrono>
#include <condition_variable>
#include <mutex>
#include <vector>

namespace sgns::neoswarm::network
{
    class ResultAggregation
    {
        public:
        struct Config
        {
            std::chrono::milliseconds m_timeout{ 5000 }; 
            size_t min_responses_ = 1;                  
            size_t max_responses_ = 10;                 
        };

        ResultAggregation();
        explicit ResultAggregation( Config cfg );

        void Submit( const NodeOutput& output );

        outcome::result<std::vector<NodeOutput>> Collect();

        void Reset();

        size_t ResponseCount() const;

        private:
        Config m_cfg;
        std::vector<NodeOutput> results_;
        mutable std::mutex m_mutex;
        std::condition_variable cv_;
        bool done_ = false;
    };

} // namespace sgns::neoswarm::network

#endif // NEOSWARM_NETWORK_RESULTAGGREGATION_HPP

Updated on 2026-07-25 at 22:56:57 +0000