From 68424281c534b9abc58ad7e7391107b49f8e6830 Mon Sep 17 00:00:00 2001 From: Mike Hearn Date: Sun, 19 Feb 2012 12:22:43 +0100 Subject: [PATCH] Print out alert messages to the log. --- src/com/google/bitcoin/core/BitcoinSerializer.java | 1 - src/com/google/bitcoin/core/Peer.java | 10 ++++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/src/com/google/bitcoin/core/BitcoinSerializer.java b/src/com/google/bitcoin/core/BitcoinSerializer.java index 53ca0f15..2f152bdf 100644 --- a/src/com/google/bitcoin/core/BitcoinSerializer.java +++ b/src/com/google/bitcoin/core/BitcoinSerializer.java @@ -335,7 +335,6 @@ public class BitcoinSerializer { } else if (command.equals("headers")) { return new HeadersMessage(params, payloadBytes); } else if (command.equals("alert")) { - log.info("alert payload " + Utils.bytesToHexString(payloadBytes)); return new AlertMessage(params, payloadBytes); } else { log.warn("No support for deserializing message with name {}", command); diff --git a/src/com/google/bitcoin/core/Peer.java b/src/com/google/bitcoin/core/Peer.java index 14e0e275..9e8b749f 100644 --- a/src/com/google/bitcoin/core/Peer.java +++ b/src/com/google/bitcoin/core/Peer.java @@ -209,6 +209,8 @@ public class Peer { // properly explore the network. } else if (m instanceof HeadersMessage) { processHeaders((HeadersMessage) m); + } else if (m instanceof AlertMessage) { + processAlert((AlertMessage)m); } else { // TODO: Handle the other messages we can receive. log.warn("Received unhandled message: {}", m); @@ -234,6 +236,14 @@ public class Peer { disconnect(); } + private void processAlert(AlertMessage m) { + if (m.isSignatureValid()) { + log.info("Received alert from peer {}: {}", toString(), m.getStatusBar()); + } else { + log.warn("Received alert with invalid signature from peer {}: {}", toString(), m.getStatusBar()); + } + } + private void processHeaders(HeadersMessage m) throws IOException, ProtocolException { // Runs in network loop thread for this peer. //