Commit Graph

44 Commits

Author SHA1 Message Date
Dave Collins
4e878a85fd config: New option --blocksonly
Upstream commit d1e493f4ee.

Since Decred has supported the ability to disable transaction relaying
since the first version, this removes the additional checks which dealt
with only disconnecting peers that were at a high enough protocol
version to always disconnect when peers are announcing transactions when
they were instructed not to.
2016-05-30 14:31:13 -05:00
Dave Collins
208eaba692 peer: Implement sendheaders support (BIP0130).
Upstream commit 8a58f8cf3a.

Modified the supported protocol version passed to peer to
wire.BIP0111Version which is the version in Decred just before the new
protocol version for wire.SendHeadersVersion.
2016-05-30 14:05:02 -05:00
Dave Collins
6febb7b244 peer: declare QueueMessage()'s doneChan as send only.
Contains the following upstream commits:
- e08038115b
  - This commit has already been cherry-picked so it is a NOOP
- 391d5e4a01
  - This commit has been replaced by a new commit that was cherry-picked
    so it has been converted to a NOOP
- c1861bc8fa
2016-05-30 13:41:36 -05:00
Dave Collins
d3ef588608 multi: Update with result of gofmt -s.
Contains the following upstream commits:
- d4852101d4
  - This commit has already been independently applied so it is mostly a
    NOOP
- f389742b39

In addition, gofmt -s has been run again to simplify the new additions
to Decred and and all simplifications are included in the merge commit.
2016-05-30 12:40:44 -05:00
Dave Collins
2030b4d057 multi: Fix several misspellings in the comments.
Contains the following upstream commits:
- ef9c50be57
- eb882f39f8

In addition to merging the fixes in the commits, this also fixes a few
more misspellings that were introduced in the new Decred code.
2016-05-30 12:24:21 -05:00
Dave Collins
0d67c15bee peer: Consolidate several public methods.
Upstream commit 73d353247c.
2016-05-27 23:10:40 -05:00
Dave Collins
e190b7fa44 Use atomic operations instead of mutexes.
Upstream commit 383ed041ec.
2016-05-27 21:24:47 -05:00
Dave Collins
c9c32d56ef peer: Simplify PushAddrMsg method loop.
Upstream commit e03fa30e89.
2016-05-27 00:55:52 -05:00
Dave Collins
08f7b6b270 peer: Rename variable for consistency.
Contains the following upstream commits:
- 2f6aeacfab
  - This commit has already been independently applied so it is mostly a
    NOOP except for a comment update
- 542844832e
  - This commit has already been cherry picked so it is mostly a NOOP
