Transaction broadcast (#209)

* Add transaction broadcast to all known peers once they have been
accepted by our own transaction pool.
* Some debug log

Fixes #200
This commit is contained in:
Ignotus Peverell
2017-10-25 21:06:24 +00:00
committed by GitHub
parent 7178b400b8
commit e2e24bc38e
7 changed files with 76 additions and 2 deletions
+7
View File
@@ -139,6 +139,13 @@ impl Peer {
self.proto.send_block(b)
}
/// Sends the provided transaction to the remote peer. The request may be
/// dropped if the remote peer is known to already have the transaction.
pub fn send_transaction(&self, tx: &core::Transaction) -> Result<(), Error> {
// TODO do not send if the peer sent us the tx in the first place
self.proto.send_transaction(tx)
}
pub fn send_header_request(&self, locator: Vec<Hash>) -> Result<(), Error> {
self.proto.send_header_request(locator)
}
+14
View File
@@ -270,6 +270,20 @@ impl Server {
}
}
/// Broadcasts the provided transaction to all our peers. A peer
/// implementation may drop the broadcast request if it knows the
/// remote peer already has the transaction.
pub fn broadcast_transaction(&self, tx: &core::Transaction) {
let peers = self.peers.write().unwrap();
for p in peers.deref() {
if p.is_connected() {
if let Err(e) = p.send_transaction(tx) {
debug!(LOGGER, "Error sending block to peer: {:?}", e);
}
}
}
}
/// Number of peers we're currently connected to.
pub fn peer_count(&self) -> u32 {
self.peers.read().unwrap().len() as u32