Commit graph

29 commits

Author SHA1 Message Date
Dave Collins
bc6ff038e3 Fix a race in the amgr found by the race detector. 2014-02-05 12:37:35 -06:00
Dave Collins
d33e9b4165 Unexport and comment btcDial and btcLookup func.
These functions are at the package level and only apply within btcd, so
unexport them to be consistent.
2014-01-10 01:31:20 -06:00
Owain G. Ainsworth
dd7c910e86 Enable use of a different proxy for .onion addresses.
This implements --onion (and --onionuser/--onionpass) that enable a
different proxy to be used to connect to .onion addresses. If no main
proxy is supplied then no proxy will be used for non-onion addresses.

Additionally we add --noonion that blocks connection attempts to .onion
addresses entirely (and avoids using tor for proxy dns lookups).

the --tor option has been supersceded and thus removed.

Closes #47
2014-01-07 19:18:09 +00:00
Dave Collins
aeec39c1ff Add 2014 to copyright dates. 2014-01-01 10:16:15 -06:00
Owain G. Ainsworth
1145fb57ed handle .onion addresses in deserialising addrmanager.
Use the generic function that already handles this.
2013-12-10 19:39:48 +00:00
Owain G. Ainsworth
f93203b91e Initial basic support for selection of external ip address.
This implements only the bare bones of external ip address selection
using very similar algorithms and selection methods to bitcoind. Every
address we bind to, and if we bind to the wildcard, every listening
address is recorded, and one for the appropriate address type of the
peer is selected.

Support for fetching addresses via upnp, external services, or via the
command line are not yet implemented.

Closes #35
2013-12-10 19:39:47 +00:00
Owain G. Ainsworth
1e836d26f4 Handle tor and dns-name addresses.
Perform the requisite processing on .onion addresses to turn them into the tor
reserved ipv6 region (the same as bitcoind and onioncat). Furthermore,
when printing an ip address, reverse the conversion so we print it
nicely.  base32 as standard is uppercase, but tor and bitcoind seem to
use lowercase so we  first must for we force .onion addrs to uppercase
(and to lowercase on the reverse).

As a side effect we now should handle dns names on the command line (via tor if
required) and add them to the addressmanger as necessary.
2013-12-10 19:39:46 +00:00
Owain G. Ainsworth
d2dd40aae2 fix tor range. add :: to make sure it is parsed as v6. 2013-12-10 19:39:46 +00:00
Owain G. Ainsworth
f843c141ae in Valid() ensure that na.IP is set. Found by drahn. 2013-11-22 18:48:36 +00:00
Dave Collins
eb8688df79 Convert btcd to use new btclog package.
Also, make every subsystem within btcd use its own logger instance so each
subsystem can have its own level specified independent of the others.

This is work towards #48.
2013-11-21 17:41:21 -06:00
Owain G. Ainsworth
5d3fcc660e Handle tor addresses in addrmanager.
Both GroupKey and Tor() needed amending for tor addresses, filling in some
TODOs.

Closes #36.
Closes #37
2013-11-19 14:51:41 +00:00
Owain G. Ainsworth
3afdc43e69 Fix reference counting when expiring peers. 2013-10-14 22:27:21 +01:00
Dave Collins
44aafcf742 Return on file error in address manager save.
This commit modifies the address manager save code to exit when there is
an error creating the file used to store addresses.  Previously the error
was only logged leaving the invalid file handle to be used later.
2013-10-12 11:49:10 -05:00
Dave Collins
9772626dd8 Improve logging.
This commit is a first pass at improving the logging.  It changes a number
of things to improve the readability of the output.  The biggest addition
is message summaries for each message type when using the debug logging
level.

