Search in sources :

Example 1 with NetworkAddressWithTime

use of neo.model.network.NetworkAddressWithTime in project neo-java by coranos.

the class LocalControllerNode method onAddr.

/**
 * handles the "addr" message.
 *
 * @param peer
 *            the peer taht sent the message.
 * @param message
 *            the message.
 */
private void onAddr(final RemoteNodeControllerRunnable peer, final Message message) {
    if (stopped) {
        return;
    }
    try {
        final AddrPayload addrPayload = (AddrPayload) message.payload;
        if (addrPayload == null) {
            return;
        }
        for (final NetworkAddressWithTime nawt : addrPayload.getAddressList()) {
            final byte[] addressBa = nawt.address.getBytesCopy();
            ArrayUtils.reverse(addressBa);
            final int port = nawt.port.toReverseBytesPositiveBigInteger().intValue();
            final InetAddress address = InetAddress.getByAddress(addressBa);
            if (LOG.isTraceEnabled()) {
                LOG.trace("address:{};port:{};", address, port);
            }
            final InetSocketAddress addressAndPort = new InetSocketAddress(address, port);
            final RemoteNodeData data = new RemoteNodeData(remoteNodeConfig);
            synchronized (RemoteNodeData.class) {
                data.setConnectionPhase(NodeConnectionPhaseEnum.UNKNOWN);
            }
            data.setTcpAddressAndPort(addressAndPort);
            addRemoteNodeDataToPool(data);
        }
        synchronized (peerDataSet) {
            if (LOG.isDebugEnabled()) {
                LOG.debug("{} onAddr response:{}, count {}, peerDataSet {}", peer.getData().getTcpAddressAndPortString(), message.command, addrPayload.getAddressList().size(), peerDataSet.size());
            }
        }
    } catch (final Exception e) {
        LOG.error("error in onAddr", e);
    }
}
Also used : RemoteNodeData(neo.network.model.RemoteNodeData) NetworkAddressWithTime(neo.model.network.NetworkAddressWithTime) InetSocketAddress(java.net.InetSocketAddress) AddrPayload(neo.model.network.AddrPayload) InetAddress(java.net.InetAddress) IOException(java.io.IOException)

Aggregations

IOException (java.io.IOException)1 InetAddress (java.net.InetAddress)1 InetSocketAddress (java.net.InetSocketAddress)1 AddrPayload (neo.model.network.AddrPayload)1 NetworkAddressWithTime (neo.model.network.NetworkAddressWithTime)1 RemoteNodeData (neo.network.model.RemoteNodeData)1