- 4d40a2110a
2016-05-26 16:57:32 -05:00
Dave Collins
f0389a3039 peer: Add DisableRelayTx to config.
Upstream commit 2a7f41cddb.
2016-05-26 16:54:13 -05:00
Dave Collins
50dd5db0f5 peer: Unexport the mru inventory map.
Upstream commit 1217e00d39.
2016-05-25 15:16:16 -05:00
Alex Yocom-Piatt
708b4007ac peer: fix panic due to err in handleVersionMsg (#222)
In case of an error during protocol negotiation in handleVersionMsg,
immediately break out and prevent further processing of OnVersion
listener which generally depends upon peer attributes like NA to be set
during the negotiation. Fixes #579.
2016-05-25 14:42:22 -05:00
Dave Collins
e955b1fdb1 peer: Combine stats struct into peer struct.
Contains the following upstream commits:
- 0c3cf63773
- ee8601ecac
  - Reverted because btcd releases do not apply to dcrd
- 23df5ed2fc
  - Reverted because btcd releases do not apply to dcrd
- 6c00d07910
2016-05-25 12:18:18 -05:00
Dave Collins
4bffbb10db mempool/peer: Sync upstream comment updates.
Upstream commits
- 5016675d40
- d765c73a41
2016-05-24 13:30:02 -05:00
Dario Nieuwenhuis
a70c67a551 peer: remove getaddr msg from stall detection.
The getaddr msg is usually replied to with an addr msg, but if
the other peer does not have any addresses to share it will not
reply at all (instead of replying with an addr msg with 0 addresses).
Therefore, the getaddr msg is not guaranteed a reply, so this commit
removes it from stall detection to avoid incorrectly kicking
such peers.
2016-05-24 11:29:24 -05:00
Dave Collins
c052ff9c73 peer: Fix failing test case due to wrong TimeOffset
Upstream commit 21d11e2809
2016-05-24 10:41:38 -05:00
Dave Collins
415ad8f03b peer: Sync upstream fixes and improvements.
Upstream commits:
- 4a397d51d4
- 5c50db5357
2016-05-20 16:16:50 -05:00
Dave Collins
40d778dd2d docs: Make various README.md files consistent.
Upstream commit 3942a116e4

This merge also includes a few Decred specific modifications and
corrects some old btcjson references that should have been updated to
dcrjson.
2016-05-20 16:00:12 -05:00
Dave Collins
756eff2fee peer: Refactor peer code into its own package.
Contains the following upstream commits:

- 00bddf7540
- 250228c32f
- f1bd2f8d6e
- cbbe3a8bbe
- aa03d68e1e

In addition to the normal required changes for syncing, the following
changes have been made in order to facilitate integration of the new
package into Decred:

- Removed check in PushRejectMsg against protocol version since all
  peers since the initial version support it
- Fixed leaked timer in `syncMiningStateAfterSync` function
- Add the Decred-specific OnGetMiningState and OnMiningState handlers to
  the new peer package
- Add handler for the new mining state messages to the 'serverPeer' type
  and register them
- Use the new constant for wire.InitialProtocolVersion in the reject
  message instead of hard coded number
- Remove logic specific to the regression network since Decred does not
  have it
2016-05-20 13:58:23 -05:00
David Hill
d1e493f4ee config: New option --blocksonly (#553)
The --blocksonly configuration option disables accepting transactions
from remote peers.  It will still accept, relay, and rebroadcast
valid transactions sent via RPC or websockets.
2016-04-07 18:16:46 -05:00
David Hill
8a58f8cf3a peer: Implement sendheaders support (BIP0130).
This modifies the peer package to add support for the sendheaders
protocol message introduced by BIP0030.

NOTE: This does not add support to btcd itself. That requires the server
and sync code to make use of the new functionality exposed by these
changes.  As a result, btcd will still be using protocol version 70011.
2016-04-06 16:56:48 -05:00
David Hill
c1861bc8fa peer: declare QueueMessage()'s doneChan as send only.
This ensures the channel passed to QueueMessage is writable and that
QueueMessage will not read from the channel (write-only).

This change is merely a safety change.  If a user of the API passes
a read-only channel to QueueMessage, it will now be caught at compile
time instead of panicking during runtime.

Also update internal functions.
2016-04-06 13:50:27 -05:00
Dave Collins
f389742b39 multi: Update with result of gofmt -s.
This commit updates the code to make use of the most recent simplified
output from gofmt.
2016-02-25 13:02:54 -06:00
Dave Collins
eb882f39f8 multi: Fix several misspellings in the comments.
This commit corrects several typos in the comments found by misspell.
2016-02-25 11:17:12 -06:00
Jonathan Gillham
73d353247c peer: Consolidate Connect, Disconnect, Start, Shutdown public methods.
This commit does not change functionality. It makes the creation of inbound and outbound peers more homogeneous. As a result the Start method of peer was removed as it was found not to be necessary. This is the first of several pull requests/commits designed to make the peer public API and internals less complex.
2016-02-06 11:11:15 +00:00
David Hill
383ed041ec Use atomic operations instead of mutexes. 2016-02-04 15:20:04 -05:00
Jonathan Gillham
e03fa30e89 peer: Simplify PushAddrMsg method loop.
This implementation ensures that all addresses have an equal chance of
being included in the addr message. It also moves the pseudorandom number
generator seeding to package level so that it can be overridden for
testing if required.
2016-01-24 10:52:59 +00:00
Dario Nieuwenhuis
89af747603 peer: remove getaddr msg from stall detection.
The getaddr msg is usually replied to with an addr msg, but if
the other peer does not have any addresses to share it will not
reply at all (instead of replying with an addr msg with 0 addresses).
Therefore, the getaddr msg is not guaranteed a reply, so this commit
removes it from stall detection to avoid incorrectly kicking
such peers.
2015-12-27 19:50:36 +01:00
Jonathan Gillham
4d40a2110a peer: Rename variable for consistency. 2015-12-14 21:52:06 -08:00
Javed Khan
542844832e peer: fix panic due to err in handleVersionMsg
In case of an error during protocol negotiation in handleVersionMsg,
immediately break out and prevent further processing of OnVersion
listener which generally depends upon peer attributes like NA to be set
during the negotiation. Fixes #579.
2015-12-10 01:16:03 +05:30
David Hill
2a7f41cddb peer: Add DisableRelayTx to config.
DisableRelayTx sets the DisableRelayTx value in the version
message which informs the remote peer on whether to send
inv messages for transactions.
2015-12-03 10:29:06 -05:00
Dave Collins
1217e00d39 peer: Unexport the mru inventory map.
This unexports the mruInventoryMap type since it is only needed within
the peer package.
2015-11-24 09:41:35 -06:00
Dave Collins
6c00d07910 peer: Combine stats struct into peer struct.
This defines the peer stat fields directly in the Peer struct instead of
defining them in a separate struct and embedding them.  It is slightly
more efficient this way and there is really no reason to have them
defined separately anyways since they are not passed around or otherwise
used independently.
2015-11-23 09:25:53 -06:00
Javed Khan
0c3cf63773 Use new connections for peers in TestOutboundPeer
Fixes a rare hang during peer tests due to the same connection being
used for different outbound peers. Also fixed passing a chan to
QueueMessage(..) which was not being waited on, so was not being used.
2015-11-16 23:01:51 +05:30
David Hill
5016675d40 Move comment to where it belongs. 2015-11-10 13:20:29 -05:00
Javed Khan
21d11e2809 Fix failing test case because of wrong TimeOffset 2015-11-10 05:15:55 +05:30
Dave Collins
5c50db5357 peer: Don't stall on pongs. 2015-10-26 08:59:01 -05:00
Dave Collins
4a397d51d4 peer: Don't log write errs due to disconnect.
This commit modifies the peer logging so that it will not log an error
when it's due to the remote peer disconnecting or the peer being
forcibly disconnected or shutdown.
2015-10-23 14:55:43 -05:00
Dave Collins
3942a116e4 docs: Make various README.md files consistent.
First, it removes the documentation section from all the README.md files
and instead puts a web-based godoc badge and link at the top with the
other badges.  This is being done since the local godoc tool no longer
ships with Go by default, so the instructions no longer work without
first installing godoc. Due to this, pretty much everyone uses the
web-based godoc these days anyways.  Anyone who has manually installed
godoc won't need instructions.

Second, it makes sure the ISC license badge is at the top with the other
badges and removes the textual reference in the overview section.

Finally, it's modifies the Installation section to Installation and
Updating and adds a '-u' to the 'go get' command since it works for both
and thus is simpler.
2015-10-23 14:51:36 -05:00
Dave Collins
aa03d68e1e peer: Correct a few typos in documentation. 2015-10-23 14:47:18 -05:00
Dave Collins
cbbe3a8bbe peer: Implement stall detection.
This commit implements stall detection logic at the peer level to detect
and disconnect peers that are either not following the protocol in
regards to expected response messages or have otherwise stalled.  This
is accomplished by setting deadlines for each message type which expects
a response and periodically checking them while properly taking into
account processing time.

There are an increasing number of nodes on the network which claim to be
full nodes, but don't actually properly implement the entire p2p
protocol even though they implement it enough to cause properly
implemented nodes to make data requests to which they never respond.

Since btcd currently only syncs new blocks via single sync peer and,
prior to this commit only had very basic stall detection, this could
lead to a situation where the block download became stalled indefinitely
due to one of these misbehaving peers.  This commit fixes that issue
since the stalled peer will now be detected and disconnected which leads
to a new sync peer being selected.

This logic will also fit nicely with the future multi-peer sync model
which is on the roadmap and for which infrastructure work is underway.

Fixes #486 and fixes #229.
2015-10-23 10:27:00 -05:00
Dave Collins
f1bd2f8d6e peer: Ping on interval instead of delayed timer.
This commit modifies the ping logic in the peer to ping on an interval
regardless of what other messages are being sent versus the previous
method of delaying the ping each time a message that is expected to
receive data is sent.

This helps improve the ping statistics and simplifies its logic.
2015-10-23 10:22:22 -05:00
Dave Collins
250228c32f peer: Improve documentation.
This fleshes out the doc.go documentation which is shown on godoc, the
README.md shown on github, and improves a couple of comments for the
fields in the Config struct.
2015-10-23 01:17:12 -05:00
Javed Khan
00bddf7540 peer: Refactor peer code into its own package.
This commit introduces package peer which contains peer related features
refactored from peer.go.

The following is an overview of the features the package provides:

- Provides a basic concurrent safe bitcoin peer for handling bitcoin
  communications via the peer-to-peer protocol
- Full duplex reading and writing of bitcoin protocol messages
- Automatic handling of the initial handshake process including protocol
  version negotiation
- Automatic periodic keep-alive pinging and pong responses
- Asynchronous message queueing of outbound messages with optional
  channel for notification when the message is actually sent
- Inventory message batching and send trickling with known inventory
  detection and avoidance
- Ability to wait for shutdown/disconnect
- Flexible peer configuration
  - Caller is responsible for creating outgoing connections and listening
    for incoming connections so they have flexibility to establish
    connections as they see fit (proxies, etc.)
  - User agent name and version
  - Bitcoin network
  - Service support signalling (full nodes, bloom filters, etc.)
  - Maximum supported protocol version
  - Ability to register callbacks for handling bitcoin protocol messages
- Proper handling of bloom filter related commands when the caller does
  not specify the related flag to signal support
  - Disconnects the peer when the protocol version is high enough
  - Does not invoke the related callbacks for older protocol versions
- Snapshottable peer statistics such as the total number of bytes read
  and written, the remote address, user agent, and negotiated protocol
  version
- Helper functions for pushing addresses, getblocks, getheaders, and
  reject messages
  - These could all be sent manually via the standard message output
    function, but the helpers provide additional nice functionality such
    as duplicate filtering and address randomization
- Full documentation with example usage
- Test coverage

In addition to the addition of the new package, btcd has been refactored
to make use of the new package by extending the basic peer it provides to
work with the blockmanager and server to act as a full node.  The
following is a broad overview of the changes to integrate the package:

- The server is responsible for all connection management including
  persistent peers and banning
- Callbacks for all messages that are required to implement a full node
  are registered
- Logic necessary to serve data and behave as a full node is now in the
  callback registered with the peer

Finally, the following peer-related things have been improved as a part
of this refactor:

- Don't log or send reject message due to peer disconnects
- Remove trace logs that aren't particularly helpful
- Finish an old TODO to switch the queue WaitGroup over to a channel
- Improve various comments and fix some code consistency cases
- Improve a few logging bits
- Implement a most-recently-used nonce tracking for detecting self
  connections and generate a unique nonce for each peer
2015-10-23 06:17:29 +05:30