Skip to content
Snippets Groups Projects
Select Git revision
  • 18e53b9ec83bf41f4b08431fe7e99a8bfaf6cd1f
  • master default
  • cmake_fixes
  • pulls/1772757862/750
  • copilot/fix-770
  • windows_ci_static
  • c_link
  • cpack
  • windows_ci
  • cert_pk_id
  • proxy_push_result
  • cnode_put_id
  • update-windows-build
  • proxy
  • resubscribe_on_token_change
  • actions
  • client_mode
  • llhttp
  • search_node_add
  • crypto_aes_gcm_argon2
  • ios_notifications
  • v3.4.0
  • v3.3.1
  • v3.3.1rc1
  • v3.3.1rc2
  • v3.3.0
  • v3.2.0
  • v3.1.11
  • v3.1.10
  • v3.1.9
  • v3.1.8.2
  • v3.1.8.1
  • v3.1.8
  • v3.1.7
  • v3.1.6
  • v3.1.5
  • v3.1.4
  • v3.1.3
  • v3.1.2
  • v3.1
  • v3.0.1
41 results

network_engine.cpp

Blame
  • Code owners
    Assign users and groups as approvers for specific file changes. Learn more.
    network_engine.cpp 46.59 KiB
    /*
     *  Copyright (C) 2014-2022 Savoir-faire Linux Inc.
     *  Author(s) : Adrien Béraud <adrien.beraud@savoirfairelinux.com>
     *              Simon Désaulniers <simon.desaulniers@savoirfairelinux.com>
     *
     *  This program is free software; you can redistribute it and/or modify
     *  it under the terms of the GNU General Public License as published by
     *  the Free Software Foundation; either version 3 of the License, or
     *  (at your option) any later version.
     *
     *  This program is distributed in the hope that it will be useful,
     *  but WITHOUT ANY WARRANTY; without even the implied warranty of
     *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     *  GNU General Public License for more details.
     *
     *  You should have received a copy of the GNU General Public License
     *  along with this program. If not, see <https://www.gnu.org/licenses/>.
     */
    
    #include "network_engine.h"
    #include "request.h"
    #include "default_types.h"
    #include "log_enable.h"
    #include "parsed_message.h"
    
    #include <msgpack.hpp>
    
    namespace dht {
    namespace net {
    using namespace std::chrono_literals;
    
    const std::string DhtProtocolException::GET_NO_INFOHASH {"Get_values with no info_hash"};
    const std::string DhtProtocolException::LISTEN_NO_INFOHASH {"Listen with no info_hash"};
    const std::string DhtProtocolException::LISTEN_WRONG_TOKEN {"Listen with wrong token"};
    const std::string DhtProtocolException::PUT_NO_INFOHASH {"Put with no info_hash"};
    const std::string DhtProtocolException::PUT_WRONG_TOKEN {"Put with wrong token"};
    const std::string DhtProtocolException::PUT_INVALID_ID {"Put with invalid id"};
    const std::string DhtProtocolException::STORAGE_NOT_FOUND {"Access operation for unknown storage"};
    
    constexpr std::chrono::seconds NetworkEngine::UDP_REPLY_TIME;
    constexpr std::chrono::seconds NetworkEngine::RX_MAX_PACKET_TIME;
    constexpr std::chrono::seconds NetworkEngine::RX_TIMEOUT;
    
    const std::string NetworkEngine::my_v {"RNG1"};
    
    static constexpr uint8_t v4prefix[16] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0xFF, 0xFF, 0, 0, 0, 0};
    
    constexpr unsigned SEND_NODES {8};
    
    
    struct NetworkEngine::PartialMessage {
        SockAddr from;
        time_point start;
        time_point last_part;
        std::unique_ptr<ParsedMessage> msg;
    };
    
    std::vector<Blob>
    serializeValues(const std::vector<Sp<Value>>& st)
    {
        std::vector<Blob> svals;
        svals.reserve(st.size());
        for (const auto& v : st)
            svals.emplace_back(packMsg(v));
        return svals;
    }
    
    void
    packToken(msgpack::packer<msgpack::sbuffer>& pk, const Blob& token)
    {