Monero
Loading...
Searching...
No Matches
dandelionpp.h
Go to the documentation of this file.
1// Copyright (c) 2019-2022, The Monero Project
2//
3// All rights reserved.
4//
5// Redistribution and use in source and binary forms, with or without modification, are
6// permitted provided that the following conditions are met:
7//
8// 1. Redistributions of source code must retain the above copyright notice, this list of
9// conditions and the following disclaimer.
10//
11// 2. Redistributions in binary form must reproduce the above copyright notice, this list
12// of conditions and the following disclaimer in the documentation and/or other
13// materials provided with the distribution.
14//
15// 3. Neither the name of the copyright holder nor the names of its contributors may be
16// used to endorse or promote products derived from this software without specific
17// prior written permission.
18//
19// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
20// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
21// MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
22// THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
24// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
25// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
26// STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
27// THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28
29#pragma once
30
31#include <boost/uuid/uuid.hpp>
32#include <cstddef>
33#include <memory>
34#include <utility>
35#include <vector>
36
37#include "span.h"
38
39namespace net
40{
41namespace dandelionpp
42{
45 {
46 // Make sure to update clone method if changing members
47 std::vector<boost::uuids::uuid> out_mapping_; //<! Current outgoing uuid connection at index.
48 std::vector<std::pair<boost::uuids::uuid, std::size_t>> in_mapping_; //<! uuid source to an `out_mapping_` index.
49 std::vector<std::size_t> usage_count_;
50
51 // Use clone method to prevent "hidden" copies.
52 connection_map(const connection_map&) = default;
53
54 public:
55 using value_type = boost::uuids::uuid;
56 using size_type = std::vector<boost::uuids::uuid>::size_type;
57 using difference_type = std::vector<boost::uuids::uuid>::difference_type;
58 using reference = const boost::uuids::uuid&;
60 using iterator = std::vector<boost::uuids::uuid>::const_iterator;
62
64 explicit connection_map()
65 : connection_map(std::vector<boost::uuids::uuid>{}, 0)
66 {}
67
69 explicit connection_map(std::vector<boost::uuids::uuid> out_connections, std::size_t stems);
70
72 ~connection_map() noexcept;
73 connection_map& operator=(connection_map&&) = default;
74 connection_map& operator=(const connection_map&) = delete;
75
78
81 {
82 return out_mapping_.begin();
83 }
84
87 {
88 return out_mapping_.end();
89 }
90
97 bool update(std::vector<boost::uuids::uuid> current);
98
100 std::size_t size() const noexcept;
101
103 boost::uuids::uuid get_stem(const boost::uuids::uuid& source);
104 };
105} // dandelionpp
106} // net
iterator const_iterator
Definition dandelionpp.h:61
const boost::uuids::uuid & reference
Definition dandelionpp.h:58
~connection_map() noexcept
Definition dandelionpp.cpp:126
connection_map(connection_map &&)=default
std::vector< boost::uuids::uuid >::size_type size_type
Definition dandelionpp.h:56
std::vector< boost::uuids::uuid > out_mapping_
Definition dandelionpp.h:47
std::vector< boost::uuids::uuid >::const_iterator iterator
Definition dandelionpp.h:60
const_iterator end() const noexcept
Definition dandelionpp.h:86
std::vector< std::size_t > usage_count_
Definition dandelionpp.h:49
connection_map(const connection_map &)=default
connection_map clone() const
Definition dandelionpp.cpp:129
const_iterator begin() const noexcept
Definition dandelionpp.h:80
std::vector< boost::uuids::uuid >::difference_type difference_type
Definition dandelionpp.h:57
std::vector< std::pair< boost::uuids::uuid, std::size_t > > in_mapping_
Definition dandelionpp.h:48
boost::uuids::uuid value_type
Definition dandelionpp.h:55
connection_map()
Initialized with zero stem connections.
Definition dandelionpp.h:64
bool update(std::vector< boost::uuids::uuid > current)
Definition dandelionpp.cpp:134
boost::uuids::uuid get_stem(const boost::uuids::uuid &source)
Definition dandelionpp.cpp:183
std::size_t size() const noexcept
Definition dandelionpp.cpp:172
reference const_reference
Definition dandelionpp.h:59
#define const
Definition ipfrdr.c:80
const char * uuid
Definition minissdp.c:598
Definition portable_binary_archive.hpp:29
Definition dandelionpp.cpp:42
Definition net_utils_base.h:59
Definition enums.h:68
const CharType(& source)[N]
Definition pointer.h:1147