Commit Graph

94 Commits

Author SHA1 Message Date
Dave Collins
318d81bc90
multi: Wrap errors for better errors.Is/As support.
This updates all remaining cases of unwrapped errors in fmt.Errorf calls
to wrap the underlying errors with the %w format verb to ensure they
work nicely with errors.Is and errors.As.
2023-08-25 16:31:11 -05:00
Dave Collins
fc54d98b1e
multi: Remove a bunch of dup words in comments. 2023-08-23 14:13:51 -05:00
Dave Collins
4f2be61d57
addrmgr: Prepare v2.0.2.
This updates the addrmgr module dependencies and serves as a base for
addrmgr/v2.0.2.

The updated direct dependencies in this commit are as follows:

- github.com/decred/dcrd/chaincfg/chainhash@v1.0.4
- github.com/decred/dcrd/wire@v1.6.0

The updated indirect dependencies in this commit are as follows:

- github.com/decred/dcrd/crypto/blake256@v1.0.1
- github.com/klauspost/cpuid/v2@v2.0.9
- lukechampine.com/blake3 v1.2.1

The full list of updated direct and indirect dependencies since the
previous addrmgr/v2.0.1 release are the same as above.

Finally, all modules in the repository are tidied to ensure they are
updated to use the latest versions hoisted forward as a result.
2023-06-07 14:54:30 -05:00
Jonathan Chappelow
3bc18a3be5 addrmgr: set min value and optimize address chance
This updates the (*KnownAddress).chance method in the following ways:
1. Apply a lower limit to the return value.  Using 0.01  as this minimum
   prevents tiny chance values from causing excessive iterations in
   (*AddrManager).GetAddress, currently the only caller.
2. Replace an inefficient loop with a single math.Pow.

These changes are mitigations to excessive CPU use in the GetAddress
method that manifest when the number of attempts for a KnownAddress
becomes large.  However, this method and much of addrmgr should be
rewritten in the future since there are some ad hoc and questionable
approaches to candidate address selection.
2023-01-21 01:33:32 -06:00
Jonathan Chappelow
1c09ad77ca addrmgr: break after selecting random address
This adds a missing break statement to the range over the map of
addresses used to select a random entry from the map.  Previously
the loop would continue needlessly until the entire map was traversed.
This is a minor optimization.
2023-01-21 01:33:32 -06:00
Dave Collins
ad02d8f300
multi: Go 1.19 doc comment formatting.
This modifies the entire repository to use the new formatting of doc
comments in the upcoming Go 1.19 release.

The primary motivating factors for this are:

- Builds check that files are formatted per gofmt and that will no
  longer be true as of Go 1.19 without these changes
- Separating all the updates into a single commit ensures these
  documentation only formatting changes do not clutter up diffs that
  actually change code

For the most part, the changes are just the automated changes suggested
by the Go 1.19 version of gofmt, but there are also a few cases where
the comments were reworded a bit to play nicely with the new formatting
requirements.

For example, the new version of gofmt reformats and collapses nested
lists where as the existing version does not.  Thus, instances of nested
lists have been changed to either eliminate them or use mixed markers
which produce expect results.
2022-07-30 04:08:58 -05:00
Dave Collins
7d59dd3b69
multi: Support module graph prune and lazy load.
This bumps the go directive for all of the modules provided by the
repository to 1.17 which will allow the new module graph pruning and
lazy loading capabilities introduced in Go 1.17 to be used once the
updated modules are released.

This means that, as described by the documentation, the go.mod files for
each module now include a separate require block that includes all of
the indirect dependencies
2022-03-25 07:20:01 -05:00
Eng Zer Jun
fccb811eb2
blockchain: Use TempDir to create temp test dirs.
The directory created by `T.TempDir` is automatically removed when the
test and all its subtests complete.

This commit also refactor several cleanup logic by using `t.Cleanup`
instead of `defer`.

Reference: https://pkg.go.dev/testing#T.TempDir
Reference: https://pkg.go.dev/testing#T.Cleanup
Signed-off-by: Eng Zer Jun <engzerjun@gmail.com>
2022-03-17 20:17:26 -05:00
David Hill
3685e5be98 build: update golangci-lint to v1.44.1 2022-02-18 12:48:40 -06:00
Dave Collins
debbf873eb
addrmgr: Prepare v2.0.0.
This updates the addrmgr module dependencies, the copyright year in the
files modified since the previous release, and serves as a base for
addrmgr/v2.0.0.

The updated direct dependencies in this commit are as follows:

- github.com/decred/dcrd/chaincfg/chainhash@v1.0.3
- github.com/decred/dcrd/wire@v1.5.0
- github.com/decred/slog@v1.2.0

