Commit graph

57 commits

Author SHA1 Message Date
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
Dave Collins ca14702e5d Correct getpeerinfo JSON marshalling for omitempty.
The fields of the PeerInfo should not have been marked omit as the only
ones that should be omitted to for compatibility are the SyncNode and
BanScore fields.
2013-12-27 19:25:20 -06:00
Dave Collins 3faa256f75 Correct the getpeerinfo RPC services field.
In order to match the Satohsi client, the return is supposed to be an
8-digit string representation of the services instead of the actual
services numeric value.
2013-12-27 17:35:51 -06:00
Owain G. Ainsworth 8310661c29 Parse out ports from externalip strings if present.
If not, continue to use the default. Should fix a problem reported by
Justus Ranvier on github.

Closes #38 (again)
2013-12-16 20:48:23 +00:00
Owain G. Ainsworth 2a554c43b0 Shutdown server fully on ctrl-c
since we don't wait for peers, this largely just waits for the server procs
themselves to die. Unless the entire server is wedged (which is what kill -9 is
for) this should always shut down fairly swiftly.

This should mean we sync addrmanager and disestablish upnp correctly on
interrupt.

Discussed with davec.
2013-12-10 22:40:17 +00:00
Owain G. Ainsworth f8e88df237 Add basic support for UPnP.
This code borrows and fixes up a chunk of code to handle upnp from
Taipei-Torrent (https://github.com/jackpal/Taipei-Torrent), under
current versions of go none of the xml parsing was working correctly.
This fixes that and also refactors the SOAP code to be a little nicer by
stripping off the soap containers. It is still rather rough but seems to
correctly redirect ports and advertise the correct address.

Upnp is not run by default. --upnp will enable it, but it will still not
run if we are not listening or if --externalip is in use.

Closes #51
2013-12-10 22:39:54 +00:00
Owain G. Ainsworth 8968f7dd74 Add support for --externalip.
Closes #38
2013-12-10 19:39:47 +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
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 5da5dfe1c4 Add --rpclisten that behaves frighteningly similar to --listen.
Except it works for the rpcserver instead of the main server.

Closes #34
2013-11-19 14:48:58 +00:00
Dave Collins c3a3fbcabf Don't bother parsing listeners if disabled. 2013-11-13 21:16:49 -06:00
Dave Collins 3902a71bee Minor cleanup. 2013-11-13 21:12:41 -06:00
Dave Collins ac375df71f Use the passed addresses in parseListeners.
Also, check the return error on parseListeners to catch invalid IP
addresses.
2013-11-13 21:02:34 -06:00
Dave Collins 7b86bec825 Comment new parseLiteners function. 2013-11-13 19:43:36 -06:00
Owain G. Ainsworth 6116a6cb02 Support --listen.
This allows the provision of address/port pairs to be listened on instead
of just providing the port. e.g.:
btcd --listen 1.2.3.4:4321 --listen 127.0.0.01 --listen [::1]:5432

When --proxy and --connect are used, we disable listening *unless* any --listen
arguments have been provided, when we will listen on those addresses as
requested.

Initial code by davec, integration by myself.

Closes #33

allow listens to fail, but warn. error if all failed

fmt
2013-11-14 01:15:47 +00:00
Josh Rickmar b97a2145d8 Try to match bitcoind sendrawtransaction RPC errors. 2013-11-07 10:34:55 -05:00
Owain G. Ainsworth c1a1e6b6b2 keep track of connected groups as we gain and lose outbound peers.
Instead of recalculating every time we go to look for more peers. Should
save a few cycles.
2013-11-06 19:08:06 +00:00
Owain G. Ainsworth 6949a4f940 Have a list per class of peer instead of just one.
persistentpeers and outbound(nonpersistent) peers get their own lists,
so iterating over them can be much simpler (and quicker when you have
125 peer of which 8 are outbound).
2013-11-06 19:08:06 +00:00
Owain G. Ainsworth 4d80750afe Move all local data to peerhandler into a peerState structure
Pass peerstate around instead of indivdual bits.
2013-11-06 18:52:58 +00:00
John C. Vernaleo b72f0c6474 Make peerinfo output match bitcoind a bit better.
Add long option for username in btcctl.
2013-11-04 16:25:13 -05:00
Owain G. Ainsworth 231efa35f5 Provide useragent in getpeerinfo now we know it. 2013-10-29 23:00:23 +00:00
Owain G. Ainsworth 59e2b204a3 Add doc comments. 2013-10-29 20:30:16 +00:00
Owain G. Ainsworth da2901a4fd Add support for the addnode command
Currently this acts on the list of all peers, and not just the list of
permanent peers. this will be changed shortly.
2013-10-29 20:30:07 +00:00
Owain G. Ainsworth b1f14732b1 Implement getpeerinfo and getconnectedcount
We have a channel for queries and commands in server, where we pass in
args and the channel to reply from, let rpcserver use these interfaces
to provide the requistie information.

So far not all of the informaation is 100% correct, the syncpeer
information needs to be fetched from blockmanager, the subversion isn't
recorded and the number of bytes sent and recieved needs to be obtained
from btcwire. The rest should be correct.
2013-10-29 17:05:12 +00:00
Owain G. Ainsworth 5a9cc91e62 Add an idle timer for peers.
If we don't hear from a peer for 5 minutes, we disconnect them. To keep
traffic flowing we send a ping every 2 minutes if we have not send any
other message that should get a reply.
2013-10-17 17:06:47 +01: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 1d2c48555b Misc cleanup. 2013-10-07 19:24:44 -05:00
Dave Collins 849c830cf8 Move DNS seed consts to same file that uses them.
Also, use multi constant define for the result.
2013-10-07 17:58:16 -05:00
Dave Collins c03f2b757b Move initial DNS seeding to own func. 2013-10-07 17:38:45 -05:00
Dave Collins 995d8da491 Handle another removal case missed in prev commit.
Also, the loops which only remove a single element and break or return
don't need the extra logic for iteration since they don't continue
iteration after removal.
2013-10-07 10:10:22 -05:00
Dave Collins 219a6131f4 Correct all list/container loops that remove items.
It is not safe to remove an item from a container/list while iterating the
list without first saving the next pointer since removing the item nils
the internal list element's next pointer.
2013-10-07 09:06:29 -05:00
Dave Collins 47c07ee5e1 Update a few comments. 2013-10-04 00:35:26 -05:00
Dave Collins 78e9b94d93 Implement transaction pool and relay.
This commit is a rather large one which implements transaction pool and
relay according to the protocol rules of the reference implementation.
It makes use of btcchain to ensure the transactions are valid for the
block chain and includes several stricter checks which determine if they
are "standard" or not before admitting them into the pool and relaying
them.

There are still a few TODOs around the more strict rules which determine
which transactions are willing to be mined, but the core checks which
are imperative (everything except the all of the "standard" checks really)
to operate as a good citizen on the bitcoin network are in place.
2013-10-03 22:31:54 -05:00
Dave Collins 29dfa22086 Introduce a Stringer on peers.
Rather than having all of the various places that print peer figure out
the direction and form the string, centralize it by implementing the
Stringer interface on the peer.
2013-10-02 20:05:10 -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
Owain G. Ainsworth f333cb4220 Remove a (largely harmless) race on p.conn
Add a Connected() member function that checks atomic variables to see if
the peer is connected.
2013-10-02 23:06:29 +01:00
Owain G. Ainsworth 5c1340be8f make logging about peers rather quieter.
Only log errors for most cases if the peer is persisent (and thus requested).
Only log by default after version exchange, and after losing a peer that had
completed version exchange. Make most other messages debug.
2013-10-02 22:50:24 +01:00
Dave Collins ad12d10503 Remove unused wakeup timer in peerHandler. 2013-10-02 13:52:44 -05:00
Owain G. Ainsworth 4455e77dde Don't create additional outbound peers if any --connect are specified. 2013-10-02 15:16:04 +01:00
Owain G. Ainsworth 98109dbadd Fix shutdown hangs.
We would occasionally hang or a while during server shudown, this is due
to an outbound peer waiting on a connection or a sleep. However, we
don't actually require to wait for the peers to finish at all. So just
let them finish.

Secondly, make peer.disconnnect and server.shutdown atomic varaibles so
that checking them from multiple goroutines isn't race, and clean up
their usage.
2013-10-02 14:36:04 +01:00
Owain G. Ainsworth 030c610211 Revert "Comment multi-peer connect while code is under dev."
This reverts commit 7609ff396a.
2013-10-02 14:36:04 +01:00
Owain G. Ainsworth ca7cb8c875 move the intiial chain cache generation into bm.
Blockmanager is otherwise the only current consumer of chain and it is
messy to do it outside of it.
2013-10-02 14:36:04 +01:00
Owain G. Ainsworth d9214030e0 Don't propagate inv messages to connecting peers.
Only queue messages for peers that have finished connecting to prevent
filling goroutines and causing deadlocks.
2013-10-02 14:35:59 +01:00
Dave Collins 0195306ff7 Updated missed function call for lint rename. 2013-09-18 11:25:18 -05:00
Dave Collins a5cc716940 Address some minor things reported by golint. 2013-09-18 00:36:40 -05:00
Dave Collins 7609ff396a Comment multi-peer connect while code is under dev. 2013-09-17 10:58:16 -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