rippled
Predicates.h
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 #ifndef RIPPLE_PEERFINDER_SIM_PREDICATES_H_INCLUDED
21 #define RIPPLE_PEERFINDER_SIM_PREDICATES_H_INCLUDED
22 
23 namespace ripple {
24 namespace PeerFinder {
25 namespace Sim {
26 
29 template <typename Node>
31 {
32 public:
33  is_remote_node_pred(Node const& n) : node(n)
34  {
35  }
36  template <typename Link>
37  bool
38  operator()(Link const& l) const
39  {
40  return &node == &l.remote_node();
41  }
42 
43 private:
44  Node const& node;
45 };
46 
47 template <typename Node>
49 is_remote_node(Node const& node)
50 {
51  return is_remote_node_pred<Node>(node);
52 }
53 
54 template <typename Node>
55 is_remote_node_pred<Node>
56 is_remote_node(Node const* node)
57 {
58  return is_remote_node_pred<Node>(*node);
59 }
62 //------------------------------------------------------------------------------
63 
66 {
67 public:
68  explicit is_remote_endpoint(beast::IP::Endpoint const& address)
69  : m_endpoint(address)
70  {
71  }
72  template <typename Link>
73  bool
74  operator()(Link const& link) const
75  {
76  return link.remote_endpoint() == m_endpoint;
77  }
78 
79 private:
81 };
82 
83 } // namespace Sim
84 } // namespace PeerFinder
85 } // namespace ripple
86 
87 #endif
ripple::PeerFinder::Sim::is_remote_node
is_remote_node_pred< Node > is_remote_node(Node const &node)
Definition: Predicates.h:49
ripple::PeerFinder::Sim::is_remote_endpoint
UnaryPredicate, true if the remote address matches.
Definition: Predicates.h:65
ripple::PeerFinder::Sim::is_remote_node_pred::is_remote_node_pred
is_remote_node_pred(Node const &n)
Definition: Predicates.h:33
ripple::PeerFinder::Sim::is_remote_endpoint::operator()
bool operator()(Link const &link) const
Definition: Predicates.h:74
ripple::PeerFinder::Sim::is_remote_endpoint::m_endpoint
const beast::IP::Endpoint m_endpoint
Definition: Predicates.h:80
ripple::PeerFinder::Sim::is_remote_node_pred::node
Node const & node
Definition: Predicates.h:44
ripple::PeerFinder::Sim::is_remote_node_pred
UnaryPredicate, returns true if the 'to' node on a Link matches.
Definition: Predicates.h:30
ripple
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition: RCLCensorshipDetector.h:29
ripple::PeerFinder::Sim::is_remote_node_pred::operator()
bool operator()(Link const &l) const
Definition: Predicates.h:38
beast::IP::Endpoint
A version-independent IP address and port combination.
Definition: IPEndpoint.h:38
ripple::PeerFinder::Sim::is_remote_endpoint::is_remote_endpoint
is_remote_endpoint(beast::IP::Endpoint const &address)
Definition: Predicates.h:68