rippled
peerfinder/impl/Logic.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_LOGIC_H_INCLUDED
21 #define RIPPLE_PEERFINDER_LOGIC_H_INCLUDED
22 
23 #include <ripple/basics/Log.h>
24 #include <ripple/basics/contract.h>
25 #include <ripple/basics/random.h>
26 #include <ripple/beast/container/aged_container_utility.h>
27 #include <ripple/beast/net/IPAddressConversion.h>
28 #include <ripple/peerfinder/PeerfinderManager.h>
29 #include <ripple/peerfinder/impl/Bootcache.h>
30 #include <ripple/peerfinder/impl/Counts.h>
31 #include <ripple/peerfinder/impl/Fixed.h>
32 #include <ripple/peerfinder/impl/Handouts.h>
33 #include <ripple/peerfinder/impl/Livecache.h>
34 #include <ripple/peerfinder/impl/Reporting.h>
35 #include <ripple/peerfinder/impl/SlotImp.h>
36 #include <ripple/peerfinder/impl/Source.h>
37 #include <ripple/peerfinder/impl/Store.h>
38 #include <ripple/peerfinder/impl/iosformat.h>
39 
40 #include <algorithm>
41 #include <functional>
42 #include <map>
43 #include <memory>
44 #include <set>
45 
46 namespace ripple {
47 namespace PeerFinder {
48 
53 template <class Checker>
54 class Logic
55 {
56 public:
57  // Maps remote endpoints to slots. Since a slot has a
58  // remote endpoint upon construction, this holds all counts.
59  //
61 
66 
68 
69  // True if we are stopping.
70  bool stopping_ = false;
71 
72  // The source we are currently fetching.
73  // This is used to cancel I/O during program exit.
75 
76  // Configuration settings
78 
79  // Slot counts and other aggregate statistics.
81 
82  // A list of slots that should always be connected
84 
85  // Live livecache from mtENDPOINTS messages
87 
88  // LiveCache of addresses suitable for gaining initial connections
90 
91  // Holds all counts
93 
94  // The addresses (but not port) we are connected to. This includes
95  // outgoing connection attempts. Note that this set can contain
96  // duplicates (since the port is not set)
98 
99  // Set of public keys belonging to active peers
101 
102  // A list of dynamic sources to consult as a fallback
104 
106 
108 
109  //--------------------------------------------------------------------------
110 
112  clock_type& clock,
113  Store& store,
114  Checker& checker,
115  beast::Journal journal)
116  : m_journal(journal)
117  , m_clock(clock)
118  , m_store(store)
119  , m_checker(checker)
120  , livecache_(m_clock, journal)
121  , bootcache_(store, m_clock, journal)
122  , m_whenBroadcast(m_clock.now())
124  {
125  config({});
126  }
127 
128  // Load persistent state information from the Store
129  //
130  void
132  {
134  bootcache_.load();
135  }
136 
143  void
145  {
147  stopping_ = true;
148  if (fetchSource_ != nullptr)
149  fetchSource_->cancel();
150  }
151 
152  //--------------------------------------------------------------------------
153  //
154  // Manager
155  //
156  //--------------------------------------------------------------------------
157 
158  void
159  config(Config const& c)
160  {
162  config_ = c;
164  }
165 
166  Config
168  {
170  return config_;
171  }
172 
173  void
175  {
177  v.push_back(ep);
178  addFixedPeer(name, v);
179  }
180 
181  void
183  std::string const& name,
184  std::vector<beast::IP::Endpoint> const& addresses)
185  {
187 
188  if (addresses.empty())
189  {
190  JLOG(m_journal.info())
191  << "Could not resolve fixed slot '" << name << "'";
192  return;
193  }
194 
195  for (auto const& remote_address : addresses)
196  {
197  if (remote_address.port() == 0)
198  {
199  Throw<std::runtime_error>(
200  "Port not specified for address:" +
201  remote_address.to_string());
202  }
203 
204  auto result(fixed_.emplace(
205  std::piecewise_construct,
206  std::forward_as_tuple(remote_address),
208 
209  if (result.second)
210  {
211  JLOG(m_journal.debug())
212  << beast::leftw(18) << "Logic add fixed '" << name
213  << "' at " << remote_address;
214  return;
215  }
216  }
217  }
218 
219  //--------------------------------------------------------------------------
220 
221  // Called when the Checker completes a connectivity test
222  void
224  beast::IP::Endpoint const& remoteAddress,
225  beast::IP::Endpoint const& checkedAddress,
226  boost::system::error_code ec)
227  {
228  if (ec == boost::asio::error::operation_aborted)
229  return;
230 
232  auto const iter(slots_.find(remoteAddress));
233  if (iter == slots_.end())
234  {
235  // The slot disconnected before we finished the check
236  JLOG(m_journal.debug())
237  << beast::leftw(18) << "Logic tested " << checkedAddress
238  << " but the connection was closed";
239  return;
240  }
241 
242  SlotImp& slot(*iter->second);
243  slot.checked = true;
244  slot.connectivityCheckInProgress = false;
245 
246  if (ec)
247  {
248  // VFALCO TODO Should we retry depending on the error?
249  slot.canAccept = false;
250  JLOG(m_journal.error())
251  << beast::leftw(18) << "Logic testing " << iter->first
252  << " with error, " << ec.message();
253  bootcache_.on_failure(checkedAddress);
254  return;
255  }
256 
257  slot.canAccept = true;
258  slot.set_listening_port(checkedAddress.port());
259  JLOG(m_journal.debug()) << beast::leftw(18) << "Logic testing "
260  << checkedAddress << " succeeded";
261  }
262 
263  //--------------------------------------------------------------------------
264 
267  beast::IP::Endpoint const& local_endpoint,
268  beast::IP::Endpoint const& remote_endpoint)
269  {
270  JLOG(m_journal.debug())
271  << beast::leftw(18) << "Logic accept" << remote_endpoint
272  << " on local " << local_endpoint;
273 
275 
276  // Check for duplicate connection
277  if (is_public(remote_endpoint))
278  {
279  auto const count =
280  connectedAddresses_.count(remote_endpoint.address());
281  if (count > config_.ipLimit)
282  {
283  JLOG(m_journal.debug())
284  << beast::leftw(18) << "Logic dropping inbound "
285  << remote_endpoint << " because of ip limits.";
286  return SlotImp::ptr();
287  }
288  }
289 
290  // Create the slot
291  SlotImp::ptr const slot(std::make_shared<SlotImp>(
292  local_endpoint,
293  remote_endpoint,
294  fixed(remote_endpoint.address()),
295  m_clock));
296  // Add slot to table
297  auto const result(slots_.emplace(slot->remote_endpoint(), slot));
298  // Remote address must not already exist
299  assert(result.second);
300  // Add to the connected address list
301  connectedAddresses_.emplace(remote_endpoint.address());
302 
303  // Update counts
304  counts_.add(*slot);
305 
306  return result.first->second;
307  }
308 
309  // Can't check for self-connect because we don't know the local endpoint
311  new_outbound_slot(beast::IP::Endpoint const& remote_endpoint)
312  {
313  JLOG(m_journal.debug())
314  << beast::leftw(18) << "Logic connect " << remote_endpoint;
315 
317 
318  // Check for duplicate connection
319  if (slots_.find(remote_endpoint) != slots_.end())
320  {
321  JLOG(m_journal.debug())
322  << beast::leftw(18) << "Logic dropping " << remote_endpoint
323  << " as duplicate connect";
324  return SlotImp::ptr();
325  }
326 
327  // Create the slot
328  SlotImp::ptr const slot(std::make_shared<SlotImp>(
329  remote_endpoint, fixed(remote_endpoint), m_clock));
330 
331  // Add slot to table
332  auto const result = slots_.emplace(slot->remote_endpoint(), slot);
333  // Remote address must not already exist
334  assert(result.second);
335 
336  // Add to the connected address list
337  connectedAddresses_.emplace(remote_endpoint.address());
338 
339  // Update counts
340  counts_.add(*slot);
341 
342  return result.first->second;
343  }
344 
345  bool
347  SlotImp::ptr const& slot,
348  beast::IP::Endpoint const& local_endpoint)
349  {
350  JLOG(m_journal.trace())
351  << beast::leftw(18) << "Logic connected" << slot->remote_endpoint()
352  << " on local " << local_endpoint;
353 
355 
356  // The object must exist in our table
357  assert(slots_.find(slot->remote_endpoint()) != slots_.end());
358  // Assign the local endpoint now that it's known
359  slot->local_endpoint(local_endpoint);
360 
361  // Check for self-connect by address
362  {
363  auto const iter(slots_.find(local_endpoint));
364  if (iter != slots_.end())
365  {
366  assert(
367  iter->second->local_endpoint() == slot->remote_endpoint());
368  JLOG(m_journal.warn())
369  << beast::leftw(18) << "Logic dropping "
370  << slot->remote_endpoint() << " as self connect";
371  return false;
372  }
373  }
374 
375  // Update counts
376  counts_.remove(*slot);
377  slot->state(Slot::connected);
378  counts_.add(*slot);
379  return true;
380  }
381 
382  Result
383  activate(SlotImp::ptr const& slot, PublicKey const& key, bool reserved)
384  {
385  JLOG(m_journal.debug())
386  << beast::leftw(18) << "Logic handshake " << slot->remote_endpoint()
387  << " with " << (reserved ? "reserved " : "") << "key " << key;
388 
390 
391  // The object must exist in our table
392  assert(slots_.find(slot->remote_endpoint()) != slots_.end());
393  // Must be accepted or connected
394  assert(
395  slot->state() == Slot::accept || slot->state() == Slot::connected);
396 
397  // Check for duplicate connection by key
398  if (keys_.find(key) != keys_.end())
399  return Result::duplicate;
400 
401  // If the peer belongs to a cluster or is reserved,
402  // update the slot to reflect that.
403  counts_.remove(*slot);
404  slot->reserved(reserved);
405  counts_.add(*slot);
406 
407  // See if we have an open space for this slot
408  if (!counts_.can_activate(*slot))
409  {
410  if (!slot->inbound())
411  bootcache_.on_success(slot->remote_endpoint());
412  return Result::full;
413  }
414 
415  // Set the key right before adding to the map, otherwise we might
416  // assert later when erasing the key.
417  slot->public_key(key);
418  {
419  auto const result = keys_.insert(key);
420  // Public key must not already exist
421  assert(result.second);
422  (void)result.second;
423  }
424 
425  // Change state and update counts
426  counts_.remove(*slot);
427  slot->activate(m_clock.now());
428  counts_.add(*slot);
429 
430  if (!slot->inbound())
431  bootcache_.on_success(slot->remote_endpoint());
432 
433  // Mark fixed slot success
434  if (slot->fixed() && !slot->inbound())
435  {
436  auto iter(fixed_.find(slot->remote_endpoint()));
437  assert(iter != fixed_.end());
438  iter->second.success(m_clock.now());
439  JLOG(m_journal.trace()) << beast::leftw(18) << "Logic fixed "
440  << slot->remote_endpoint() << " success";
441  }
442 
443  return Result::success;
444  }
445 
451  redirect(SlotImp::ptr const& slot)
452  {
454  RedirectHandouts h(slot);
456  handout(&h, (&h) + 1, livecache_.hops.begin(), livecache_.hops.end());
457  return std::move(h.list());
458  }
459 
463  // VFALCO TODO This should add the returned addresses to the
464  // squelch list in one go once the list is built,
465  // rather than having each module add to the squelch list.
468  {
470 
472 
473  // Count how many more outbound attempts to make
474  //
475  auto needed(counts_.attempts_needed());
476  if (needed == 0)
477  return none;
478 
479  ConnectHandouts h(needed, m_squelches);
480 
481  // Make sure we don't connect to already-connected entries.
482  for (auto const& s : slots_)
483  {
484  auto const result(
485  m_squelches.insert(s.second->remote_endpoint().address()));
486  if (!result.second)
487  m_squelches.touch(result.first);
488  }
489 
490  // 1. Use Fixed if:
491  // Fixed active count is below fixed count AND
492  // ( There are eligible fixed addresses to try OR
493  // Any outbound attempts are in progress)
494  //
495  if (counts_.fixed_active() < fixed_.size())
496  {
497  get_fixed(needed, h.list(), m_squelches);
498 
499  if (!h.list().empty())
500  {
501  JLOG(m_journal.debug()) << beast::leftw(18) << "Logic connect "
502  << h.list().size() << " fixed";
503  return h.list();
504  }
505 
506  if (counts_.attempts() > 0)
507  {
508  JLOG(m_journal.debug())
509  << beast::leftw(18) << "Logic waiting on "
510  << counts_.attempts() << " attempts";
511  return none;
512  }
513  }
514 
515  // Only proceed if auto connect is enabled and we
516  // have less than the desired number of outbound slots
517  //
519  return none;
520 
521  // 2. Use Livecache if:
522  // There are any entries in the cache OR
523  // Any outbound attempts are in progress
524  //
525  {
527  handout(
528  &h, (&h) + 1, livecache_.hops.rbegin(), livecache_.hops.rend());
529  if (!h.list().empty())
530  {
531  JLOG(m_journal.debug())
532  << beast::leftw(18) << "Logic connect " << h.list().size()
533  << " live "
534  << ((h.list().size() > 1) ? "endpoints" : "endpoint");
535  return h.list();
536  }
537  else if (counts_.attempts() > 0)
538  {
539  JLOG(m_journal.debug())
540  << beast::leftw(18) << "Logic waiting on "
541  << counts_.attempts() << " attempts";
542  return none;
543  }
544  }
545 
546  /* 3. Bootcache refill
547  If the Bootcache is empty, try to get addresses from the current
548  set of Sources and add them into the Bootstrap cache.
549 
550  Pseudocode:
551  If ( domainNames.count() > 0 AND (
552  unusedBootstrapIPs.count() == 0
553  OR activeNameResolutions.count() > 0) )
554  ForOneOrMore (DomainName that hasn't been resolved recently)
555  Contact DomainName and add entries to the
556  unusedBootstrapIPs return;
557  */
558 
559  // 4. Use Bootcache if:
560  // There are any entries we haven't tried lately
561  //
562  for (auto iter(bootcache_.begin());
563  !h.full() && iter != bootcache_.end();
564  ++iter)
565  h.try_insert(*iter);
566 
567  if (!h.list().empty())
568  {
569  JLOG(m_journal.debug())
570  << beast::leftw(18) << "Logic connect " << h.list().size()
571  << " boot "
572  << ((h.list().size() > 1) ? "addresses" : "address");
573  return h.list();
574  }
575 
576  // If we get here we are stuck
577  return none;
578  }
579 
582  {
584  result;
585 
587 
588  clock_type::time_point const now = m_clock.now();
589  if (m_whenBroadcast <= now)
590  {
592 
593  {
594  // build list of active slots
596  slots.reserve(slots_.size());
598  slots_.cbegin(),
599  slots_.cend(),
600  [&slots](Slots::value_type const& value) {
601  if (value.second->state() == Slot::active)
602  slots.emplace_back(value.second);
603  });
604  std::shuffle(slots.begin(), slots.end(), default_prng());
605 
606  // build target vector
607  targets.reserve(slots.size());
609  slots.cbegin(),
610  slots.cend(),
611  [&targets](SlotImp::ptr const& slot) {
612  targets.emplace_back(slot);
613  });
614  }
615 
616  /* VFALCO NOTE
617  This is a temporary measure. Once we know our own IP
618  address, the correct solution is to put it into the Livecache
619  at hops 0, and go through the regular handout path. This way
620  we avoid handing our address out too frequenty, which this code
621  suffers from.
622  */
623  // Add an entry for ourselves if:
624  // 1. We want incoming
625  // 2. We have slots
626  // 3. We haven't failed the firewalled test
627  //
629  {
630  Endpoint ep;
631  ep.hops = 0;
632  // we use the unspecified (0) address here because the value is
633  // irrelevant to recipients. When peers receive an endpoint
634  // with 0 hops, they use the socket remote_addr instead of the
635  // value in the message. Furthermore, since the address value
636  // is ignored, the type/version (ipv4 vs ipv6) doesn't matter
637  // either. ipv6 has a slightly more compact string
638  // representation of 0, so use that for self entries.
641  for (auto& t : targets)
642  t.insert(ep);
643  }
644 
645  // build sequence of endpoints by hops
647  handout(
648  targets.begin(),
649  targets.end(),
651  livecache_.hops.end());
652 
653  // broadcast
654  for (auto const& t : targets)
655  {
656  SlotImp::ptr const& slot = t.slot();
657  auto const& list = t.list();
658  JLOG(m_journal.trace())
659  << beast::leftw(18) << "Logic sending "
660  << slot->remote_endpoint() << " with " << list.size()
661  << ((list.size() == 1) ? " endpoint" : " endpoints");
662  result.push_back(std::make_pair(slot, list));
663  }
664 
666  }
667 
668  return result;
669  }
670 
671  void
673  {
675 
676  // Expire the Livecache
677  livecache_.expire();
678 
679  // Expire the recent cache in each slot
680  for (auto const& entry : slots_)
681  entry.second->expire();
682 
683  // Expire the recent attempts table
685 
687  }
688 
689  //--------------------------------------------------------------------------
690 
691  // Validate and clean up the list that we received from the slot.
692  void
693  preprocess(SlotImp::ptr const& slot, Endpoints& list)
694  {
695  bool neighbor(false);
696  for (auto iter = list.begin(); iter != list.end();)
697  {
698  Endpoint& ep(*iter);
699 
700  // Enforce hop limit
701  if (ep.hops > Tuning::maxHops)
702  {
703  JLOG(m_journal.debug())
704  << beast::leftw(18) << "Endpoints drop " << ep.address
705  << " for excess hops " << ep.hops;
706  iter = list.erase(iter);
707  continue;
708  }
709 
710  // See if we are directly connected
711  if (ep.hops == 0)
712  {
713  if (!neighbor)
714  {
715  // Fill in our neighbors remote address
716  neighbor = true;
717  ep.address =
718  slot->remote_endpoint().at_port(ep.address.port());
719  }
720  else
721  {
722  JLOG(m_journal.debug())
723  << beast::leftw(18) << "Endpoints drop " << ep.address
724  << " for extra self";
725  iter = list.erase(iter);
726  continue;
727  }
728  }
729 
730  // Discard invalid addresses
731  if (!is_valid_address(ep.address))
732  {
733  JLOG(m_journal.debug()) << beast::leftw(18) << "Endpoints drop "
734  << ep.address << " as invalid";
735  iter = list.erase(iter);
736  continue;
737  }
738 
739  // Filter duplicates
740  if (std::any_of(
741  list.begin(),
742  iter,
743  [ep](Endpoints::value_type const& other) {
744  return ep.address == other.address;
745  }))
746  {
747  JLOG(m_journal.debug()) << beast::leftw(18) << "Endpoints drop "
748  << ep.address << " as duplicate";
749  iter = list.erase(iter);
750  continue;
751  }
752 
753  // Increment hop count on the incoming message, so
754  // we store it at the hop count we will send it at.
755  //
756  ++ep.hops;
757 
758  ++iter;
759  }
760  }
761 
762  void
764  {
765  // If we're sent too many endpoints, sample them at random:
766  if (list.size() > Tuning::numberOfEndpointsMax)
767  {
768  std::shuffle(list.begin(), list.end(), default_prng());
770  }
771 
772  JLOG(m_journal.trace())
773  << beast::leftw(18) << "Endpoints from " << slot->remote_endpoint()
774  << " contained " << list.size()
775  << ((list.size() > 1) ? " entries" : " entry");
776 
778 
779  // The object must exist in our table
780  assert(slots_.find(slot->remote_endpoint()) != slots_.end());
781 
782  // Must be handshaked!
783  assert(slot->state() == Slot::active);
784 
785  clock_type::time_point const now(m_clock.now());
786 
787  // Limit how often we accept new endpoints
788  if (slot->whenAcceptEndpoints > now)
789  return;
790 
791  preprocess(slot, list);
792 
793  for (auto const& ep : list)
794  {
795  assert(ep.hops != 0);
796 
797  slot->recent.insert(ep.address, ep.hops);
798 
799  // Note hops has been incremented, so 1
800  // means a directly connected neighbor.
801  //
802  if (ep.hops == 1)
803  {
804  if (slot->connectivityCheckInProgress)
805  {
806  JLOG(m_journal.debug())
807  << beast::leftw(18) << "Logic testing " << ep.address
808  << " already in progress";
809  continue;
810  }
811 
812  if (!slot->checked)
813  {
814  // Mark that a check for this slot is now in progress.
815  slot->connectivityCheckInProgress = true;
816 
817  // Test the slot's listening port before
818  // adding it to the livecache for the first time.
819  //
821  ep.address,
822  std::bind(
824  this,
825  slot->remote_endpoint(),
826  ep.address,
827  std::placeholders::_1));
828 
829  // Note that we simply discard the first Endpoint
830  // that the neighbor sends when we perform the
831  // listening test. They will just send us another
832  // one in a few seconds.
833 
834  continue;
835  }
836 
837  // If they failed the test then skip the address
838  if (!slot->canAccept)
839  continue;
840  }
841 
842  // We only add to the livecache if the neighbor passed the
843  // listening test, else we silently drop neighbor endpoint
844  // since their listening port is misconfigured.
845  //
846  livecache_.insert(ep);
847  bootcache_.insert(ep.address);
848  }
849 
850  slot->whenAcceptEndpoints = now + Tuning::secondsPerMessage;
851  }
852 
853  //--------------------------------------------------------------------------
854 
855  void
856  remove(SlotImp::ptr const& slot)
857  {
858  {
859  auto const iter = slots_.find(slot->remote_endpoint());
860  // The slot must exist in the table
861  assert(iter != slots_.end());
862  // Remove from slot by IP table
863  slots_.erase(iter);
864  }
865  // Remove the key if present
866  if (slot->public_key() != std::nullopt)
867  {
868  auto const iter = keys_.find(*slot->public_key());
869  // Key must exist
870  assert(iter != keys_.end());
871  keys_.erase(iter);
872  }
873  // Remove from connected address table
874  {
875  auto const iter(
876  connectedAddresses_.find(slot->remote_endpoint().address()));
877  // Address must exist
878  assert(iter != connectedAddresses_.end());
880  }
881 
882  // Update counts
883  counts_.remove(*slot);
884  }
885 
886  void
887  on_closed(SlotImp::ptr const& slot)
888  {
890 
891  remove(slot);
892 
893  // Mark fixed slot failure
894  if (slot->fixed() && !slot->inbound() && slot->state() != Slot::active)
895  {
896  auto iter(fixed_.find(slot->remote_endpoint()));
897  assert(iter != fixed_.end());
898  iter->second.failure(m_clock.now());
899  JLOG(m_journal.debug()) << beast::leftw(18) << "Logic fixed "
900  << slot->remote_endpoint() << " failed";
901  }
902 
903  // Do state specific bookkeeping
904  switch (slot->state())
905  {
906  case Slot::accept:
907  JLOG(m_journal.trace()) << beast::leftw(18) << "Logic accept "
908  << slot->remote_endpoint() << " failed";
909  break;
910 
911  case Slot::connect:
912  case Slot::connected:
913  bootcache_.on_failure(slot->remote_endpoint());
914  // VFALCO TODO If the address exists in the ephemeral/live
915  // endpoint livecache then we should mark the
916  // failure
917  // as if it didn't pass the listening test. We should also
918  // avoid propagating the address.
919  break;
920 
921  case Slot::active:
922  JLOG(m_journal.trace()) << beast::leftw(18) << "Logic close "
923  << slot->remote_endpoint();
924  break;
925 
926  case Slot::closing:
927  JLOG(m_journal.trace()) << beast::leftw(18) << "Logic finished "
928  << slot->remote_endpoint();
929  break;
930 
931  default:
932  assert(false);
933  break;
934  }
935  }
936 
937  void
939  {
941 
942  bootcache_.on_failure(slot->remote_endpoint());
943  }
944 
945  // Insert a set of redirect IP addresses into the Bootcache
946  template <class FwdIter>
947  void
948  onRedirects(
949  FwdIter first,
950  FwdIter last,
951  boost::asio::ip::tcp::endpoint const& remote_address);
952 
953  //--------------------------------------------------------------------------
954 
955  // Returns `true` if the address matches a fixed slot address
956  // Must have the lock held
957  bool
958  fixed(beast::IP::Endpoint const& endpoint) const
959  {
960  for (auto const& entry : fixed_)
961  if (entry.first == endpoint)
962  return true;
963  return false;
964  }
965 
966  // Returns `true` if the address matches a fixed slot address
967  // Note that this does not use the port information in the IP::Endpoint
968  // Must have the lock held
969  bool
970  fixed(beast::IP::Address const& address) const
971  {
972  for (auto const& entry : fixed_)
973  if (entry.first.address() == address)
974  return true;
975  return false;
976  }
977 
978  //--------------------------------------------------------------------------
979  //
980  // Connection Strategy
981  //
982  //--------------------------------------------------------------------------
983 
985  template <class Container>
986  void
988  std::size_t needed,
989  Container& c,
990  typename ConnectHandouts::Squelches& squelches)
991  {
992  auto const now(m_clock.now());
993  for (auto iter = fixed_.begin(); needed && iter != fixed_.end(); ++iter)
994  {
995  auto const& address(iter->first.address());
996  if (iter->second.when() <= now &&
997  squelches.find(address) == squelches.end() &&
998  std::none_of(
999  slots_.cbegin(),
1000  slots_.cend(),
1001  [address](Slots::value_type const& v) {
1002  return address == v.first.address();
1003  }))
1004  {
1005  squelches.insert(iter->first.address());
1006  c.push_back(iter->first);
1007  --needed;
1008  }
1009  }
1010  }
1011 
1012  //--------------------------------------------------------------------------
1013 
1014  void
1016  {
1017  fetch(source);
1018  }
1019 
1020  void
1022  {
1023  m_sources.push_back(source);
1024  }
1025 
1026  //--------------------------------------------------------------------------
1027  //
1028  // Bootcache livecache sources
1029  //
1030  //--------------------------------------------------------------------------
1031 
1032  // Add a set of addresses.
1033  // Returns the number of addresses added.
1034  //
1035  int
1037  {
1038  int count(0);
1040  for (auto addr : list)
1041  {
1042  if (bootcache_.insertStatic(addr))
1043  ++count;
1044  }
1045  return count;
1046  }
1047 
1048  // Fetch bootcache addresses from the specified source.
1049  void
1051  {
1052  Source::Results results;
1053 
1054  {
1055  {
1057  if (stopping_)
1058  return;
1059  fetchSource_ = source;
1060  }
1061 
1062  // VFALCO NOTE The fetch is synchronous,
1063  // not sure if that's a good thing.
1064  //
1065  source->fetch(results, m_journal);
1066 
1067  {
1069  if (stopping_)
1070  return;
1071  fetchSource_ = nullptr;
1072  }
1073  }
1074 
1075  if (!results.error)
1076  {
1077  int const count(addBootcacheAddresses(results.addresses));
1078  JLOG(m_journal.info())
1079  << beast::leftw(18) << "Logic added " << count << " new "
1080  << ((count == 1) ? "address" : "addresses") << " from "
1081  << source->name();
1082  }
1083  else
1084  {
1085  JLOG(m_journal.error()) << beast::leftw(18) << "Logic failed "
1086  << "'" << source->name() << "' fetch, "
1087  << results.error.message();
1088  }
1089  }
1090 
1091  //--------------------------------------------------------------------------
1092  //
1093  // Endpoint message handling
1094  //
1095  //--------------------------------------------------------------------------
1096 
1097  // Returns true if the IP::Endpoint contains no invalid data.
1098  bool
1100  {
1101  if (is_unspecified(address))
1102  return false;
1103  if (!is_public(address))
1104  return false;
1105  if (address.port() == 0)
1106  return false;
1107  return true;
1108  }
1109 
1110  //--------------------------------------------------------------------------
1111  //
1112  // PropertyStream
1113  //
1114  //--------------------------------------------------------------------------
1115 
1116  void
1118  {
1119  for (auto const& entry : slots)
1120  {
1122  SlotImp const& slot(*entry.second);
1123  if (slot.local_endpoint() != std::nullopt)
1124  item["local_address"] = to_string(*slot.local_endpoint());
1125  item["remote_address"] = to_string(slot.remote_endpoint());
1126  if (slot.inbound())
1127  item["inbound"] = "yes";
1128  if (slot.fixed())
1129  item["fixed"] = "yes";
1130  if (slot.reserved())
1131  item["reserved"] = "yes";
1132 
1133  item["state"] = stateString(slot.state());
1134  }
1135  }
1136 
1137  void
1139  {
1141 
1142  // VFALCO NOTE These ugly casts are needed because
1143  // of how std::size_t is declared on some linuxes
1144  //
1145  map["bootcache"] = std::uint32_t(bootcache_.size());
1146  map["fixed"] = std::uint32_t(fixed_.size());
1147 
1148  {
1149  beast::PropertyStream::Set child("peers", map);
1150  writeSlots(child, slots_);
1151  }
1152 
1153  {
1154  beast::PropertyStream::Map child("counts", map);
1155  counts_.onWrite(child);
1156  }
1157 
1158  {
1159  beast::PropertyStream::Map child("config", map);
1160  config_.onWrite(child);
1161  }
1162 
1163  {
1164  beast::PropertyStream::Map child("livecache", map);
1165  livecache_.onWrite(child);
1166  }
1167 
1168  {
1169  beast::PropertyStream::Map child("bootcache", map);
1170  bootcache_.onWrite(child);
1171  }
1172  }
1173 
1174  //--------------------------------------------------------------------------
1175  //
1176  // Diagnostics
1177  //
1178  //--------------------------------------------------------------------------
1179 
1180  Counts const&
1181  counts() const
1182  {
1183  return counts_;
1184  }
1185 
1186  static std::string
1188  {
1189  switch (state)
1190  {
1191  case Slot::accept:
1192  return "accept";
1193  case Slot::connect:
1194  return "connect";
1195  case Slot::connected:
1196  return "connected";
1197  case Slot::active:
1198  return "active";
1199  case Slot::closing:
1200  return "closing";
1201  default:
1202  break;
1203  };
1204  return "?";
1205  }
1206 };
1207 
1208 //------------------------------------------------------------------------------
1209 
1210 template <class Checker>
1211 template <class FwdIter>
1212 void
1214  FwdIter first,
1215  FwdIter last,
1216  boost::asio::ip::tcp::endpoint const& remote_address)
1217 {
1218  std::lock_guard _(lock_);
1219  std::size_t n = 0;
1220  for (; first != last && n < Tuning::maxRedirects; ++first, ++n)
1221  bootcache_.insert(beast::IPAddressConversion::from_asio(*first));
1222  if (n > 0)
1223  {
1224  JLOG(m_journal.trace()) << beast::leftw(18) << "Logic add " << n
1225  << " redirect IPs from " << remote_address;
1226  }
1227 }
1228 
1229 } // namespace PeerFinder
1230 } // namespace ripple
1231 
1232 #endif
ripple::PeerFinder::Checker
Tests remote listening sockets to make sure they are connectible.
Definition: Checker.h:39
ripple::PeerFinder::ConnectHandouts::full
bool full() const
Definition: Handouts.h:299
ripple::PeerFinder::Result::duplicate
@ duplicate
ripple::PeerFinder::Bootcache::insertStatic
bool insertStatic(beast::IP::Endpoint const &endpoint)
Add a staticallyconfigured address to the cache.
Definition: Bootcache.cpp:125
ripple::PeerFinder::Logic::m_clock
clock_type & m_clock
Definition: peerfinder/impl/Logic.h:63
std::vector::resize
T resize(T... args)
std::make_tuple
T make_tuple(T... args)
std::for_each
T for_each(T... args)
ripple::PeerFinder::Logic::m_sources
std::vector< std::shared_ptr< Source > > m_sources
Definition: peerfinder/impl/Logic.h:103
std::bind
T bind(T... args)
ripple::PeerFinder::SlotImp::inbound
bool inbound() const override
Returns true if this is an inbound connection.
Definition: SlotImp.h:52
std::string
STL class.
std::shared_ptr
STL class.
ripple::PeerFinder::Slot::accept
@ accept
Definition: peerfinder/Slot.h:37
ripple::PeerFinder::Logic::get_fixed
void get_fixed(std::size_t needed, Container &c, typename ConnectHandouts::Squelches &squelches)
Adds eligible Fixed addresses for outbound attempts.
Definition: peerfinder/impl/Logic.h:987
ripple::PeerFinder::Logic::load
void load()
Definition: peerfinder/impl/Logic.h:131
beast::Journal::trace
Stream trace() const
Severity stream access functions.
Definition: Journal.h:309
beast::PropertyStream::Map
Definition: PropertyStream.h:224
ripple::PeerFinder::Tuning::maxRedirects
@ maxRedirects
Definition: peerfinder/impl/Tuning.h:70
ripple::PeerFinder::ConnectHandouts
Receives handouts for making automatic connections.
Definition: Handouts.h:270
ripple::PeerFinder::Logic
The Logic for maintaining the list of Slot addresses.
Definition: peerfinder/impl/Logic.h:54
functional
ripple::PeerFinder::Slot::active
@ active
Definition: peerfinder/Slot.h:37
ripple::PeerFinder::Logic::keys_
std::set< PublicKey > keys_
Definition: peerfinder/impl/Logic.h:100
std::vector::reserve
T reserve(T... args)
ripple::PeerFinder::Logic::new_outbound_slot
SlotImp::ptr new_outbound_slot(beast::IP::Endpoint const &remote_endpoint)
Definition: peerfinder/impl/Logic.h:311
std::vector
STL class.
std::map::find
T find(T... args)
std::vector::size
T size(T... args)
ripple::PeerFinder::Logic::on_failure
void on_failure(SlotImp::ptr const &slot)
Definition: peerfinder/impl/Logic.h:938
ripple::PeerFinder::Logic::Logic
Logic(clock_type &clock, Store &store, Checker &checker, beast::Journal journal)
Definition: peerfinder/impl/Logic.h:111
ripple::PeerFinder::Livecache::onWrite
void onWrite(beast::PropertyStream::Map &map)
Output statistics.
Definition: Livecache.h:472
ripple::PeerFinder::Tuning::secondsPerMessage
constexpr std::chrono::seconds secondsPerMessage(151)
ripple::PeerFinder::Logic::m_whenBroadcast
clock_type::time_point m_whenBroadcast
Definition: peerfinder/impl/Logic.h:105
ripple::PeerFinder::RedirectHandouts
Receives handouts for redirecting a connection.
Definition: Handouts.h:102
ripple::PeerFinder::Logic::bootcache_
Bootcache bootcache_
Definition: peerfinder/impl/Logic.h:89
ripple::PeerFinder::Bootcache::on_failure
void on_failure(beast::IP::Endpoint const &endpoint)
Called when an outbound connection attempt fails to handshake.
Definition: Bootcache.cpp:173
ripple::PeerFinder::SlotImp::checked
bool checked
Definition: SlotImp.h:192
ripple::PeerFinder::Logic::fixed_
std::map< beast::IP::Endpoint, Fixed > fixed_
Definition: peerfinder/impl/Logic.h:83
beast::IP::Endpoint::address
Address const & address() const
Returns the address portion of this endpoint.
Definition: IPEndpoint.h:76
beast::detail::aged_ordered_container::insert
auto insert(value_type const &value) -> typename std::enable_if<!maybe_multi, std::pair< iterator, bool >>::type
Definition: aged_ordered_container.h:1747
std::map::emplace
T emplace(T... args)
ripple::PeerFinder::Logic::onRedirects
void onRedirects(FwdIter first, FwdIter last, boost::asio::ip::tcp::endpoint const &remote_address)
Definition: peerfinder/impl/Logic.h:1213
ripple::PeerFinder::Logic::addFixedPeer
void addFixedPeer(std::string const &name, std::vector< beast::IP::Endpoint > const &addresses)
Definition: peerfinder/impl/Logic.h:182
beast::Journal::warn
Stream warn() const
Definition: Journal.h:327
std::recursive_mutex
STL class.
std::lock_guard
STL class.
ripple::PeerFinder::Tuning::numberOfEndpointsMax
constexpr std::uint32_t numberOfEndpointsMax
Definition: peerfinder/impl/Tuning.h:116
ripple::PeerFinder::Logic::counts
Counts const & counts() const
Definition: peerfinder/impl/Logic.h:1181
ripple::PeerFinder::Logic::config_
Config config_
Definition: peerfinder/impl/Logic.h:77
ripple::PeerFinder::Bootcache::periodicActivity
void periodicActivity()
Stores the cache in the persistent database on a timer.
Definition: Bootcache.cpp:199
std::any_of
T any_of(T... args)
ripple::PeerFinder::Store
Abstract persistence for PeerFinder data.
Definition: Store.h:27
beast::PropertyStream::Set
Definition: PropertyStream.h:296
ripple::PeerFinder::Counts::can_activate
bool can_activate(Slot const &s) const
Returns true if the slot can become active.
Definition: Counts.h:71
algorithm
ripple::PeerFinder::Source::Results::addresses
IPAddresses addresses
Definition: Source.h:49
ripple::PeerFinder::Counts::inboundSlots
int inboundSlots() const
Returns the total number of inbound slots.
Definition: Counts.h:165
ripple::PeerFinder::Bootcache::load
void load()
Load the persisted data from the Store into the container.
Definition: Bootcache.cpp:88
beast::abstract_clock::now
virtual time_point now() const =0
Returns the current time.
std::multiset< beast::IP::Address >
std::vector::push_back
T push_back(T... args)
beast::IPAddressConversion::from_asio
static IP::Endpoint from_asio(boost::asio::ip::address const &address)
Definition: IPAddressConversion.h:63
ripple::PeerFinder::Result::success
@ success
ripple::PeerFinder::Livecache::insert
void insert(Endpoint const &ep)
Creates or updates an existing Element based on a new message.
Definition: Livecache.h:427
ripple::PeerFinder::Counts::out_max
int out_max() const
Returns the total number of outbound slots.
Definition: Counts.h:103
ripple::PeerFinder::Logic::m_checker
Checker & m_checker
Definition: peerfinder/impl/Logic.h:65
ripple::PeerFinder::Counts
Manages the count of available connections for the various slots.
Definition: Counts.h:34
ripple::PeerFinder::RedirectHandouts::list
std::vector< Endpoint > & list()
Definition: Handouts.h:125
ripple::PeerFinder::Bootcache::size
map_type::size_type size() const
Returns the number of entries in the cache.
Definition: Bootcache.cpp:49
ripple::PeerFinder::Config::wantIncoming
bool wantIncoming
true if we want to accept incoming connections.
Definition: PeerfinderManager.h:64
ripple::PeerFinder::Logic::onConnected
bool onConnected(SlotImp::ptr const &slot, beast::IP::Endpoint const &local_endpoint)
Definition: peerfinder/impl/Logic.h:346
beast::detail::aged_ordered_container::find
iterator find(K const &k)
Definition: aged_ordered_container.h:1015
beast::IP::Address
boost::asio::ip::address Address
Definition: IPAddress.h:41
ripple::PublicKey
A public key.
Definition: PublicKey.h:59
ripple::PeerFinder::Logic::addStaticSource
void addStaticSource(std::shared_ptr< Source > const &source)
Definition: peerfinder/impl/Logic.h:1015
ripple::PeerFinder::Logic::lock_
std::recursive_mutex lock_
Definition: peerfinder/impl/Logic.h:67
ripple::PeerFinder::Bootcache
Stores IP addresses useful for gaining initial connections.
Definition: Bootcache.h:51
ripple::PeerFinder::Logic::buildEndpointsForPeers
std::vector< std::pair< std::shared_ptr< Slot >, std::vector< Endpoint > > > buildEndpointsForPeers()
Definition: peerfinder/impl/Logic.h:581
ripple::PeerFinder::Bootcache::insert
bool insert(beast::IP::Endpoint const &endpoint)
Add a newly-learned address to the cache.
Definition: Bootcache.cpp:111
ripple::PeerFinder::Logic::redirect
std::vector< Endpoint > redirect(SlotImp::ptr const &slot)
Return a list of addresses suitable for redirection.
Definition: peerfinder/impl/Logic.h:451
ripple::PeerFinder::Logic::onWrite
void onWrite(beast::PropertyStream::Map &map)
Definition: peerfinder/impl/Logic.h:1138
ripple::PeerFinder::ConnectHandouts::list
list_type & list()
Definition: Handouts.h:311
ripple::JsonOptions::none
@ none
ripple::PeerFinder::Counts::out_active
int out_active() const
Returns the number of outbound peers assigned an open slot.
Definition: Counts.h:112
ripple::PeerFinder::Bootcache::end
const_iterator end() const
Definition: Bootcache.cpp:67
ripple::PeerFinder::Livecache::hops_t::shuffle
void shuffle()
Shuffle each hop list.
Definition: Livecache.h:495
ripple::PeerFinder::Slot::connected
@ connected
Definition: peerfinder/Slot.h:37
ripple::PeerFinder::SlotImp::canAccept
bool canAccept
Definition: SlotImp.h:196
ripple::PeerFinder::Livecache::hops_t::rbegin
reverse_iterator rbegin()
Definition: Livecache.h:305
ripple::PeerFinder::Logic::connectedAddresses_
std::multiset< beast::IP::Address > connectedAddresses_
Definition: peerfinder/impl/Logic.h:97
ripple::set
bool set(T &target, std::string const &name, Section const &section)
Set a value from a configuration Section If the named value is not found or doesn't parse as a T,...
Definition: BasicConfig.h:313
ripple::default_prng
beast::xor_shift_engine & default_prng()
Return the default random engine.
Definition: ripple/basics/random.h:65
ripple::PeerFinder::Logic::stop
void stop()
Stop the logic.
Definition: peerfinder/impl/Logic.h:144
ripple::PeerFinder::Logic::counts_
Counts counts_
Definition: peerfinder/impl/Logic.h:80
beast::Journal::error
Stream error() const
Definition: Journal.h:333
beast::Journal::info
Stream info() const
Definition: Journal.h:321
ripple::PeerFinder::Logic::autoconnect
std::vector< beast::IP::Endpoint > autoconnect()
Create new outbound connection attempts as needed.
Definition: peerfinder/impl/Logic.h:467
std::vector::erase
T erase(T... args)
ripple::PeerFinder::Endpoint::hops
std::uint32_t hops
Definition: PeerfinderManager.h:119
beast::IP::Endpoint::port
Port port() const
Returns the port number on the endpoint.
Definition: IPEndpoint.h:62
ripple::PeerFinder::Counts::onConfig
void onConfig(Config const &config)
Called when the config is set or changed.
Definition: Counts.h:135
ripple::PeerFinder::Logic::fixed
bool fixed(beast::IP::Address const &address) const
Definition: peerfinder/impl/Logic.h:970
ripple::PeerFinder::Livecache
The Livecache holds the short-lived relayed Endpoint messages.
Definition: Livecache.h:39
ripple::PeerFinder::SlotImp::local_endpoint
std::optional< beast::IP::Endpoint > const & local_endpoint() const override
The local endpoint of the socket, when known.
Definition: SlotImp.h:82
ripple::PeerFinder::Logic::addFixedPeer
void addFixedPeer(std::string const &name, beast::IP::Endpoint const &ep)
Definition: peerfinder/impl/Logic.h:174
beast::Journal
A generic endpoint for log messages.
Definition: Journal.h:58
beast::expire
std::enable_if< is_aged_container< AgedContainer >::value, std::size_t >::type expire(AgedContainer &c, std::chrono::duration< Rep, Period > const &age)
Expire aged container items past the specified age.
Definition: aged_container_utility.h:33
std::uint32_t
ripple::PeerFinder::Slot::closing
@ closing
Definition: peerfinder/Slot.h:37
std::forward_as_tuple
T forward_as_tuple(T... args)
map
ripple::PeerFinder::Tuning::recentAttemptDuration
constexpr std::chrono::seconds recentAttemptDuration(60)
ripple::PeerFinder::Logic::checkComplete
void checkComplete(beast::IP::Endpoint const &remoteAddress, beast::IP::Endpoint const &checkedAddress, boost::system::error_code ec)
Definition: peerfinder/impl/Logic.h:223
ripple::PeerFinder::Logic::fetchSource_
std::shared_ptr< Source > fetchSource_
Definition: peerfinder/impl/Logic.h:74
ripple::PeerFinder::Logic::activate
Result activate(SlotImp::ptr const &slot, PublicKey const &key, bool reserved)
Definition: peerfinder/impl/Logic.h:383
ripple::PeerFinder::Logic::addSource
void addSource(std::shared_ptr< Source > const &source)
Definition: peerfinder/impl/Logic.h:1021
beast::IP::AddressV6
boost::asio::ip::address_v6 AddressV6
Definition: IPAddressV6.h:34
ripple::PeerFinder::Slot::State
State
Definition: peerfinder/Slot.h:37
ripple::PeerFinder::Source::Results::error
boost::system::error_code error
Definition: Source.h:46
ripple::PeerFinder::Logic::fetch
void fetch(std::shared_ptr< Source > const &source)
Definition: peerfinder/impl/Logic.h:1050
beast::abstract_clock< std::chrono::steady_clock >
memory
ripple::PeerFinder::Bootcache::onWrite
void onWrite(beast::PropertyStream::Map &map)
Write the cache state to the property stream.
Definition: Bootcache.cpp:207
ripple::PeerFinder::Logic::stateString
static std::string stateString(Slot::State state)
Definition: peerfinder/impl/Logic.h:1187
ripple::PeerFinder::Bootcache::on_success
void on_success(beast::IP::Endpoint const &endpoint)
Called when an outbound connection handshake completes.
Definition: Bootcache.cpp:147
ripple::PeerFinder::Logic::remove
void remove(SlotImp::ptr const &slot)
Definition: peerfinder/impl/Logic.h:856
ripple::PeerFinder::Livecache::hops
class ripple::PeerFinder::Livecache::hops_t hops
ripple::PeerFinder::Logic::once_per_second
void once_per_second()
Definition: peerfinder/impl/Logic.h:672
beast::leftw
Left justifies a field at the specified width.
Definition: iosformat.h:33
ripple::PeerFinder::handout
void handout(TargetFwdIter first, TargetFwdIter last, SeqFwdIter seq_first, SeqFwdIter seq_last)
Distributes objects to targets according to business rules.
Definition: Handouts.h:67
ripple
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition: RCLCensorshipDetector.h:29
beast::detail::aged_ordered_container::end
iterator end()
Definition: aged_ordered_container.h:728
ripple::PeerFinder::Livecache::hops_t::end
iterator end()
Definition: Livecache.h:287
ripple::PeerFinder::Logic::m_journal
beast::Journal m_journal
Definition: peerfinder/impl/Logic.h:62
ripple::PeerFinder::Config::listeningPort
std::uint16_t listeningPort
The listening port number.
Definition: PeerfinderManager.h:70
beast::detail::aged_ordered_container
Associative container where each element is also indexed by time.
Definition: aged_ordered_container.h:82
ripple::PeerFinder::Counts::fixed_active
std::size_t fixed_active() const
Returns the number of active fixed connections.
Definition: Counts.h:126
ripple::PeerFinder::Logic::fixed
bool fixed(beast::IP::Endpoint const &endpoint) const
Definition: peerfinder/impl/Logic.h:958
ripple::PeerFinder::ConnectHandouts::try_insert
bool try_insert(beast::IP::Endpoint const &endpoint)
Definition: Handouts.h:332
std::map::cbegin
T cbegin(T... args)
ripple::PeerFinder::Counts::attempts
std::size_t attempts() const
Returns the number of outbound connection attempts.
Definition: Counts.h:96
ripple::PeerFinder::Checker::async_connect
void async_connect(beast::IP::Endpoint const &endpoint, Handler &&handler)
Performs an async connection test on the specified endpoint.
Definition: Checker.h:207
ripple::PeerFinder::SlotImp::set_listening_port
void set_listening_port(std::uint16_t port)
Definition: SlotImp.h:103
ripple::PeerFinder::Counts::add
void add(Slot const &s)
Adds the slot state and properties to the slot counts.
Definition: Counts.h:57
ripple::PeerFinder::Livecache::expire
void expire()
Erase entries whose time has expired.
Definition: Livecache.h:405
ripple::PeerFinder::Logic::new_inbound_slot
SlotImp::ptr new_inbound_slot(beast::IP::Endpoint const &local_endpoint, beast::IP::Endpoint const &remote_endpoint)
Definition: peerfinder/impl/Logic.h:266
ripple::PeerFinder::Logic::config
Config config()
Definition: peerfinder/impl/Logic.h:167
beast::detail::aged_ordered_container::touch
void touch(beast::detail::aged_container_iterator< is_const, Iterator > pos)
Definition: aged_ordered_container.h:989
ripple::PeerFinder::Counts::onWrite
void onWrite(beast::PropertyStream::Map &map)
Output statistics.
Definition: Counts.h:227
std::multiset::count
T count(T... args)
ripple::PeerFinder::Logic::writeSlots
void writeSlots(beast::PropertyStream::Set &set, Slots const &slots)
Definition: peerfinder/impl/Logic.h:1117
ripple::PeerFinder::Logic::stopping_
bool stopping_
Definition: peerfinder/impl/Logic.h:70
ripple::PeerFinder::Logic::m_store
Store & m_store
Definition: peerfinder/impl/Logic.h:64
std::vector::empty
T empty(T... args)
ripple::PeerFinder::Logic::preprocess
void preprocess(SlotImp::ptr const &slot, Endpoints &list)
Definition: peerfinder/impl/Logic.h:693
ripple::PeerFinder::Logic::slots_
Slots slots_
Definition: peerfinder/impl/Logic.h:92
beast::Journal::debug
Stream debug() const
Definition: Journal.h:315
std::size_t
ripple::to_string
std::string to_string(Manifest const &m)
Format the specified manifest to a string for debugging purposes.
Definition: app/misc/impl/Manifest.cpp:41
ripple::PeerFinder::Bootcache::begin
const_iterator begin() const
IP::Endpoint iterators that traverse in decreasing valence.
Definition: Bootcache.cpp:55
std::make_pair
T make_pair(T... args)
ripple::PeerFinder::Logic::is_valid_address
bool is_valid_address(beast::IP::Endpoint const &address)
Definition: peerfinder/impl/Logic.h:1099
beast::IP::Endpoint
A version-independent IP address and port combination.
Definition: IPEndpoint.h:38
std::map::end
T end(T... args)
ripple::PeerFinder::SlotImp::ptr
std::shared_ptr< SlotImp > ptr
Definition: SlotImp.h:36
ripple::PeerFinder::Config::autoConnect
bool autoConnect
true if we want to establish connections automatically
Definition: PeerfinderManager.h:67
ripple::PeerFinder::Tuning::maxHops
constexpr std::uint32_t maxHops
Definition: peerfinder/impl/Tuning.h:110
ripple::PeerFinder::Config
PeerFinder configuration settings.
Definition: PeerfinderManager.h:40
ripple::PeerFinder::Counts::attempts_needed
std::size_t attempts_needed() const
Returns the number of attempts needed to bring us to the max.
Definition: Counts.h:87
ripple::PeerFinder::Logic::on_closed
void on_closed(SlotImp::ptr const &slot)
Definition: peerfinder/impl/Logic.h:887
ripple::PeerFinder::SlotImp::state
State state() const override
Returns the state of the connection.
Definition: SlotImp.h:70
beast::IP::Endpoint::at_port
Endpoint at_port(Port port) const
Returns a new Endpoint with a different port.
Definition: IPEndpoint.h:69
ripple::PeerFinder::Logic::livecache_
Livecache livecache_
Definition: peerfinder/impl/Logic.h:86
ripple::PeerFinder::SlotImp
Definition: SlotImp.h:33
ripple::PeerFinder::Source::Results
The results of a fetch.
Definition: Source.h:41
ripple::PeerFinder::Slot::connect
@ connect
Definition: peerfinder/Slot.h:37
ripple::PeerFinder::Endpoint
Describes a connectible peer address along with some metadata.
Definition: PeerfinderManager.h:113
ripple::PeerFinder::Logic::config
void config(Config const &c)
Definition: peerfinder/impl/Logic.h:159
ripple::PeerFinder::SlotImp::reserved
bool reserved() const override
Returns true if this is a reserved connection.
Definition: SlotImp.h:64
std::shuffle
T shuffle(T... args)
ripple::PeerFinder::Counts::remove
void remove(Slot const &s)
Removes the slot state and properties from the slot counts.
Definition: Counts.h:64
ripple::PeerFinder::Result::full
@ full
beast::abstract_clock::time_point
typename Clock::time_point time_point
Definition: abstract_clock.h:63
ripple::PeerFinder::Logic::m_squelches
ConnectHandouts::Squelches m_squelches
Definition: peerfinder/impl/Logic.h:107
ripple::PeerFinder::Livecache::hops_t::rend
reverse_iterator rend()
Definition: Livecache.h:323
ripple::PeerFinder::Config::onWrite
void onWrite(beast::PropertyStream::Map &map)
Write the configuration into a property stream.
Definition: PeerfinderConfig.cpp:66
ripple::PeerFinder::Endpoint::address
beast::IP::Endpoint address
Definition: PeerfinderManager.h:120
ripple::PeerFinder::Config::ipLimit
int ipLimit
Limit how many incoming connections we allow per IP.
Definition: PeerfinderManager.h:76
ripple::PeerFinder::SlotImp::connectivityCheckInProgress
bool connectivityCheckInProgress
Definition: SlotImp.h:200
set
std::ref
T ref(T... args)
ripple::PeerFinder::SlotImp::fixed
bool fixed() const override
Returns true if this is a fixed connection.
Definition: SlotImp.h:58
ripple::PeerFinder::SlotImp::remote_endpoint
beast::IP::Endpoint const & remote_endpoint() const override
The remote endpoint of socket.
Definition: SlotImp.h:76
ripple::PeerFinder::Logic::addBootcacheAddresses
int addBootcacheAddresses(IPAddresses const &list)
Definition: peerfinder/impl/Logic.h:1036
ripple::PeerFinder::Logic::on_endpoints
void on_endpoints(SlotImp::ptr const &slot, Endpoints list)
Definition: peerfinder/impl/Logic.h:763
ripple::PeerFinder::Result
Result
Possible results from activating a slot.
Definition: PeerfinderManager.h:135
ripple::PeerFinder::Livecache::hops_t::begin
iterator begin()
Definition: Livecache.h:269