当前位置: 首页>>代码示例>>C++>>正文


C++ PacketPtr::encrypt方法代码示例

本文整理汇总了C++中PacketPtr::encrypt方法的典型用法代码示例。如果您正苦于以下问题:C++ PacketPtr::encrypt方法的具体用法?C++ PacketPtr::encrypt怎么用?C++ PacketPtr::encrypt使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在PacketPtr的用法示例。


在下文中一共展示了PacketPtr::encrypt方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: timerCallback

        void OutboundMessageFragments::timerCallback(const boost::system::error_code& e, PeerState ps, uint32_t const msgId)
        {
            if(!e) {
                std::lock_guard<std::mutex> lock(m_mutex);

                auto itr = m_states.find(msgId);
                if(itr != m_states.end()) {
                    OutboundMessageState& oms = itr->second;

                    if(oms.getTries() > 5) {
                        m_states.erase(msgId);
                        return;
                    }

                    PacketBuilder::FragmentPtr frag = oms.getNextUnackdFragment();
                    if(frag) {
                        std::vector<PacketBuilder::FragmentPtr> fragList;
                        fragList.push_back(frag);

                        oms.markFragmentSent(fragList[0]->fragNum);

                        PacketPtr p = PacketBuilder::buildData(ps.getEndpoint(), false, CompleteAckList(), PartialAckList(), fragList);
                        p->encrypt(ps.getCurrentSessionKey(), ps.getCurrentMacKey());
                        m_context.sendPacket(p);

                        oms.incrementTries();

                        oms.getTimer().expires_at(oms.getTimer().expires_at() + boost::posix_time::time_duration(0, 0, 2));
                        oms.getTimer().async_wait(boost::bind(&OutboundMessageFragments::timerCallback, this, boost::asio::placeholders::error, ps, msgId));
                    }
                }
            }
        }
开发者ID:anastiel,项目名称:i2pcpp,代码行数:33,代码来源:OutboundMessageFragments.cpp

示例2: sendDataCallback

        void OutboundMessageFragments::sendDataCallback(PeerState ps, uint32_t const msgId)
        {
            std::lock_guard<std::mutex> lock(m_mutex);

            auto itr = m_states.find(msgId);
            if(itr != m_states.end()) {
                OutboundMessageState& oms = itr->second;

                std::vector<PacketBuilder::FragmentPtr> fragList;
                auto fragment = oms.getNextFragment();

                if (fragment == nullptr) {
                    throw std::runtime_error("no ssu fragment when sending");
                }

                fragList.push_back(fragment);

                oms.markFragmentSent(fragList[0]->fragNum);

                PacketPtr p = PacketBuilder::buildData(ps.getEndpoint(), false, CompleteAckList(), PartialAckList(), fragList);
                p->encrypt(ps.getCurrentSessionKey(), ps.getCurrentMacKey());
                m_context.sendPacket(p);

                if(!oms.allFragmentsSent())
                    m_context.ios.post(boost::bind(&OutboundMessageFragments::sendDataCallback, this, ps, msgId));
            }
        }
开发者ID:anastiel,项目名称:i2pcpp,代码行数:27,代码来源:OutboundMessageFragments.cpp

示例3: processCreated

        void EstablishmentManager::processCreated(EstablishmentStatePtr const &state)
        {
            state->calculateDHSecret();

            if(!state->verifyCreationSignature()) {
                I2P_LOG(m_log, warning) << "creation signature verification failed";
                state->setState(EstablishmentState::State::FAILURE);
                return;
            }

            const ByteArray& dhSecret = state->getDHSecret();
            SessionKey newKey(toSessionKey(dhSecret)), newMacKey;

            state->setSessionKey(newKey);

            copy(dhSecret.begin() + 32, dhSecret.begin() + 32 + 32, newMacKey.begin());
            state->setMacKey(newMacKey);

            Endpoint ep = state->getTheirEndpoint();
            PeerState ps(ep, state->getTheirIdentity().getHash());
            ps.setCurrentSessionKey(state->getSessionKey());
            ps.setCurrentMacKey(state->getMacKey());

            std::lock_guard<std::mutex> lock(m_context.peers.getMutex());
            m_context.peers.addPeer(std::move(ps));

            PacketPtr p = PacketBuilder::buildSessionConfirmed(state);
            p->encrypt(state->getSessionKey(), state->getMacKey());

            m_context.sendPacket(p);

            state->setState(EstablishmentState::State::CONFIRMED_SENT);
            post(state);
        }
开发者ID:anastiel,项目名称:i2pcpp,代码行数:34,代码来源:EstablishmentManager.cpp

示例4: sendRequest

        void EstablishmentManager::sendRequest(EstablishmentStatePtr const &state)
        {
            PacketPtr p = PacketBuilder::buildSessionRequest(state);
            p->encrypt(state->getSessionKey(), state->getMacKey());

            m_context.sendPacket(p);

            state->setState(EstablishmentState::State::REQUEST_SENT);
            post(state);
        }
开发者ID:anastiel,项目名称:i2pcpp,代码行数:10,代码来源:EstablishmentManager.cpp

示例5: processRequest

        void EstablishmentManager::processRequest(EstablishmentStatePtr const &state)
        {
            state->calculateDHSecret();

            PacketPtr p = PacketBuilder::buildSessionCreated(state);
            p->encrypt(state->getIV(), state->getSessionKey(), state->getMacKey());

            const ByteArray& dhSecret = state->getDHSecret();
            SessionKey newKey(toSessionKey(dhSecret)), newMacKey;

            state->setSessionKey(newKey);

            copy(dhSecret.begin() + 32, dhSecret.begin() + 32 + 32, newMacKey.begin());
            state->setMacKey(newMacKey);

            m_context.sendPacket(p);

            state->setState(EstablishmentState::State::CREATED_SENT);
            post(state);
        }
开发者ID:anastiel,项目名称:i2pcpp,代码行数:20,代码来源:EstablishmentManager.cpp


注:本文中的PacketPtr::encrypt方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。