コード例 #1
0
        void out_thread(master_post_office* o)
        try
        {
            REQUIRE(o);

            std::string last_address;

            bool sent = false;
            while(!o->_done || sent)
            try
            {
                sent = false;

                //get message from queue
                message m;
                if(!o->_out.pop(m, true))
                    continue;

                sent = true;

                REQUIRE_GREATER_EQUAL(m.meta.from.size(), 1);
                REQUIRE_GREATER_EQUAL(m.meta.to.size(), 1);

                const std::string outside_queue_address = m.meta.to.front();
                last_address = outside_queue_address;

                //encode message
                std::stringstream s;
                s << m;
                u::bytes data = u::to_bytes(s.str());

                //encrypt message
                if(m.meta.force == metadata::security::assymetric)
                    data = o->_session_library->encrypt_assymetric(outside_queue_address, data);
                else 
                    data = o->_session_library->encrypt(outside_queue_address, data);

                //send message over wire
                o->_connections.send(outside_queue_address, data);

                if(o->_outside_stats.on) o->_outside_stats.out_pop_count++;
                if(o->_done) u::sleep_thread(QUIT_SLEEP);
            }
            catch(std::exception& e)
            {
                LOG << "error sending message to " << last_address << ": " << e.what() << std::endl;
            }
            catch(...)
            {
                LOG << "error sending message to " << last_address << ": unknown error." << std::endl;
            }
        }
        catch(...)
        {
            LOG << "exit: master_post::out_thread" << std::endl;
        }
コード例 #2
0
ファイル: master_post.cpp プロジェクト: mempko/firestr
        void out_thread(master_post_office* o)
        try
        {
            REQUIRE(o);

            std::string last_address;

            while(!o->_done)
            try
            {
                //get message from queue
                message m;
                if(!o->_out.pop(m, true))
                    continue;

                REQUIRE_GREATER_EQUAL(m.meta.from.size(), 1);
                REQUIRE_GREATER_EQUAL(m.meta.to.size(), 1);

                const std::string outside_queue_address = m.meta.to.front();
                last_address = outside_queue_address;

                //encode, compress, and encrypt message
                auto data = u::encode(m);
                data = u::compress(data);

                encrypt_message(
                        data, 
                        m, 
                        outside_queue_address,
                        *o->_encrypted_channels);

                //send message over wire
                o->_connections.send(outside_queue_address, data, m.meta.robust);

                if(o->_outside_stats.on) o->_outside_stats.out_pop_count++;
            }
            catch(std::exception& e)
            {
                LOG << "error sending message to " << last_address << ": " << e.what() << std::endl;
            }
            catch(...)
            {
                LOG << "error sending message to " << last_address << ": unknown error." << std::endl;
            }
            u::sleep_thread(QUIT_SLEEP);
        }
        catch(...)
        {
            LOG << "exit: master_post::out_thread" << std::endl;
        }