Line data Source code
1 : /* 2 : * Copyright (C) 2024 Savoir-faire Linux Inc. 3 : * Author: Fadi Shehadeh <fadi.shehadeh@savoirfairelinux.com> 4 : * 5 : * This program is free software; you can redistribute it and/or modify 6 : * it under the terms of the GNU General Public License as published by 7 : * the Free Software Foundation; either version 3 of the License, or 8 : * (at your option) any later version. 9 : * 10 : * This program is distributed in the hope that it will be useful, 11 : * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 : * GNU General Public License for more details. 14 : * 15 : * You should have received a copy of the GNU General Public License 16 : * along with this program. If not, see <https://www.gnu.org/licenses/>. 17 : */ 18 : #pragma once 19 : 20 : #include <string> 21 : #include <string_view> 22 : #include <msgpack.hpp> 23 : 24 : #include <opendht/infohash.h> 25 : 26 : using namespace std::literals; 27 : using NodeId = dht::h256; 28 : 29 : namespace jami { 30 : 31 : namespace swarm_protocol { 32 : 33 : static constexpr int version = 1; 34 : 35 : enum class Query : uint8_t { FIND = 1, FOUND = 2 }; 36 : 37 : using NodeId = dht::PkId; 38 : 39 : struct Request 40 : { 41 : Query q; // Type of query 42 : int num; // Number of nodes 43 : NodeId nodeId; 44 2580 : MSGPACK_DEFINE_MAP(q, num, nodeId); 45 : }; 46 : 47 : struct Response 48 : { 49 : Query q; 50 : std::vector<NodeId> nodes; 51 : std::vector<NodeId> mobile_nodes; 52 : 53 2562 : MSGPACK_DEFINE_MAP(q, nodes, mobile_nodes); 54 : }; 55 : 56 : struct Message 57 : { 58 : int v = version; 59 : bool is_mobile {false}; 60 : std::optional<Request> request; 61 : std::optional<Response> response; 62 5144 : MSGPACK_DEFINE_MAP(v, is_mobile, request, response); 63 : }; 64 : 65 : }; // namespace swarm_protocol 66 : 67 : } // namespace jami 68 5134 : MSGPACK_ADD_ENUM(jami::swarm_protocol::Query);