The full list of updated direct dependencies since the previous
addrmgr/v1.2.0 release are the same as above.

Finally, all modules in the repository are tidied to ensure they are
updated to use the latest versions hoisted forward as a result.
2021-11-11 13:31:52 -06:00
Sef Boukenken
38c187f187 addrmgr: Decouple addrmgr from wire NetAddress.
This change removes the wire NetAddress type as a dependency of the address
manager module by introducing a new NetAddress type owned by the address
manager, in preparation for upcoming changes to the wire protocol.

- Introduce a new NetAddress type in the address manager.
- Modify KnownAddress struct to use address manager NetAddress.
- Replace DeserializeNetAddress with newNetAddressFromString.
2021-09-14 13:32:46 -05:00
Sef Boukenken
676f678ecd addrmgr: Rename network address type.
This commit renames the address manager's type
NetworkAddress to NetAddressType and also introduces
a new NetAddressReach type.
2021-09-14 13:32:46 -05:00
Sef Boukenken
eeb475305b addrmgr: Decouple IP network checks from wire.
This commit modifies the IP network checks to accept a net.IP rather
than a wire.NetAddress.
2021-09-14 13:32:46 -05:00
Sef Boukenken
9211582550 addrmgr: Remove unnecessary test cases.
This commit removes unnecessary tests cases around the test helper
addAddressByIP. Since the values passed to this method are always
valid, there is no need for the error handling around it since that
results in code that serves to test a test helper.
2021-09-14 13:32:46 -05:00
Sef Boukenken
c507ec49f4 addrmgr: Improve test coverage.
This change increases test coverage within the address manager in
addition to improving comments throughout related code.

- Add tests for method ValidatePeerNa.
- Add tests for method HostToNetAddress.
- Add additional tests for methods Connected, Attempt, and Good.
- Improve coverage around local address handling.
- Improve coverage for internal behavior between tried and new buckets.
2021-09-14 13:32:46 -05:00
Dave Collins
07d2272975
addrmgr: Remove deprecated code.
This removes the deprecated functions along with the additional code and
tests which are no longer necessary as a result of removing the
functions.

The following is a list of exported types and functions removed along
with what they were replaced by:

- DisableLog -> UseLogger(slog.Disabled)
- FetchLocalAddresses -> LocalAddresses
- IsPeerNaValid -> ValidatePeerNa
2021-09-10 07:38:35 -05:00
jholdstock
e3f7f58a68 multi: Don't use deprecated ioutil package.
As of go 1.16, the "io/ioutil" package is deprecated. All functionality
from "io/ioutil" has been moved to either the "io" or "os" packages.
2021-09-01 06:09:37 -05:00
Sef Boukenken
32a14f8d7f addrmgr: Start v2 module dev cycle.
Upcoming changes constitute breaking public API changes to the addrmgr
module, therefore, this follows the process for introducing major API
breaks which consists of:

- Bump the major version in the go.mod of the affected module if not
  already done since the last release tag
- Add a replacement to the go.mod in the main module if not already done
  since the last release tag
- Update all imports in the repo to use the new major version as
  necessary
- Make necessary modifications to allow all other modules to use the new
  version in the same commit
- Repeat the process for any other modules that require a new major as a
  result of consuming the new major(s)
2021-02-12 12:15:54 -06:00
Dave Collins
0ecab1bc63
addrmgr: Prepare v1.2.0.
This updates the addrmgr module dependencies, the copyright year in the
files modified since the previous release, and serves as a base for
addrmgr/v1.2.0.

The updated direct dependencies in this commit are as follows:

- github.com/decred/dcrd/wire@v1.4.0
- github.com/decred/slog@v1.1.0

The full list of updated direct dependencies since the previous
addrmgr/v1.1.0 release are as follows:

- github.com/decred/dcrd/wire@v1.4.0
- github.com/decred/slog@v1.1.0
2020-09-25 12:14:00 -05:00
Ryan Staudt
9971b4ab35 rpcserver: Add handler test coverage.
This adds test coverage for several of the rpcserver handler
functions.
2020-07-01 12:32:08 -05:00
David Hill
4971faff25 multi: remove whitespace 2019-11-21 18:31:30 -06:00
Donald Adu-Poku
8a2bf97211 server: improve address discovery.
This properly associates ports applicable to discovered
IPs based on the listeners specified and the network
address type of the discovered host. Inbound peers
can now corroborate valid sugmissions from outbound
peer

Submissions are now bounded, address discovery also
accounts for setups using NAT.
2019-10-27 11:44:15 -05:00
Dave Collins
f65cdab3b9
addrmgr: Prepare v1.1.0.
This updates the addrmgr module dependencies and serves as a base for
addrmgr/v1.1.0.