There is sitll more to do here such as allowing the level of each
subsystem to be independently specified, syslog support, and allowing the
logging level to be changed run-time.
2013-10-10 17:22:19 -05:00
Dave Collins
a275687f3f Make peer load message consistent and fix spello. 2013-10-10 10:06:58 -05:00
Dave Collins
f983b0846e Add missing format specific in addrmanager.
Found by go vet.
2013-10-04 00:37:15 -05:00
Owain G. Ainsworth
8974e789f7 Convert the rest of the subsystems to use atomics for shutdown vars. 2013-10-03 00:33:42 +01:00
David Hill
6f9aada482 RFC4193 is fc00::/7, not fc00::/15. Also fix two typos in RFC4843()
and RFC6052
2013-10-02 17:31:44 -04:00
Owain G. Ainsworth
71ea6700a2 Hold amgr lock in {load,save}Peers.
We're traversing internal datastructures here.
2013-10-02 20:37:42 +01:00
Owain G. Ainsworth
70f15f434f Return nil in GetAddress if no addresses present.
Honestly thought we already did this, but turns out no.
2013-10-02 20:19:47 +01:00
Owain G. Ainsworth
7d24f31fbd lack of a peers.json isn't an error, don't log in that case. 2013-10-02 15:25:43 +01:00
Owain G. Ainsworth
850420055f Bucketizing for addrmanager
Implement the bucketing by source group and group using essentially the
same algorithm as the address maanger in bitcoind.

Fix up the saving of peer.json to do so in a json format that keeps bucket
metadata.

If we fail to load the some of the data we asssume that we have
incomplete information, so we nuke the existing file and reinitialise so
we have a clean slate.
2013-10-02 14:35:59 +01:00
Dave Collins
94c795dec4 Add AMGR prefix to log messages for consistency. 2013-09-18 11:21:19 -05:00
Dave Collins
a5cc716940 Address some minor things reported by golint. 2013-09-18 00:36:40 -05:00
Dave Collins
3ca1e82f66 Make go vet happy. 2013-09-18 00:27:47 -05:00
Dave Collins
92a8605b24 Continue work on addrmgr and multi-peer.
- Remove leftover debug log prints
- Increment waitgroup outside of goroutine
- Various comment and log message consistency
- Combine peer setup and newPeer -> newInboundPeer
- Save and load peers.json to/from cfg.DataDir
- Only claim addrmgr needs more addresses when it has less than 1000
- Add warning if unkown peer on orphan block.
2013-09-17 10:48:47 -05:00
Owain G. Ainsworth
6c05e9d475 Flesh out addrmanger with some basic functionality.
Use it to add multiple peer support. We try and keep 8 outbound peers
active at all times.

This address manager is not as complete as the one in bitcoind yet, but
additional functionality is being worked on.

We currently handle (in a similar manner to bitcoind):

- biasing between new and already tried addresses based on number of connected
  peers.
- rejection of non-default ports until desparate
- address selection probabilities based on last successful connection and number
  of failures.
- routability checks based on known unroutable subnets.
- only connecting to each network `group' once at any one time.

We currently lack support for:
- tor ``addresses'' (an .onion address encoded in 64 bytes of ip address)
- full state save and restore (we just save a json with the list of known
  addresses in it)
- multiple buckets for new and tried addresses selected by a hash of address and
 source.  The current algorithm functions the same as bitcoind would with only
 one bucket for new and tried (making the address cache rather smaller than it
 otherwise would be).
2013-09-15 20:25:55 -05:00
Dave Collins
33b65f943f Increment waitgroups before goroutines are started.
This commit changes the code so that all calls to .Add on waitgroups
happen before the associated goroutines are launched.   Doing this after
the goroutine could technically cause a race where the goroutine started
and finished before the main goroutine has a chance to increment the
counter.  In our particular case none of the goroutines exit quickly
enough for this to be an issue, but nevertheless the correct way should be
used.
2013-09-12 17:24:37 -05:00
Dave Collins
8574846e87 Move btcd to root directory.
This allows easier go get paths.
2013-08-07 12:47:51 -05:00
Renamed from btcd/addrmanager.go (Browse further)