Electroneum
Loading...
Searching...
No Matches
nodetool::peerlist_storage Class Reference

#include <net_peerlist.h>

Public Member Functions

 peerlist_storage ()
 peerlist_storage (peerlist_storage &&)=default
 peerlist_storage (const peerlist_storage &)=delete
 ~peerlist_storage () noexcept
peerlist_storageoperator= (peerlist_storage &&)=default
peerlist_storageoperator= (const peerlist_storage &)=delete
bool store (std::ostream &dest, const peerlist_types &other) const
 Save peers from this and other in stream dest.
bool store (const std::string &path, const peerlist_types &other) const
 Save peers from this and other in one file at path.
peerlist_types take_zone (epee::net_utils::zone zone)

Static Public Member Functions

static boost::optional< peerlist_storageopen (std::istream &src, const bool new_format)
static boost::optional< peerlist_storageopen (const std::string &path)

Detailed Description

Definition at line 62 of file net_peerlist.h.

Constructor & Destructor Documentation

◆ peerlist_storage() [1/3]

nodetool::peerlist_storage::peerlist_storage ( )
inline

Definition at line 65 of file net_peerlist.h.

66 : m_types{}
67 {}
Here is the caller graph for this function:

◆ peerlist_storage() [2/3]

nodetool::peerlist_storage::peerlist_storage ( peerlist_storage && )
default
Here is the call graph for this function:

◆ peerlist_storage() [3/3]

nodetool::peerlist_storage::peerlist_storage ( const peerlist_storage & )
delete
Here is the call graph for this function:

◆ ~peerlist_storage()

nodetool::peerlist_storage::~peerlist_storage ( )
noexcept

Definition at line 222 of file net_peerlist.cpp.

223 {}

Member Function Documentation

◆ open() [1/2]

boost::optional< peerlist_storage > nodetool::peerlist_storage::open ( const std::string & path)
static
Returns
Peers stored in file at path

Definition at line 191 of file net_peerlist.cpp.

192 {
193 std::ifstream src_file{};
194 src_file.open( path , std::ios_base::binary | std::ios_base::in);
195 if(src_file.fail())
196 return boost::none;
197
198 boost::optional<peerlist_storage> out = open(src_file, true);
199 if (!out)
200 {
201 // if failed, try reading in unportable mode
202 boost::filesystem::copy_file(path, path + ".unportable", boost::filesystem::copy_options::overwrite_existing);
203 src_file.close();
204 src_file.open( path , std::ios_base::binary | std::ios_base::in);
205 if(src_file.fail())
206 return boost::none;
207
208 out = open(src_file, false);
209 if (!out)
210 {
211 // This is different from the `return boost::none` cases above. Those
212 // cases could fail due to bad file permissions, so a shutdown is
213 // likely more appropriate.
214 MWARNING("Failed to load p2p config file, falling back to default config");
215 out.emplace();
216 }
217 }
218
219 return out;
220 }
static boost::optional< peerlist_storage > open(std::istream &src, const bool new_format)
#define MWARNING(x)
Definition misc_log_ex.h:74
Here is the call graph for this function:

◆ open() [2/2]

boost::optional< peerlist_storage > nodetool::peerlist_storage::open ( std::istream & src,
const bool new_format )
static
Returns
Peers stored in stream src in new_format (portable archive or older non-portable).

Definition at line 161 of file net_peerlist.cpp.

162 {
163 try
164 {
166 if (new_format)
167 {
168 boost::archive::portable_binary_iarchive a{src};
169 a >> out.m_types;
170 }
171 else
172 {
173 boost::archive::binary_iarchive a{src};
174 a >> out.m_types;
175 }
176
177 if (src.good())
178 {
179 std::sort(out.m_types.white.begin(), out.m_types.white.end(), by_zone{});
180 std::sort(out.m_types.gray.begin(), out.m_types.gray.end(), by_zone{});
181 std::sort(out.m_types.anchor.begin(), out.m_types.anchor.end(), by_zone{});
182 return {std::move(out)};
183 }
184 }
185 catch (const std::exception& e)
186 {}
187
188 return boost::none;
189 }
const GenericPointer< typename T::ValueType > T2 T::AllocatorType & a
Definition pointer.h:1124
Here is the call graph for this function:
Here is the caller graph for this function:

◆ operator=() [1/2]

peerlist_storage & nodetool::peerlist_storage::operator= ( const peerlist_storage & )
delete
Here is the call graph for this function:

◆ operator=() [2/2]

peerlist_storage & nodetool::peerlist_storage::operator= ( peerlist_storage && )
default
Here is the call graph for this function:

◆ store() [1/2]

bool nodetool::peerlist_storage::store ( const std::string & path,
const peerlist_types & other ) const

Save peers from this and other in one file at path.

Definition at line 240 of file net_peerlist.cpp.

241 {
242 std::ofstream dest_file{};
243 dest_file.open( path , std::ios_base::binary | std::ios_base::out| std::ios::trunc);
244 if(dest_file.fail())
245 return false;
246
247 return store(dest_file, other);
248 }
bool store(std::ostream &dest, const peerlist_types &other) const
Save peers from this and other in stream dest.
Here is the call graph for this function:

◆ store() [2/2]

bool nodetool::peerlist_storage::store ( std::ostream & dest,
const peerlist_types & other ) const

Save peers from this and other in stream dest.

Definition at line 225 of file net_peerlist.cpp.

226 {
227 try
228 {
229 boost::archive::portable_binary_oarchive a{dest};
230 const peerlist_join pj{std::cref(m_types), std::cref(other)};
231 a << pj;
232 return dest.good();
233 }
234 catch (const boost::archive::archive_exception& e)
235 {}
236
237 return false;
238 }
CXA_THROW_INFO_T void(* dest)(void *))
Here is the caller graph for this function:

◆ take_zone()

peerlist_types nodetool::peerlist_storage::take_zone ( epee::net_utils::zone zone)
Returns
Peers in zone and from remove from this.

Definition at line 250 of file net_peerlist.cpp.

251 {
252 peerlist_types out{};
253 out.white = do_take_zone(m_types.white, zone);
254 out.gray = do_take_zone(m_types.gray, zone);
255 out.anchor = do_take_zone(m_types.anchor, zone);
256 return out;
257 }
Here is the caller graph for this function:

The documentation for this class was generated from the following files:
  • /home/abuild/rpmbuild/BUILD/electroneum-5.1.3.1-build/electroneum-5.1.3.1/src/p2p/net_peerlist.h
  • /home/abuild/rpmbuild/BUILD/electroneum-5.1.3.1-build/electroneum-5.1.3.1/src/p2p/net_peerlist.cpp