The updated direct dependencies in this commit are as follows:

- github.com/decred/dcrd/chaincfg/chainhash@v1.0.2
- github.com/decred/dcrd/wire@v1.3.0

The full list of updated direct dependencies since the previous
addrmgr/v1.0.2 release are as follows:

- github.com/decred/dcrd/chaincfg/chainhash@v1.0.2
- github.com/decred/dcrd/wire@v1.3.0
2019-10-15 13:15:48 -05:00
Aaron Campbell
8be96a8729 multi: Correct typos.
Correct typos found by reading code, ispell, and creative grepping.
2019-08-22 10:20:03 -05:00
Aaron Campbell
03678bb754 multi: Correct typos.
Correct typos found by reading code and creative grepping.
2019-08-16 17:37:58 -05:00
Donald Adu-Poku
b69302960f multi: add getnetworkinfo rpc. 2019-08-14 15:21:01 -05:00
Donald Adu-Poku
77a14a9ead multi: add automatic network address discovery.
This discovers the network address(es) of the daemon
through connected outbound peers. The address(es)
discovered are advertised to subsequent connecting peers.
2019-08-14 06:53:10 -05:00
David Hill
2036772446 addrmgr: drop container/list. 2019-06-18 14:44:55 -04:00
David Hill
3d2d557614 multi: deprecate DisableLog 2019-03-18 11:16:35 -05:00
David Hill
69bac3189f multi: drop init and just set default log 2019-03-18 11:16:35 -05:00
Dave Collins
0f50fd5f8c
multi: Add go 1.11 directive to all modules.
This adds the go 1.11 directive to all of the modules in order to
clearly mark they build and work with that version.  Go 1.12 modified
the tools such that tidy will automatically add the new version to
modules that do not already have a directive and that would prevent
builds on Go 1.11 through Go 1.11.3 which is not desirable.
2019-03-18 02:02:35 -05:00
Dave Collins
e052b9cbf2
multi: Remove non-root module replacements.
This modifies all of the modules, with the exception of the root module,
to remove all replacement directives from their go.mod files and update
the requirements and module sums accordingly.

While it is nice to be able to build and test directly from each module
directory and have it pull in the latest untagged changes when
developing, having all of the overrides in each module makes it
infeasible to use the module tools to help maintain the modules and thus
makes it quite difficult to ensure they are all independently accurate
for external consumers.

By maintaining all of the overrides in the root module and invoking all
builds and tests from it, the overrides will apply to ensure the latest
code is being built and tested.

This also modifies the tests script used with in CI to run all of the
tests from the root module accordingly.
2019-02-08 18:01:43 -06:00
Dave Collins
36f61d8ebd build: Tidy module sums (go mod tidy). 2018-08-16 20:03:27 -05:00
Dave Collins
9536f0c88f
release: Bump module versions and deps.
This bumps the various module versions as follows:

- github.com/decred/dcrd/addrmgr@v1.0.2
- github.com/decred/dcrd/wire@v1.1.0
- github.com/decred/dcrd/chaincfg@v1.1.1
- github.com/decred/dcrd/connmgr@v1.0.1
- github.com/decred/dcrd/dcrutil@v1.1.1
- github.com/decred/dcrd/database@v1.0.1
- github.com/decred/dcrd/hdkeychain@v1.1.0
- github.com/decred/dcrd/txscript@v1.0.1
- github.com/decred/dcrd/blockchain/stake@v1.0.1
- github.com/decred/dcrd/gcs@v1.0.1
- github.com/decred/dcrd/blockchain@v1.0.1
- github.com/decred/dcrd/mining@v1.0.1
- github.com/decred/dcrd/mempool@v1.0.1
- github.com/decred/dcrd/peer@v1.0.1
- github.com/decred/dcrd/rpcclient@v1.0.1

It also updates all of the dependencies for every module accordingly and
adds a few missing overrides for transitive dependencies.
2018-08-09 14:30:22 -05:00
Dave Collins
295179fc0d
build: Refine build module support.
This further refines the modules to add the following new modules
instead of depending on the entire dcrd module:

- github.com/decred/dcrd/dcrjson@v1.0.0
- github.com/decred/dcrd/blockchain@v1.0.0
- github.com/decred/dcrd/blockchain/stake@v1.0.0
- github.com/decred/dcrd/gcs@v1.0.0
- github.com/decred/dcrd/mining@v1.0.0
- github.com/decred/dcrd/mempool@v1.0.0
- github.com/decred/dcrd/peer@v1.0.0
- github.com/decred/dcrd/rpcclient@v1.0.0

