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

Fix a class casting bug that isn't picked up by the unit tests as they don't use a real socket. Due to the move to embedded handlers during code review.

This commit is contained in:
Mike Hearn 2012-07-04 17:38:28 +02:00
parent 567fccbf8a
commit f018e2956e
2 changed files with 18 additions and 11 deletions

View File

@ -561,9 +561,12 @@ public class PeerGroup {
*/ */
public ChannelFuture connectTo(SocketAddress address) { public ChannelFuture connectTo(SocketAddress address) {
ChannelFuture future = bootstrap.connect(address); ChannelFuture future = bootstrap.connect(address);
TCPNetworkConnection connection = (TCPNetworkConnection)future.getChannel().getPipeline().get("codec"); TCPNetworkConnection.NetworkHandler networkHandler =
if (connection != null) (TCPNetworkConnection.NetworkHandler) future.getChannel().getPipeline().get("codec");
connection.setRemoteAddress(address); if (networkHandler != null) {
// This can be null in unit tests or apps that don't use TCP connections.
networkHandler.getOwnerObject().setRemoteAddress(address);
}
Peer peer = peerFromChannelFuture(future); Peer peer = peerFromChannelFuture(future);
channelFutures.put(peer, future); channelFutures.put(peer, future);
return future; return future;

View File

@ -16,14 +16,6 @@
package com.google.bitcoin.core; package com.google.bitcoin.core;
import static org.jboss.netty.channel.Channels.write;
import java.io.IOException;
import java.net.InetAddress;
import java.net.InetSocketAddress;
import java.net.SocketAddress;
import java.util.Date;
import org.jboss.netty.buffer.ChannelBuffer; import org.jboss.netty.buffer.ChannelBuffer;
import org.jboss.netty.buffer.ChannelBufferInputStream; import org.jboss.netty.buffer.ChannelBufferInputStream;
import org.jboss.netty.buffer.ChannelBufferOutputStream; import org.jboss.netty.buffer.ChannelBufferOutputStream;
@ -34,6 +26,14 @@ import org.jboss.netty.handler.codec.replay.VoidEnum;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import java.io.IOException;
import java.net.InetAddress;
import java.net.InetSocketAddress;
import java.net.SocketAddress;
import java.util.Date;
import static org.jboss.netty.channel.Channels.write;
/** /**
* A {@code TCPNetworkConnection} is used for connecting to a Bitcoin node over the standard TCP/IP protocol.<p> * A {@code TCPNetworkConnection} is used for connecting to a Bitcoin node over the standard TCP/IP protocol.<p>
* *
@ -173,6 +173,10 @@ public class TCPNetworkConnection {
serializer.serialize(message, new ChannelBufferOutputStream(buffer)); serializer.serialize(message, new ChannelBufferOutputStream(buffer));
write(ctx, e.getFuture(), buffer, e.getRemoteAddress()); write(ctx, e.getFuture(), buffer, e.getRemoteAddress());
} }
public TCPNetworkConnection getOwnerObject() {
return TCPNetworkConnection.this;
}
} }
/** Returns the Netty Pipeline stage handling Bitcoin serialization for this connection. */ /** Returns the Netty Pipeline stage handling Bitcoin serialization for this connection. */