github.com/lbryio/lbcd@v0.22.119/addrmgr/doc.go (about) 1 // Copyright (c) 2014 The btcsuite developers 2 // Use of this source code is governed by an ISC 3 // license that can be found in the LICENSE file. 4 5 /* 6 Package addrmgr implements concurrency safe Bitcoin address manager. 7 8 # Address Manager Overview 9 10 In order maintain the peer-to-peer Bitcoin network, there needs to be a source 11 of addresses to connect to as nodes come and go. The Bitcoin protocol provides 12 the getaddr and addr messages to allow peers to communicate known addresses with 13 each other. However, there needs to a mechanism to store those results and 14 select peers from them. It is also important to note that remote peers can't 15 be trusted to send valid peers nor attempt to provide you with only peers they 16 control with malicious intent. 17 18 With that in mind, this package provides a concurrency safe address manager for 19 caching and selecting peers in a non-deterministic manner. The general idea is 20 the caller adds addresses to the address manager and notifies it when addresses 21 are connected, known good, and attempted. The caller also requests addresses as 22 it needs them. 23 24 The address manager internally segregates the addresses into groups and 25 non-deterministically selects groups in a cryptographically random manner. This 26 reduce the chances multiple addresses from the same nets are selected which 27 generally helps provide greater peer diversity, and perhaps more importantly, 28 drastically reduces the chances an attacker is able to coerce your peer into 29 only connecting to nodes they control. 30 31 The address manager also understands routability and Tor addresses and tries 32 hard to only return routable addresses. In addition, it uses the information 33 provided by the caller about connected, known good, and attempted addresses to 34 periodically purge peers which no longer appear to be good peers as well as 35 bias the selection toward known good peers. The general idea is to make a best 36 effort at only providing usable addresses. 37 */ 38 package addrmgr