3
0
mirror of https://github.com/Qortal/altcoinj.git synced 2025-02-07 06:44:16 +00:00

Missing synchronization for iterations.

(over synchronizedMap/synchronizedSet)
This commit is contained in:
Miron Cuperman 2012-07-18 10:48:07 -07:00
parent 831f2d582f
commit 4d58ea5111

View File

@ -304,7 +304,9 @@ public class PeerGroup {
*/ */
public synchronized List<Peer> getConnectedPeers() { public synchronized List<Peer> getConnectedPeers() {
ArrayList<Peer> result = new ArrayList<Peer>(peers.size()); ArrayList<Peer> result = new ArrayList<Peer>(peers.size());
result.addAll(peers); synchronized (peers) {
result.addAll(peers);
}
return result; return result;
} }
@ -366,12 +368,14 @@ public class PeerGroup {
FutureTask<Transaction> future = new FutureTask<Transaction>(new Runnable() { FutureTask<Transaction> future = new FutureTask<Transaction>(new Runnable() {
public void run() { public void run() {
// This is run with the peer group already locked. // This is run with the peer group already locked.
for (Peer peer : peers) { synchronized (peers) {
try { for (Peer peer : peers) {
log.info("{}: Sending transaction {}", peer.getAddress(), tx.getHashAsString()); try {
peer.sendMessage(tx); log.info("{}: Sending transaction {}", peer.getAddress(), tx.getHashAsString());
} catch (IOException e) { peer.sendMessage(tx);
log.warn("Caught IOException whilst sending transaction: {}", e.getMessage()); } catch (IOException e) {
log.warn("Caught IOException whilst sending transaction: {}", e.getMessage());
}
} }
} }
} }
@ -433,9 +437,7 @@ public class PeerGroup {
* {@link PeerEventListener} and use the onPeerConnected/onPeerDisconnected methods. * {@link PeerEventListener} and use the onPeerConnected/onPeerDisconnected methods.
*/ */
public synchronized int numConnectedPeers() { public synchronized int numConnectedPeers() {
synchronized (peers) { return peers.size();
return peers.size();
}
} }
public synchronized boolean isRunning() { public synchronized boolean isRunning() {
@ -500,8 +502,10 @@ public class PeerGroup {
synchronized (PeerGroup.this) { synchronized (PeerGroup.this) {
running = false; running = false;
shutdownPeerDiscovery(); shutdownPeerDiscovery();
for (ChannelFuture future : channelFutures.values()) { synchronized (channelFutures.values()) {
future.getChannel().close(); for (ChannelFuture future : channelFutures.values()) {
future.getChannel().close();
}
} }
bootstrap.releaseExternalResources(); bootstrap.releaseExternalResources();
} }