Skip to content
Snippets Groups Projects
Select Git revision
  • windows_ci
  • master default
  • 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
  • log_fmt
  • v2asio
  • fix-msvc
  • message_split
  • meson
  • build_unify
  • 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
40 results

infohash.cpp

Blame
  • Code owners
    Assign users and groups as approvers for specific file changes. Learn more.
    infohash.cpp 1.77 KiB
    /*
     *  Copyright (C) 2014-2022 Savoir-faire Linux Inc.
     *  Author : Adrien Béraud <adrien.beraud@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 "infohash.h"
    
    #include <functional>
    #include <sstream>
    #include <cstdio>
    
    using namespace std::literals;
    
    namespace dht {
    
    const HexMap hex_map = {};
    
    void
    NodeExport::msgpack_unpack(msgpack::object o)
    {
        if (o.type != msgpack::type::MAP)
            throw msgpack::type_error();
        if (o.via.map.size < 2)
            throw msgpack::type_error();
        if (o.via.map.ptr[0].key.as<std::string_view>() != "id"sv)
            throw msgpack::type_error();
        if (o.via.map.ptr[1].key.as<std::string_view>() != "addr"sv)
            throw msgpack::type_error();
        const auto& addr = o.via.map.ptr[1].val;
        if (addr.type != msgpack::type::BIN)
            throw msgpack::type_error();
        if (addr.via.bin.size > sizeof(sockaddr_storage))
            throw msgpack::type_error();
        id.msgpack_unpack(o.via.map.ptr[0].val);
        sslen = addr.via.bin.size;
        std::copy_n(addr.via.bin.ptr, addr.via.bin.size, (char*)&ss);
    }
    
    std::ostream& operator<< (std::ostream& s, const NodeExport& h)
    {
        msgpack::pack(s, h);
        return s;
    }
    
    }