mirror of
https://github.com/savoirfairelinux/opendht.git
synced 2026-11-08 12:28:42 +00:00
59 lines
1.8 KiB
C++
59 lines
1.8 KiB
C++
/*
|
|
* 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;
|
|
}
|
|
|
|
}
|