Hi folks,

Currently we have a problem with binding BAM data receiver to local
loopback address(localhost/127.0.0.1). In fact, databridge.receiver binds
to localhost without any issues. Problem arises when the databridge.agent
tries to connect to data receiver.

Given below is the code used by data publishers to connect to the receiver
(See
org.wso2.carbon.databridge.agent.thrift.internal.pool.client.general.ClientPoolFactory
)

TTransport receiverTransport = null;
            try {
                receiverTransport = new
TSocket(HostAddressFinder.findAddress(hostNameAndPort[0]),

 Integer.parseInt(hostNameAndPort[1]));
            } catch (SocketException ignored) {
                //already checked
            }

Problem with this approach is HostAddressFinder.findAddress returns a
different IP when hostNameAndPort[0] is set to "localhost". In other cases
it would work fine.

According to current HostAddressFinder.findAddress implementation, it
eleminates "localhost" or 127.0.0.1 and returns an address of a another
NIC. Since thrift receiver is not bound to that particular interface, an
error will be thrown at the client side.

public static String findAddress(String hostname) throws SocketException {
        if (hostname.trim().equals("localhost") ||
hostname.trim().equals("127.0.0.1") || hostname.trim().equals("::1")) {
            Enumeration<NetworkInterface> ifaces =
                    NetworkInterface.getNetworkInterfaces();
            while (ifaces.hasMoreElements()) {
                NetworkInterface iface = ifaces.nextElement();
                Enumeration<InetAddress> addresses =
iface.getInetAddresses();

                while (addresses.hasMoreElements()) {
                    InetAddress addr = addresses.nextElement();
                    if (addr instanceof Inet4Address &&
!addr.isLoopbackAddress()) {
                        return addr.getHostAddress();
                    }
                }
            }
            return "127.0.0.1";
        } else {
            return hostname;
        }
}


Why we purposely eliminate loopback address in the above method?

There'll be a probelm when a server  got multiple network interfaces and
customer wants to bind the receiver to loopback address. According to above
implementation, that is impossible. As a solution, is it safe to remove
this loopback address elimination and accept whatever the value passed as
the hostName?

Please mention your concerns.

Regards,

Dunith Dhanushka,
Senior Software Engineer - BAM,
WSO2 Inc,

Mobile - +94 71 8615744
Blog - dunithd.wordpress.com <http://blog.dunith.com>
Twitter - @dunithd <http://twitter.com/dunithd>
_______________________________________________
Dev mailing list
Dev@wso2.org
http://wso2.org/cgi-bin/mailman/listinfo/dev

Reply via email to