Peer: Break out the onTransactionBroadcast event into a separate interface.

This commit is contained in:
Mike Hearn 2015-09-18 21:10:53 +01:00
parent c2a67aaa59
commit 7014810cf6
10 changed files with 99 additions and 116 deletions

View File

@ -78,6 +78,7 @@ public class Peer extends PeerSocketHandler {
} }
private final CopyOnWriteArrayList<PeerConnectionListenerRegistration> connectionEventListeners; private final CopyOnWriteArrayList<PeerConnectionListenerRegistration> connectionEventListeners;
private final CopyOnWriteArrayList<ListenerRegistration<PeerDataEventListener>> dataEventListeners; private final CopyOnWriteArrayList<ListenerRegistration<PeerDataEventListener>> dataEventListeners;
private final CopyOnWriteArrayList<ListenerRegistration<OnTransactionBroadcastListener>> onTransactionEventListeners;
// Whether to try and download blocks and transactions from this peer. Set to false by PeerGroup if not the // Whether to try and download blocks and transactions from this peer. Set to false by PeerGroup if not the
// primary peer. This is to avoid redundant work and concurrency problems with downloading the same chain // primary peer. This is to avoid redundant work and concurrency problems with downloading the same chain
// in parallel. // in parallel.
@ -217,6 +218,7 @@ public class Peer extends PeerSocketHandler {
this.getDataFutures = new CopyOnWriteArrayList<GetDataRequest>(); this.getDataFutures = new CopyOnWriteArrayList<GetDataRequest>();
this.connectionEventListeners = new CopyOnWriteArrayList<PeerConnectionListenerRegistration>(); this.connectionEventListeners = new CopyOnWriteArrayList<PeerConnectionListenerRegistration>();
this.dataEventListeners = new CopyOnWriteArrayList<ListenerRegistration<PeerDataEventListener>>(); this.dataEventListeners = new CopyOnWriteArrayList<ListenerRegistration<PeerDataEventListener>>();
this.onTransactionEventListeners = new CopyOnWriteArrayList<ListenerRegistration<OnTransactionBroadcastListener>>();
this.getAddrFutures = new LinkedList<SettableFuture<AddressMessage>>(); this.getAddrFutures = new LinkedList<SettableFuture<AddressMessage>>();
this.fastCatchupTimeSecs = params.getGenesisBlock().getTimeSeconds(); this.fastCatchupTimeSecs = params.getGenesisBlock().getTimeSeconds();
this.isAcked = false; this.isAcked = false;
@ -255,6 +257,7 @@ public class Peer extends PeerSocketHandler {
public void addEventListener(AbstractPeerEventListener listener, Executor executor) { public void addEventListener(AbstractPeerEventListener listener, Executor executor) {
addConnectionEventListener(executor, listener); addConnectionEventListener(executor, listener);
addDataEventListener(executor, listener); addDataEventListener(executor, listener);
addOnTransactionBroadcastListener(executor, listener);
} }
/** Deprecated: use the more specific event handler methods instead */ /** Deprecated: use the more specific event handler methods instead */
@ -262,50 +265,39 @@ public class Peer extends PeerSocketHandler {
public void removeEventListener(AbstractPeerEventListener listener) { public void removeEventListener(AbstractPeerEventListener listener) {
removeConnectionEventListener(listener); removeConnectionEventListener(listener);
removeDataEventListener(listener); removeDataEventListener(listener);
removeOnTransactionBroadcastListener(listener);
} }
/** /** Registers a listener that is invoked when a peer is connected or disconnected. */
* Registers the given object as an event listener that will be invoked on the user thread. Note that listeners
* added this way will <b>not</b> receive {@link PeerEventListener#getData(Peer, GetDataMessage)} or
* {@link PeerEventListener#onPreMessageReceived(Peer, Message)} calls because those require that the listener
* be added using {@link Threading#SAME_THREAD}, which requires the other addListener form.
*/
public void addConnectionEventListener(PeerConnectionEventListener listener) { public void addConnectionEventListener(PeerConnectionEventListener listener) {
addConnectionEventListener(Threading.USER_THREAD, listener); addConnectionEventListener(Threading.USER_THREAD, listener);
} }
/** /** Registers a listener that is invoked when a peer is connected or disconnected. */
* Registers the given object as an event listener that will be invoked on the user thread. Note that listeners
* added this way will <b>not</b> receive {@link PeerEventListener#getData(Peer, GetDataMessage)} or
* {@link PeerEventListener#onPreMessageReceived(Peer, Message)} calls because those require that the listener
* be added using {@link Threading#SAME_THREAD}, which requires the other addListener form.
*/
public void addDataEventListener(PeerDataEventListener listener) {
addDataEventListener(Threading.USER_THREAD, listener);
}
/**
* Registers the given object as an event listener that will be invoked by the given executor. Note that listeners
* added using any other executor than {@link Threading#SAME_THREAD} will <b>not</b> receive
* {@link PeerEventListener#getData(Peer, GetDataMessage)} or
* {@link PeerEventListener#onPreMessageReceived(Peer, Message)} calls because this class is not willing to cross
* threads in order to get the results of those hook methods.
*/
public void addConnectionEventListener(Executor executor, PeerConnectionEventListener listener) { public void addConnectionEventListener(Executor executor, PeerConnectionEventListener listener) {
connectionEventListeners.add(new PeerConnectionListenerRegistration(listener, executor)); connectionEventListeners.add(new PeerConnectionListenerRegistration(listener, executor));
} }
/** /** Registers a listener that is called when messages are received. */
* Registers the given object as an event listener that will be invoked by the given executor. Note that listeners public void addDataEventListener(PeerDataEventListener listener) {
* added using any other executor than {@link Threading#SAME_THREAD} will <b>not</b> receive addDataEventListener(Threading.USER_THREAD, listener);
* {@link PeerEventListener#getData(Peer, GetDataMessage)} or }
* {@link PeerEventListener#onPreMessageReceived(Peer, Message)} calls because this class is not willing to cross
* threads in order to get the results of those hook methods. /** Registers a listener that is called when messages are received. */
*/
public void addDataEventListener(Executor executor, PeerDataEventListener listener) { public void addDataEventListener(Executor executor, PeerDataEventListener listener) {
dataEventListeners.add(new ListenerRegistration<PeerDataEventListener>(executor, listener)); dataEventListeners.add(new ListenerRegistration<PeerDataEventListener>(executor, listener));
} }
/** Registers a listener that is called when a transaction is broadcast across the network */
public void addOnTransactionBroadcastListener(OnTransactionBroadcastListener listener) {
addOnTransactionBroadcastListener(Threading.USER_THREAD, listener);
}
/** Registers a listener that is called when a transaction is broadcast across the network */
public void addOnTransactionBroadcastListener(Executor executor, OnTransactionBroadcastListener listener) {
onTransactionEventListeners.add(new ListenerRegistration<OnTransactionBroadcastListener>(executor, listener));
}
// Package-local version for PeerGroup // Package-local version for PeerGroup
void addConnectionEventListenerWithoutOnDisconnect(Executor executor, PeerConnectionEventListener listener) { void addConnectionEventListenerWithoutOnDisconnect(Executor executor, PeerConnectionEventListener listener) {
connectionEventListeners.add(new PeerConnectionListenerRegistration(listener, executor, false)); connectionEventListeners.add(new PeerConnectionListenerRegistration(listener, executor, false));
@ -319,6 +311,10 @@ public class Peer extends PeerSocketHandler {
return ListenerRegistration.removeFromList(listener, dataEventListeners); return ListenerRegistration.removeFromList(listener, dataEventListeners);
} }
public boolean removeOnTransactionBroadcastListener(OnTransactionBroadcastListener listener) {
return ListenerRegistration.removeFromList(listener, onTransactionEventListeners);
}
@Override @Override
public String toString() { public String toString() {
PeerAddress addr = getAddress(); PeerAddress addr = getAddress();
@ -739,7 +735,7 @@ public class Peer extends PeerSocketHandler {
} }
// Tell all listeners about this tx so they can decide whether to keep it or not. If no listener keeps a // Tell all listeners about this tx so they can decide whether to keep it or not. If no listener keeps a
// reference around then the memory pool will forget about it after a while too because it uses weak references. // reference around then the memory pool will forget about it after a while too because it uses weak references.
for (final ListenerRegistration<PeerDataEventListener> registration : dataEventListeners) { for (final ListenerRegistration<OnTransactionBroadcastListener> registration : onTransactionEventListeners) {
registration.executor.execute(new Runnable() { registration.executor.execute(new Runnable() {
@Override @Override
public void run() { public void run() {

View File

@ -26,13 +26,7 @@ import com.google.common.util.concurrent.*;
import com.squareup.okhttp.*; import com.squareup.okhttp.*;
import com.subgraph.orchid.*; import com.subgraph.orchid.*;
import net.jcip.annotations.*; import net.jcip.annotations.*;
import org.bitcoinj.core.listeners.AbstractPeerConnectionEventListener; import org.bitcoinj.core.listeners.*;
import org.bitcoinj.core.listeners.AbstractPeerDataEventListener;
import org.bitcoinj.core.listeners.AbstractWalletEventListener;
import org.bitcoinj.core.listeners.DownloadProgressTracker;
import org.bitcoinj.core.listeners.PeerConnectionEventListener;
import org.bitcoinj.core.listeners.PeerDataEventListener;
import org.bitcoinj.core.listeners.WalletEventListener;
import org.bitcoinj.crypto.*; import org.bitcoinj.crypto.*;
import org.bitcoinj.net.*; import org.bitcoinj.net.*;
import org.bitcoinj.net.discovery.*; import org.bitcoinj.net.discovery.*;
@ -119,10 +113,11 @@ public class PeerGroup implements TransactionBroadcaster {
@GuardedBy("lock") private Peer downloadPeer; @GuardedBy("lock") private Peer downloadPeer;
// Callback for events related to chain download. // Callback for events related to chain download.
@Nullable @GuardedBy("lock") private PeerDataEventListener downloadListener; @Nullable @GuardedBy("lock") private PeerDataEventListener downloadListener;
// Callbacks for events related to peer connection/disconnection /** Callbacks for events related to peer connection/disconnection */
private final CopyOnWriteArrayList<ListenerRegistration<PeerConnectionEventListener>> peerConnectionEventListeners; protected final CopyOnWriteArrayList<ListenerRegistration<PeerConnectionEventListener>> peerConnectionEventListeners;
// Callbacks for events related to peer data being received /** Callbacks for events related to peer data being received */
private final CopyOnWriteArrayList<ListenerRegistration<PeerDataEventListener>> peerDataEventListeners; protected final CopyOnWriteArrayList<ListenerRegistration<PeerDataEventListener>> peerDataEventListeners;
protected final CopyOnWriteArrayList<ListenerRegistration<OnTransactionBroadcastListener>> onTransactionBroadastEventListeners;
// Peer discovery sources, will be polled occasionally if there aren't enough inactives. // Peer discovery sources, will be polled occasionally if there aren't enough inactives.
private final CopyOnWriteArraySet<PeerDiscovery> peerDiscoverers; private final CopyOnWriteArraySet<PeerDiscovery> peerDiscoverers;
// The version message to use for new connections. // The version message to use for new connections.
@ -411,6 +406,7 @@ public class PeerGroup implements TransactionBroadcaster {
peerDiscoverers = new CopyOnWriteArraySet<PeerDiscovery>(); peerDiscoverers = new CopyOnWriteArraySet<PeerDiscovery>();
peerConnectionEventListeners = new CopyOnWriteArrayList<ListenerRegistration<PeerConnectionEventListener>>(); peerConnectionEventListeners = new CopyOnWriteArrayList<ListenerRegistration<PeerConnectionEventListener>>();
peerDataEventListeners = new CopyOnWriteArrayList<ListenerRegistration<PeerDataEventListener>>(); peerDataEventListeners = new CopyOnWriteArrayList<ListenerRegistration<PeerDataEventListener>>();
onTransactionBroadastEventListeners = new CopyOnWriteArrayList<ListenerRegistration<OnTransactionBroadcastListener>>();
runningBroadcasts = Collections.synchronizedSet(new HashSet<TransactionBroadcast>()); runningBroadcasts = Collections.synchronizedSet(new HashSet<TransactionBroadcast>());
bloomFilterMerger = new FilterMerger(DEFAULT_BLOOM_FILTER_FP_RATE); bloomFilterMerger = new FilterMerger(DEFAULT_BLOOM_FILTER_FP_RATE);
} }
@ -691,17 +687,7 @@ public class PeerGroup implements TransactionBroadcaster {
peer.addConnectionEventListener(executor, listener); peer.addConnectionEventListener(executor, listener);
} }
/** /** See {@link Peer#addDataEventListener(Executor, PeerDataEventListener)} */
* <p>Adds a listener that will be notified on the given executor when:</p>
* <ol>
* <li>New peers are connected to.</li>
* <li>Peers are disconnected from.</li>
* <li>A message is received by the download peer (there is always one peer which is elected as a peer which
* will be used to retrieve data).
* <li>Blocks are downloaded by the download peer.</li>
* </li>
* </ol>
*/
public void addDataEventListener(final Executor executor, final PeerDataEventListener listener) { public void addDataEventListener(final Executor executor, final PeerDataEventListener listener) {
peerDataEventListeners.add(new ListenerRegistration<PeerDataEventListener>(executor, checkNotNull(listener))); peerDataEventListeners.add(new ListenerRegistration<PeerDataEventListener>(executor, checkNotNull(listener)));
for (Peer peer : getConnectedPeers()) for (Peer peer : getConnectedPeers())
@ -710,22 +696,30 @@ public class PeerGroup implements TransactionBroadcaster {
peer.addDataEventListener(executor, listener); peer.addDataEventListener(executor, listener);
} }
/** /** See {@link Peer#addDataEventListener(PeerDataEventListener)} */
* Same as {@link PeerGroup#addEventListener(PeerEventListener, java.util.concurrent.Executor)} but defaults
* to running on the user thread.
*/
public void addConnectionEventListener(PeerConnectionEventListener listener) {
addConnectionEventListener(Threading.USER_THREAD, listener);
}
/**
* Same as {@link PeerGroup#addEventListener(PeerEventListener, java.util.concurrent.Executor)} but defaults
* to running on the user thread.
*/
public void addDataEventListener(PeerDataEventListener listener) { public void addDataEventListener(PeerDataEventListener listener) {
addDataEventListener(Threading.USER_THREAD, listener); addDataEventListener(Threading.USER_THREAD, listener);
} }
/** See {@link Peer#addOnTransactionBroadcastListener(OnTransactionBroadcastListener)} */
public void addOnTransactionBroadcastListener(OnTransactionBroadcastListener listener) {
addOnTransactionBroadcastListener(Threading.USER_THREAD, listener);
}
/** See {@link Peer#addOnTransactionBroadcastListener(OnTransactionBroadcastListener)} */
public void addOnTransactionBroadcastListener(Executor executor, OnTransactionBroadcastListener listener) {
onTransactionBroadastEventListeners.add(new ListenerRegistration<OnTransactionBroadcastListener>(executor, checkNotNull(listener)));
for (Peer peer : getConnectedPeers())
peer.addOnTransactionBroadcastListener(executor, listener);
for (Peer peer: getPendingPeers())
peer.addOnTransactionBroadcastListener(executor, listener);
}
/** See {@link Peer#addConnectionEventListener(PeerConnectionEventListener)} */
public void addConnectionEventListener(PeerConnectionEventListener listener) {
addConnectionEventListener(Threading.USER_THREAD, listener);
}
/** The given event listener will no longer be called with events. */ /** The given event listener will no longer be called with events. */
public boolean removeConnectionEventListener(PeerConnectionEventListener listener) { public boolean removeConnectionEventListener(PeerConnectionEventListener listener) {
boolean result = ListenerRegistration.removeFromList(listener, peerConnectionEventListeners); boolean result = ListenerRegistration.removeFromList(listener, peerConnectionEventListeners);
@ -746,12 +740,14 @@ public class PeerGroup implements TransactionBroadcaster {
return result; return result;
} }
/** /** The given event listener will no longer be called with events. */
* Removes all event listeners simultaneously. Note that this includes listeners added internally by the framework public boolean removeOnTransactionBroadcastListener(OnTransactionBroadcastListener listener) {
* so it's generally not advised to use this - it exists for special purposes only. boolean result = ListenerRegistration.removeFromList(listener, onTransactionBroadastEventListeners);
*/ for (Peer peer : getConnectedPeers())
public void clearEventListeners() { peer.removeOnTransactionBroadcastListener(listener);
peerConnectionEventListeners.clear(); for (Peer peer : getPendingPeers())
peer.removeOnTransactionBroadcastListener(listener);
return result;
} }
/** /**
@ -1393,12 +1389,12 @@ public class PeerGroup implements TransactionBroadcaster {
// Make sure the peer knows how to upload transactions that are requested from us. // Make sure the peer knows how to upload transactions that are requested from us.
peer.addDataEventListener(Threading.SAME_THREAD, peerListener); peer.addDataEventListener(Threading.SAME_THREAD, peerListener);
// And set up event listeners for clients. This will allow them to find out about new transactions and blocks. // And set up event listeners for clients. This will allow them to find out about new transactions and blocks.
for (ListenerRegistration<PeerConnectionEventListener> registration : peerConnectionEventListeners) { for (ListenerRegistration<PeerConnectionEventListener> registration : peerConnectionEventListeners)
peer.addConnectionEventListenerWithoutOnDisconnect(registration.executor, registration.listener); peer.addConnectionEventListenerWithoutOnDisconnect(registration.executor, registration.listener);
} for (ListenerRegistration<PeerDataEventListener> registration : peerDataEventListeners)
for (ListenerRegistration<PeerDataEventListener> registration : peerDataEventListeners) {
peer.addDataEventListener(registration.executor, registration.listener); peer.addDataEventListener(registration.executor, registration.listener);
} for (ListenerRegistration<OnTransactionBroadcastListener> registration : onTransactionBroadastEventListeners)
peer.addOnTransactionBroadcastListener(registration.executor, registration.listener);
} finally { } finally {
lock.unlock(); lock.unlock();
} }
@ -1564,9 +1560,10 @@ public class PeerGroup implements TransactionBroadcaster {
} }
final int fNumConnectedPeers = numConnectedPeers; final int fNumConnectedPeers = numConnectedPeers;
for (ListenerRegistration<PeerDataEventListener> registration : peerDataEventListeners) { for (ListenerRegistration<PeerDataEventListener> registration : peerDataEventListeners)
peer.removeDataEventListener(registration.listener); peer.removeDataEventListener(registration.listener);
} for (ListenerRegistration<OnTransactionBroadcastListener> registration : onTransactionBroadastEventListeners)
peer.removeOnTransactionBroadcastListener(registration.listener);
for (final ListenerRegistration<PeerConnectionEventListener> registration : peerConnectionEventListeners) { for (final ListenerRegistration<PeerConnectionEventListener> registration : peerConnectionEventListeners) {
registration.executor.execute(new Runnable() { registration.executor.execute(new Runnable() {
@Override @Override

View File

@ -16,14 +16,10 @@
package org.bitcoinj.core.listeners; package org.bitcoinj.core.listeners;
import org.bitcoinj.core.Block; import org.bitcoinj.core.*;
import org.bitcoinj.core.FilteredBlock;
import org.bitcoinj.core.GetDataMessage;
import org.bitcoinj.core.Message;
import org.bitcoinj.core.Peer;
import org.bitcoinj.core.Transaction;
import javax.annotation.*; import javax.annotation.*;
import java.util.List; import java.util.*;
/** /**
* Deprecated: implement the more specific event listener interfaces instead to fill out only what you need * Deprecated: implement the more specific event listener interfaces instead to fill out only what you need
@ -44,10 +40,6 @@ public abstract class AbstractPeerDataEventListener implements PeerDataEventList
return m; return m;
} }
@Override
public void onTransaction(Peer peer, Transaction t) {
}
@Override @Override
public List<Message> getData(Peer peer, GetDataMessage m) { public List<Message> getData(Peer peer, GetDataMessage m) {
return null; return null;

View File

@ -31,7 +31,7 @@ import java.util.Set;
* Deprecated: implement the more specific event listener interfaces instead to fill out only what you need * Deprecated: implement the more specific event listener interfaces instead to fill out only what you need
*/ */
@Deprecated @Deprecated
public abstract class AbstractPeerEventListener extends AbstractPeerDataEventListener implements PeerConnectionEventListener { public abstract class AbstractPeerEventListener extends AbstractPeerDataEventListener implements PeerConnectionEventListener, OnTransactionBroadcastListener {
@Override @Override
public void onBlocksDownloaded(Peer peer, Block block, @Nullable FilteredBlock filteredBlock, int blocksLeft) { public void onBlocksDownloaded(Peer peer, Block block, @Nullable FilteredBlock filteredBlock, int blocksLeft) {
} }

View File

@ -0,0 +1,13 @@
package org.bitcoinj.core.listeners;
import org.bitcoinj.core.*;
/**
* Called when a new transaction is broadcast over the network.
*/
public interface OnTransactionBroadcastListener {
/**
* Called when a new transaction is broadcast over the network.
*/
void onTransaction(Peer peer, Transaction t);
}

View File

@ -16,14 +16,10 @@
package org.bitcoinj.core.listeners; package org.bitcoinj.core.listeners;
import org.bitcoinj.core.Block; import org.bitcoinj.core.*;
import org.bitcoinj.core.FilteredBlock;
import org.bitcoinj.core.GetDataMessage; import javax.annotation.*;
import org.bitcoinj.core.Message; import java.util.*;
import org.bitcoinj.core.Peer;
import org.bitcoinj.core.Transaction;
import javax.annotation.Nullable;
import java.util.List;
/** /**
* <p>Implementors can listen to events like blocks being downloaded/transactions being broadcast/connect/disconnects, * <p>Implementors can listen to events like blocks being downloaded/transactions being broadcast/connect/disconnects,
@ -65,11 +61,6 @@ public interface PeerDataEventListener {
*/ */
Message onPreMessageReceived(Peer peer, Message m); Message onPreMessageReceived(Peer peer, Message m);
/**
* Called when a new transaction is broadcast over the network.
*/
void onTransaction(Peer peer, Transaction t);
/** /**
* <p>Called when a peer receives a getdata message, usually in response to an "inv" being broadcast. Return as many * <p>Called when a peer receives a getdata message, usually in response to an "inv" being broadcast. Return as many
* items as possible which appear in the {@link GetDataMessage}, or null if you're not interested in responding.</p> * items as possible which appear in the {@link GetDataMessage}, or null if you're not interested in responding.</p>

View File

@ -16,8 +16,7 @@
package org.bitcoinj.jni; package org.bitcoinj.jni;
import org.bitcoinj.core.listeners.PeerConnectionEventListener; import org.bitcoinj.core.listeners.*;
import org.bitcoinj.core.listeners.PeerDataEventListener;
import org.bitcoinj.core.*; import org.bitcoinj.core.*;
import javax.annotation.*; import javax.annotation.*;
@ -29,7 +28,7 @@ import java.util.Set;
* this class using JNI on the native side, thus several instances of this can point to different actual * this class using JNI on the native side, thus several instances of this can point to different actual
* native implementations. * native implementations.
*/ */
public class NativePeerEventListener implements PeerConnectionEventListener, PeerDataEventListener { public class NativePeerEventListener implements PeerConnectionEventListener, PeerDataEventListener, OnTransactionBroadcastListener {
public long ptr; public long ptr;
@Override @Override

View File

@ -20,9 +20,7 @@ package org.bitcoinj.core;
import com.google.common.collect.*; import com.google.common.collect.*;
import com.google.common.net.*; import com.google.common.net.*;
import com.google.common.util.concurrent.*; import com.google.common.util.concurrent.*;
import org.bitcoinj.core.listeners.AbstractPeerConnectionEventListener; import org.bitcoinj.core.listeners.*;
import org.bitcoinj.core.listeners.AbstractPeerDataEventListener;
import org.bitcoinj.core.listeners.AbstractPeerEventListener;
import org.bitcoinj.net.discovery.*; import org.bitcoinj.net.discovery.*;
import org.bitcoinj.testing.*; import org.bitcoinj.testing.*;
import org.bitcoinj.utils.*; import org.bitcoinj.utils.*;
@ -349,7 +347,7 @@ public class PeerGroupTest extends TestWithPeerGroup {
final Transaction[] event = new Transaction[1]; final Transaction[] event = new Transaction[1];
final TransactionConfidence[] confEvent = new TransactionConfidence[1]; final TransactionConfidence[] confEvent = new TransactionConfidence[1];
peerGroup.addDataEventListener(Threading.SAME_THREAD, new AbstractPeerDataEventListener() { peerGroup.addOnTransactionBroadcastListener(Threading.SAME_THREAD, new OnTransactionBroadcastListener() {
@Override @Override
public void onTransaction(Peer peer, Transaction t) { public void onTransaction(Peer peer, Transaction t) {
event[0] = t; event[0] = t;

View File

@ -17,10 +17,7 @@
package org.bitcoinj.core; package org.bitcoinj.core;
import com.google.common.collect.*; import com.google.common.collect.*;
import org.bitcoinj.core.listeners.AbstractPeerConnectionEventListener; import org.bitcoinj.core.listeners.*;
import org.bitcoinj.core.listeners.AbstractPeerDataEventListener;
import org.bitcoinj.core.listeners.AbstractWalletEventListener;
import org.bitcoinj.core.listeners.PeerConnectionEventListener;
import org.bitcoinj.params.TestNet3Params; import org.bitcoinj.params.TestNet3Params;
import org.bitcoinj.testing.FakeTxBuilder; import org.bitcoinj.testing.FakeTxBuilder;
import org.bitcoinj.testing.InboundMessageQueuer; import org.bitcoinj.testing.InboundMessageQueuer;
@ -549,7 +546,7 @@ public class PeerTest extends TestWithNetworkConnections {
ECKey to = new ECKey(); ECKey to = new ECKey();
final Transaction[] onTx = new Transaction[1]; final Transaction[] onTx = new Transaction[1];
peer.addDataEventListener(Threading.SAME_THREAD, new AbstractPeerDataEventListener() { peer.addOnTransactionBroadcastListener(Threading.SAME_THREAD, new OnTransactionBroadcastListener() {
@Override @Override
public void onTransaction(Peer peer1, Transaction t) { public void onTransaction(Peer peer1, Transaction t) {
onTx[0] = t; onTx[0] = t;

View File

@ -20,7 +20,7 @@ package org.bitcoinj.tools;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
import org.bitcoinj.core.listeners.AbstractPeerDataEventListener; import org.bitcoinj.core.listeners.*;
import org.bitcoinj.core.NetworkParameters; import org.bitcoinj.core.NetworkParameters;
import org.bitcoinj.core.Peer; import org.bitcoinj.core.Peer;
import org.bitcoinj.core.PeerGroup; import org.bitcoinj.core.PeerGroup;
@ -49,7 +49,7 @@ public class WatchMempool {
PeerGroup peerGroup = new PeerGroup(PARAMS); PeerGroup peerGroup = new PeerGroup(PARAMS);
peerGroup.setMaxConnections(32); peerGroup.setMaxConnections(32);
peerGroup.addPeerDiscovery(new DnsDiscovery(PARAMS)); peerGroup.addPeerDiscovery(new DnsDiscovery(PARAMS));
peerGroup.addDataEventListener(new AbstractPeerDataEventListener() { peerGroup.addOnTransactionBroadcastListener(new OnTransactionBroadcastListener() {
@Override @Override
public void onTransaction(Peer peer, Transaction tx) { public void onTransaction(Peer peer, Transaction tx) {
Result result = DefaultRiskAnalysis.FACTORY.create(null, tx, NO_DEPS).analyze(); Result result = DefaultRiskAnalysis.FACTORY.create(null, tx, NO_DEPS).analyze();