Also, it ensures modules that rely on other modules within the repo are
provided replacements to the latest repo code to ensure builds against
master and continuous integration use the latest code.

- github.com/decred/dcrd/addrmgr
- github.com/decred/dcrd/blockchain
- github.com/decred/dcrd/blockchain/stake
- github.com/decred/dcrd/chaincfg
- github.com/decred/dcrd/connmgr
- github.com/decred/dcrd/database
- github.com/decred/dcrd/dcrec/secp256k1
- github.com/decred/dcrd/dcrjson
- github.com/decred/dcrd/dcrutil
- github.com/decred/dcrd/gcs
- github.com/decred/dcrd/hdkeychain
- github.com/decred/dcrd/mempool
- github.com/decred/dcrd/mining
- github.com/decred/dcrd/peer
- github.com/decred/dcrd/rpcclient
- github.com/decred/dcrd/txscript
- github.com/decred/dcrd/wire
2018-08-05 20:45:45 -05:00
Dave Collins
46fe0ede74
addrmgr: Update go build module support.
This updates the addrmgr build module for the changes in the upcoming
go1.11 release and to depend on the latest chainhash and wire module
versions.
2018-07-20 18:12:01 -05:00
David Hill
4bbb9bc414 addrmgr: skip never-successful addresses
A node that has never been successfully connected should not be
announced.  Also, change maxFailures from 10 to a more conservative 5.
2018-06-26 19:13:31 -05:00
Dave Collins
5296fcf229
addrmgr: Expose method to update services.
This exposes a new method named SetServices to the address manager which
can be used to update the services for a known address.  This will be
useful to keep known services up to date.
2018-06-04 18:40:44 -05:00
Dave Collins
b730f985ca
addrmgr: Fix race in save peers.
This modifies the savePeers function in the addrmgr package to lock the
mutex before checking if saving is needed because the flag is accessed
from multiple goroutines.
2018-06-04 12:08:18 -05:00
Dave Collins
d5016f289f
addrmrg: Refine vgo deps.
Now that wire has been defined, update the addrmgr module to only depend
on it instead of the entire dcrd module.  Also, since there is no longer
a dep on the entire dcrd module to pick it up transitively, add the slog
dep as well.
2018-05-25 17:34:07 -05:00
Dave Collins
45e313e6d2
multi: Define vgo modules.
This adds module support for the versioned go toolchain.  In particular,
the following packages are defined as modules:

* addrmgr
* blockchain
* certgen
* chaincfg
* connmgr
* database
* dcrjson
* dcrutil
* gcs
* hdkeychain
* mempool
* mining
* peer
* rpcclient
* txscript
* wire

It does not update the travis build environment or README since it is
experimental at this point.
2018-05-25 15:38:16 -05:00
Dave Collins
678ff1efdd
multi: Replace btclog with slog.
This modifies all packages within the repository to the use the Decred
fork of btclog which has been renamed to slog and updates the dependency
files accordingly.
2018-05-23 14:22:10 -05:00
Markus Richter
dfee810f04 addrmgr: Test timestamp update during AddAddress()
Test for codepath that adds the same address twice and is supposed to
update the timestamp.
2018-05-02 20:47:26 -05:00
Markus Richter
5c2768047d addrmgr: Simplify package API.
Hide functions which are only used internally.
2018-05-02 20:35:40 -05:00
Markus Richter
73b4bd21b0 addrmgr: Skip low quality addresses for getaddr.
The AddressCache() should not propagate addresses of known low quality
to its peers.

Inspired by the Bitcoin Core implementation.
2018-05-01 12:49:25 -05:00
Markus Richter
8d12e29df5 addrmgr: Simplify tests for KnownAddress.
- Remove internal_test.go bridge and test internally instead.
- Used cached result of time.Now() everywhere.
2018-05-01 12:42:07 -05:00
Markus Richter
95557ac772 addrmgr: Improve isBad() performance.
Caching the result of time.Now() increases performance by around 50%
in the happy case (measured for last return statement).
2018-03-06 21:50:18 -06:00
Markus Richter
04c607e6fc addrmgr: Factor out common code.
Address a TODO in the code. The rest of the code is sufficiently
different to justify code duplication.
2018-03-07 01:13:50 +00:00
Markus Richter
c49a9bd261 addrmgr: Test removal of corrupt peers file.
Add unit test to ensure the removal of corrupt peers files.

Also fix some typos.
2018-03-06 00:03:56 +00:00
Markus Richter
625878976c addrmgr: Save peers file only if necessary.
Currently the peers file is (re-)written every ten minutes no matter
what.

Keep track of changes to the address manager state and write the peers
file only if something changed.
2018-03-05 14:17:42 -06:00