Monero
net_peerlist_boost_serialization.h
Go to the documentation of this file.
1 // Copyright (c) 2014-2018, 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 // Parts of this file are originally copyright (c) 2012-2013 The Cryptonote developers
30 
31 #pragma once
32 
33 #include "net/net_utils_base.h"
34 #include "p2p/p2p_protocol_defs.h"
35 
36 namespace boost
37 {
38  namespace serialization
39  {
40  template <class T, class Archive>
41  inline void do_serialize(Archive &a, epee::net_utils::network_address& na, T local)
42  {
43  if (typename Archive::is_saving()) local = na.as<T>();
44  a & local;
45  if (!typename Archive::is_saving()) na = local;
46  }
47  template <class Archive, class ver_type>
48  inline void serialize(Archive &a, epee::net_utils::network_address& na, const ver_type ver)
49  {
50  uint8_t type;
51  if (typename Archive::is_saving())
52  type = na.get_type_id();
53  a & type;
54  switch (type)
55  {
56  case epee::net_utils::ipv4_network_address::ID:
57  do_serialize(a, na, epee::net_utils::ipv4_network_address{0, 0});
58  break;
59  default:
60  throw std::runtime_error("Unsupported network address type");
61  }
62  }
63  template <class Archive, class ver_type>
64  inline void serialize(Archive &a, epee::net_utils::ipv4_network_address& na, const ver_type ver)
65  {
66  uint32_t ip{na.ip()};
67  uint16_t port{na.port()};
68  a & ip;
69  a & port;
70  if (!typename Archive::is_saving())
71  na = epee::net_utils::ipv4_network_address{ip, port};
72  }
73 
74  template <class Archive, class ver_type>
75  inline void serialize(Archive &a, nodetool::peerlist_entry& pl, const ver_type ver)
76  {
77  a & pl.adr;
78  a & pl.id;
79  a & pl.last_seen;
80  }
81 
82  template <class Archive, class ver_type>
83  inline void serialize(Archive &a, nodetool::anchor_peerlist_entry& pl, const ver_type ver)
84  {
85  a & pl.adr;
86  a & pl.id;
87  a & pl.first_seen;
88  }
89  }
90 }
Definition: binary_utils.h:36
int64_t last_seen
Definition: p2p_protocol_defs.h:74
const uint32_t T[512]
Definition: groestl_tables.h:33
Definition: unordered_containers_boost_serialization.h:37
AddressType adr
Definition: p2p_protocol_defs.h:72
void serialize(Archive &a, std::unordered_map< h_key, hval > &x, const boost::serialization::version_type ver)
Definition: unordered_containers_boost_serialization.h:126
AddressType adr
Definition: p2p_protocol_defs.h:87
int64_t first_seen
Definition: p2p_protocol_defs.h:89
void do_serialize(Archive &a, epee::net_utils::network_address &na, T local)
Definition: net_peerlist_boost_serialization.h:41
peerid_type id
Definition: p2p_protocol_defs.h:73
peerid_type id
Definition: p2p_protocol_defs.h:88
Definition: p2p_protocol_defs.h:85
string a
Definition: MakeCryptoOps.py:15
Definition: p2p_protocol_defs.h:70