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);
}
}
Aggregations