configuration);
futureResponseTCP.addListener(new BaseFutureAdapter<FutureResponse>() {
@Override
public void operationComplete(FutureResponse future) throws Exception {
PeerAddress serverAddress = peer.peerBean().serverPeerAddress();
if (futureResponseTCP.isSuccess()) {
Collection<PeerAddress> tmp = futureResponseTCP.responseMessage().neighborsSet(0)
.neighbors();
futureDiscover.reporter(futureResponseTCP.responseMessage().sender());
if (tmp.size() == 1) {
PeerAddress seenAs = tmp.iterator().next();
LOG.info("I'm seen as {} by peer {}. I see myself as {}",
seenAs, peerAddress, peer.peerAddress().inetAddress());
if (!peer.peerAddress().inetAddress().equals(seenAs.inetAddress())) {
// check if we have this interface in that we can
// listen to
Bindings bindings2 = new Bindings().addAddress(seenAs.inetAddress());
DiscoverResults discoverResults = DiscoverNetworks.discoverInterfaces(bindings2);
String status = discoverResults.status();
LOG.info("2nd interface discovery: {}", status);
if (discoverResults.newAddresses().size() > 0
&& discoverResults.newAddresses().contains(seenAs.inetAddress())) {
serverAddress = serverAddress.changeAddress(seenAs.inetAddress());
peer.peerBean().serverPeerAddress(serverAddress);
LOG.info("we were having the wrong interface, change it to: {}", serverAddress);
} else {
// now we know our internal IP, where we receive
// packets
final Ports ports = peer.connectionBean().channelServer().channelServerConfiguration().portsForwarding();
if (ports.isManualPort()) {
final PeerAddress serverAddressOrig = serverAddress;
serverAddress = serverAddress.changePorts(ports.tcpPort(),
ports.udpPort());
serverAddress = serverAddress.changeAddress(seenAs.inetAddress());
//manual port forwarding detected, set flag
serverAddress = serverAddress.changePortForwarding(true);
peer.peerBean().serverPeerAddress(serverAddress);
peer.peerBean().serverPeerAddress().internalPeerSocketAddress(serverAddressOrig.peerSocketAddress());
LOG.info("manual ports, change it to: {}", serverAddress);
} else {
// we need to find a relay, because there is a NAT in the way.
// we cannot use futureResponseTCP.responseMessage().recipient() as this may return also IPv6 addresses
futureDiscover