Commit graph

505 commits

Author SHA1 Message Date
Dave Collins
c1b327c06a Make the signal handling concurrent safe. 2013-10-03 09:29:18 -05:00
John C. Vernaleo
35c95f0a36 Handle case where no auth is sent to rpcserver. 2013-10-03 08:12:18 -04:00
Dave Collins
fd0679acdd Update notification for recent btcchain API change. 2013-10-02 21:21:52 -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
Dave Collins
f1e2de4f0c Go fmt. 2013-10-02 19:44:07 -05:00
Dave Collins
52701d826d Add directionality back to remove peer log too. 2013-10-02 19:43:38 -05:00
Owain G. Ainsworth
13a8a8e7e3 use directionString() instead of handrollong. 2013-10-03 01:39:31 +01:00
Owain G. Ainsworth
2dcd003722 Print if a peer is inbound or outbound.
This got lost in the peer logging rework. Pointed out by davec@.
2013-10-03 01:21:30 +01:00
Owain G. Ainsworth
eb667fdf83 Remove races on chain.
Chain is not concurrency safe, so we move the chainNotifySink handling
into the main blockmanager goroutine. Due to a possible deadlock if the
buffer is filled this still has to be a single channel that isn't linked
to the other ones. There is a possible starvation issue where the main
msgChan gets selected more often than the  notification sink, but until
chain is concurrency safe this is rather unavoidable.
2013-10-03 00:50:36 +01: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
David Hill
0cf8601169 add tests for RFC*, Local, Valid, and Routable. 2013-10-02 17:34:25 -04: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
Dave Collins
ad12d10503 Remove unused wakeup timer in peerHandler. 2013-10-02 13:52:44 -05: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
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
7eb1a5ce4e Disconnect misbehaving peers who send unsolicited blocks. 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
65725189db Keep track of currently requested blocks per peer.
Use this information so that we do not request a block per peer we got
an inv for it, makes multi peer much quieter and rather more bandwidth
efficient.

In order to remove a number of possible races we combine blockhandling
an synchandler and use one channel for all messages. This ensures that
all messages from a single peer will be recieved in order.  It also
removes the need for a lot of locking between the peer removal code and
the block/inv handlers.
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
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
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
Owain G. Ainsworth
989e7a9c48 Make error logging in peer.go unique.
Helps tracking down errors.
2013-10-02 14:35:58 +01:00
John C. Vernaleo
73f08e72a2 Add basic http auth to rpc server. 2013-10-01 17:10:21 -04:00
Dave Collins
ea256aeb5a Update a few comments. 2013-09-29 15:26:25 -05:00
Dave Collins
9880cf4646 Improve chain notification handling.
Previously a new goroutine was launched for each notification in order to
avoid blocking chain from continuing while the notification is being
processed.  This approach had a couple of issues.

First, since goroutines are not guaranteed to execute in any given order,
the notifications were no longer handled in the same order as they were
sent.  For the current code, this is not a problem, but upcoming code that
handles a transaction memory pool, the order needs to be correct.

Second, goroutines are relatively cheap, but it's still quite a bit of
overhead to launch 3-4 goroutines per block.

This commit modifies the handling code to have a single sink executing in
a separate goroutine.  The main handler then adds the notifications to a
queue which is processed by the sink.  This approach retains the
non-blocking behavior of the previous approach, but also keeps the order
correct and, as an additional benefit, is also more efficient.
2013-09-28 22:13:22 -05:00
Dave Collins
f1cd96ceb5 Update a few comments. 2013-09-26 21:06:01 -05:00
Owain G. Ainsworth
b97db056c1 Move the inventory handling from peer into blockmanager.
This removes a horrible case of reach-around from per into the guts of
the blockmaanger to frob the chain. Soon, when we try to deduplicate the
fetching of blocks from multiple peers this will need decisions made in
a central point.

Discussed at length with davec.
2013-09-27 01:51:05 +01:00
Todd T. Fries
790ba87979 reset retrycount upon successful connection 2013-09-26 16:52:05 -05:00
Todd T. Fries
1e77c8e554 update with knits from davec and an additional one from me 2013-09-26 16:45:10 -05:00
Todd T. Fries
568c0044a0 introduce a backoff behavior for peers that are not permitting connections
with help from davec

o implement peer { retrycount int64 ..
o count connect failures per peer
o calculate backoff as 10s * retrycount / 2
2013-09-26 16:26:31 -05:00
Dave Collins
a69647b94d Handle notifications from chain in own goroutine.
This change is in response to the recent change in btcchain such that
notifications are no longer sent in their own goroutine.
2013-09-21 09:57:47 -05:00
Dave Collins
9c8cd4dee1 Update sample config for recent go-flags fix.
The configuration file can now contain multiple entries for the
configuration options which allow more than one to be specified (addpeer,
connect).
2013-09-19 09:17:15 -05:00
Dave Collins
346ff6f9e2 Filter duplicate getblocks requests.
This commit adds detection and filtering for back-to-back duplicate
getblocks requests.  This is needed because the trigger for requesting
more blocks is receiving an orphan.  When the peer is further behind than
the number of blocks advertised via a single inventory message, the same
orphan block will be sent multiple times.  When the peer receives the
final inventory message, it too contains the orphan that was previously
sent.  This leads to a duplicate getblocks request that must be filtered
to prevent requesting the final series of blocks again.
2013-09-18 13:33:54 -05:00
Dave Collins
0195306ff7 Updated missed function call for lint rename. 2013-09-18 11:25:18 -05: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
465327c62d Expand environment variables in datadir.
This commit adds environment variable expansion and path cleaning to the
data directory.  This allows the user to specify data paths in the config
file such as datadir=~/.btcd/data and datadir=$SOMEVAR/btcd.  It also
adds usage instructions and an example to the sample btcd.conf file.
2013-09-18 00:16:57 -05:00
Dave Collins
f2190d21dd Add profile option to sample configuration file. 2013-09-17 17:28:07 -05:00
Dave Collins
eed4c4df9c Add log message for profile server listen port. 2013-09-17 17:15:49 -05:00
Dave Collins
fc0cd75046 gofmt. 2013-09-17 17:04:40 -05:00
Marco Peereboom
68f30c7367 add missing empty string test, pointed out by davec 2013-09-17 17:46:03 -04:00
Marco Peereboom
ada49f1413 Add a flag to enable live profiling.
The profile information can be seen with a browser on e.g.
http://localhost:6060/debug/pprof/
Alternatively, one can use the pprof tool as described at
http://golang.org/pkg/net/http/pprof/

ok davec
2013-09-17 17:40:27 -04: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