rippled
SourceStrings.cpp
1 //------------------------------------------------------------------------------
2 /*
3  This file is part of rippled: https://github.com/ripple/rippled
4  Copyright (c) 2012, 2013 Ripple Labs Inc.
5 
6  Permission to use, copy, modify, and/or distribute this software for any
7  purpose with or without fee is hereby granted, provided that the above
8  copyright notice and this permission notice appear in all copies.
9 
10  THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
11  WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12  MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
13  ANY SPECIAL , DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14  WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
15  ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
16  OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17 */
18 //==============================================================================
19 
20 #include <ripple/peerfinder/impl/SourceStrings.h>
21 
22 namespace ripple {
23 namespace PeerFinder {
24 
26 {
27 public:
28  SourceStringsImp(std::string const& name, Strings const& strings)
29  : m_name(name), m_strings(strings)
30  {
31  }
32 
33  ~SourceStringsImp() = default;
34 
35  std::string const&
36  name() override
37  {
38  return m_name;
39  }
40 
41  void
42  fetch(Results& results, beast::Journal journal) override
43  {
44  results.addresses.resize(0);
45  results.addresses.reserve(m_strings.size());
46  for (int i = 0; i < m_strings.size(); ++i)
47  {
50  if (is_unspecified(ep))
52  if (!is_unspecified(ep))
53  results.addresses.push_back(ep);
54  }
55  }
56 
57 private:
60 };
61 
62 //------------------------------------------------------------------------------
63 
65 SourceStrings::New(std::string const& name, Strings const& strings)
66 {
67  return std::make_shared<SourceStringsImp>(name, strings);
68 }
69 
70 } // namespace PeerFinder
71 } // namespace ripple
std::vector::resize
T resize(T... args)
std::string
STL class.
std::shared_ptr
STL class.
ripple::PeerFinder::Source::name
virtual std::string const & name()=0
std::vector::reserve
T reserve(T... args)
std::vector< std::string >
std::vector::size
T size(T... args)
ripple::PeerFinder::SourceStringsImp::SourceStringsImp
SourceStringsImp(std::string const &name, Strings const &strings)
Definition: SourceStrings.cpp:28
ripple::PeerFinder::SourceStrings::Strings
std::vector< std::string > Strings
Definition: SourceStrings.h:35
ripple::PeerFinder::Source::Results::addresses
IPAddresses addresses
Definition: Source.h:49
ripple::PeerFinder::SourceStringsImp::~SourceStringsImp
~SourceStringsImp()=default
std::vector::push_back
T push_back(T... args)
ripple::PeerFinder::SourceStringsImp::name
std::string const & name() override
Definition: SourceStrings.cpp:36
ripple::PeerFinder::SourceStringsImp::m_name
std::string m_name
Definition: SourceStrings.cpp:58
beast::Journal
A generic endpoint for log messages.
Definition: Journal.h:58
ripple::PeerFinder::SourceStringsImp::m_strings
Strings m_strings
Definition: SourceStrings.cpp:59
ripple
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition: RCLCensorshipDetector.h:29
ripple::PeerFinder::SourceStrings
Provides addresses from a static set of strings.
Definition: SourceStrings.h:30
beast::IP::Endpoint::from_string
static Endpoint from_string(std::string const &s)
Definition: IPEndpoint.cpp:49
ripple::PeerFinder::SourceStringsImp::fetch
void fetch(Results &results, beast::Journal journal) override
Definition: SourceStrings.cpp:42
beast::IP::Endpoint
A version-independent IP address and port combination.
Definition: IPEndpoint.h:38
ripple::PeerFinder::Source::Results
The results of a fetch.
Definition: Source.h:41
ripple::PeerFinder::SourceStrings::New
static std::shared_ptr< Source > New(std::string const &name, Strings const &strings)
Definition: SourceStrings.cpp:65
ripple::PeerFinder::SourceStringsImp
Definition: SourceStrings.cpp:25