{"action":"created","issue":{"url":"https://api.github.com/repos/btcsuite/btcd/issues/445","labels_url":"https://api.github.com/repos/btcsuite/btcd/issues/445/labels{/name}","comments_url":"https://api.github.com/repos/btcsuite/btcd/issues/445/comments","events_url":"https://api.github.com/repos/btcsuite/btcd/issues/445/events","html_url":"https://github.com/btcsuite/btcd/pull/445","id":84571828,"number":445,"title":"[peer] Refactor peer code into its own package","user":{"login":"tuxcanfly","id":132667,"avatar_url":"https://avatars.githubusercontent.com/u/132667?v=3","gravatar_id":"","url":"https://api.github.com/users/tuxcanfly","html_url":"https://github.com/tuxcanfly","followers_url":"https://api.github.com/users/tuxcanfly/followers","following_url":"https://api.github.com/users/tuxcanfly/following{/other_user}","gists_url":"https://api.github.com/users/tuxcanfly/gists{/gist_id}","starred_url":"https://api.github.com/users/tuxcanfly/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/tuxcanfly/subscriptions","organizations_url":"https://api.github.com/users/tuxcanfly/orgs","repos_url":"https://api.github.com/users/tuxcanfly/repos","events_url":"https://api.github.com/users/tuxcanfly/events{/privacy}","received_events_url":"https://api.github.com/users/tuxcanfly/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":52,"created_at":"2015-06-03T13:43:54Z","updated_at":"2015-10-09T00:06:16Z","closed_at":null,"pull_request":{"url":"https://api.github.com/repos/btcsuite/btcd/pulls/445","html_url":"https://github.com/btcsuite/btcd/pull/445","diff_url":"https://github.com/btcsuite/btcd/pull/445.diff","patch_url":"https://github.com/btcsuite/btcd/pull/445.patch"},"body":"This pull request introduces package peer which contains peer related features refactored from peer.go.\r\n\r\nThe following is an overview of the features the package provides:\r\n\r\n- Provides a basic concurrent safe bitcoin peer for handling bitcoin communications via the peer-to-peer protocol\r\n- Full duplex reading and writing of bitcoin protocol messages\r\n- Automatic handling of the initial handshake process including protocol version negotiation\r\n- Automatic periodic keep-alive pinging and pong responses\r\n- Automatic block stall detection with disconnection\r\n- Asynchronous message queuing of outbound messages with optional\r\n  channel for notification when the message is actually sent\r\n- Inventory message batching and send trickling with known inventory\r\n  detection and avoidance\r\n- Ability to wait for shutdown/disconnect\r\n- Flexible peer configuration\r\n  - Caller is responsible for creating outgoing connections and listening\r\n    for incoming connections so they have flexibility to establish connections as they see fit (proxies, etc)\r\n  - User agent name and version\r\n  - Bitcoin network\r\n  - Service support signalling (full nodes, bloom filters, etc)\r\n  - Maximum supported protocol version\r\n  - Ability to register callbacks for handling bitcoin protocol messages\r\n- Snapshottable peer statistics such as the total number of bytes read and written, the remote address, user agent, and negotiated protocol version\r\n- Helper functions pushing addresses, getblocks, getheaders, and reject messages\r\n  - These could all be sent manually via the the standard message output function, but the helpers provide additional nice functionality such as duplicate filtering and address randomization\r\n- Full documentation with example usage\r\n- Test coverage\r\n\r\nIn 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\r\nfollowing is a broad overview of the changes to integrate the package:\r\n\r\n- The server is responsible for all connection management including persistent peers and banning\r\n- Callbacks for all messages that are required to implement a full node are registered\r\n- Logic necessary to serve data and behave as a full node is now in the callback registered with the peer\r\n\r\nFinally, the following peer-related things have been improved as a part of this refactor:\r\n\r\n- Don't log or send reject message due to peer disconnects\r\n- Remove trace logs that aren't particularly helpful\r\n- Finish an old TODO to switch the queue waitgroup over to a channel\r\n- Improve various comments and fix some code consistency cases\r\n- Improve a few logging bits\r\n- Implement a most-recently-used nonce tracking for detecting self\r\n  connections and generate a unique nonce for each peer\r\n\r\nImplements and closes #439 "},"comment":{"url":"https://api.github.com/repos/btcsuite/btcd/issues/comments/146721176","html_url":"https://github.com/btcsuite/btcd/pull/445#issuecomment-146721176","issue_url":"https://api.github.com/repos/btcsuite/btcd/issues/445","id":146721176,"user":{"login":"davecgh","id":2115102,"avatar_url":"https://avatars.githubusercontent.com/u/2115102?v=3","gravatar_id":"","url":"https://api.github.com/users/davecgh","html_url":"https://github.com/davecgh","followers_url":"https://api.github.com/users/davecgh/followers","following_url":"https://api.github.com/users/davecgh/following{/other_user}","gists_url":"https://api.github.com/users/davecgh/gists{/gist_id}","starred_url":"https://api.github.com/users/davecgh/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/davecgh/subscriptions","organizations_url":"https://api.github.com/users/davecgh/orgs","repos_url":"https://api.github.com/users/davecgh/repos","events_url":"https://api.github.com/users/davecgh/events{/privacy}","received_events_url":"https://api.github.com/users/davecgh/received_events","type":"User","site_admin":false},"created_at":"2015-10-09T00:06:16Z","updated_at":"2015-10-09T00:06:16Z","body":"The `server` type still has a `peerState` member that is now unused and `newServer` is creating it.  Also, when it is created in `peerHandler` it's not adjusting the `maxOutboundPeers` as it should be (and is doing in `newServer` currently)."}}