use of org.aion.zero.impl.sync.msg.ResBlocksHeaders in project aion by aionnetwork.
the class ResBlocksHeadersHandler method receive.
@Override
public void receive(int _nodeIdHashcode, String _displayId, final byte[] _msgBytes) {
if (_msgBytes == null || _msgBytes.length == 0)
return;
ResBlocksHeaders resHeaders = ResBlocksHeaders.decode(_msgBytes);
if (resHeaders != null) {
List<A0BlockHeader> headers = resHeaders.getHeaders();
if (headers != null && headers.size() > 0) {
this.log.debug("<res-headers from-number={} size={} node={}>", headers.get(0).getNumber(), headers.size(), _displayId);
this.syncMgr.validateAndAddHeaders(_nodeIdHashcode, _displayId, headers);
} else {
this.log.error("<res-headers empty-headers node={} >", _displayId);
}
} else
this.log.error("<res-headers decode-msg msg-bytes={} node={} >", _msgBytes.length, _displayId);
}
use of org.aion.zero.impl.sync.msg.ResBlocksHeaders in project aion by aionnetwork.
the class ResBlocksHeadersTest method testHeaders.
@Test
public void testHeaders() {
int m = 192;
List<A0BlockHeader> bhs1 = new ArrayList<A0BlockHeader>();
for (int i = 0; i < m; i++) {
bhs1.add(bh1);
}
ResBlocksHeaders rbhs1 = new ResBlocksHeaders(bhs1);
byte[] rbhsBytes = rbhs1.encode();
ResBlocksHeaders rbhs2 = ResBlocksHeaders.decode(rbhsBytes);
List<A0BlockHeader> bhs2 = rbhs2.getHeaders();
assertThat(bhs2.size()).isEqualTo(m);
}
use of org.aion.zero.impl.sync.msg.ResBlocksHeaders in project aion by aionnetwork.
the class ReqBlocksHeadersHandler method receive.
@Override
public void receive(int _nodeIdHashcode, String _displayId, final byte[] _msgBytes) {
ReqBlocksHeaders reqHeaders = ReqBlocksHeaders.decode(_msgBytes);
if (reqHeaders != null) {
long fromBlock = reqHeaders.getFromBlock();
int take = reqHeaders.getTake();
this.log.debug("<req-headers from-number={} size={} node={}>", fromBlock, take, _displayId);
List<A0BlockHeader> headers = this.blockchain.getListOfHeadersStartFrom(new BlockIdentifier(null, fromBlock), 0, Math.min(take, max), false);
ResBlocksHeaders rbhs = new ResBlocksHeaders(headers);
this.p2pMgr.send(_nodeIdHashcode, rbhs);
} else
this.log.error("<req-headers decode-msg msg-bytes={} node={}>", _msgBytes == null ? 0 : _msgBytes.length, _nodeIdHashcode);
}
Aggregations