Search in sources :

Example 11 with RemoteNodeData

use of neo.network.model.RemoteNodeData 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

RemoteNodeData (neo.network.model.RemoteNodeData)11 ArrayList (java.util.ArrayList)4 InetSocketAddress (java.net.InetSocketAddress)3 IOException (java.io.IOException)2 InetAddress (java.net.InetAddress)2 LocalNodeData (neo.network.model.LocalNodeData)2 JSONObject (org.json.JSONObject)2 EnumMap (java.util.EnumMap)1 TreeMap (java.util.TreeMap)1 AddrPayload (neo.model.network.AddrPayload)1 NetworkAddressWithTime (neo.model.network.NetworkAddressWithTime)1 VersionPayload (neo.model.network.VersionPayload)1 RemoteNodeControllerRunnable (neo.network.RemoteNodeControllerRunnable)1 NodeConnectionPhaseEnum (neo.network.model.NodeConnectionPhaseEnum)1 JSONArray (org.json.JSONArray)1 Test (org.junit.Test)1