Search in sources :

Example 1 with ResBlocksHeaders

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);
}
Also used : A0BlockHeader(org.aion.zero.types.A0BlockHeader) ResBlocksHeaders(org.aion.zero.impl.sync.msg.ResBlocksHeaders)

Example 2 with ResBlocksHeaders

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);
}
Also used : A0BlockHeader(org.aion.zero.types.A0BlockHeader) ResBlocksHeaders(org.aion.zero.impl.sync.msg.ResBlocksHeaders) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Example 3 with ResBlocksHeaders

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);
}
Also used : BlockIdentifier(org.aion.mcf.types.BlockIdentifier) A0BlockHeader(org.aion.zero.types.A0BlockHeader) ResBlocksHeaders(org.aion.zero.impl.sync.msg.ResBlocksHeaders) ReqBlocksHeaders(org.aion.zero.impl.sync.msg.ReqBlocksHeaders)

Aggregations

ResBlocksHeaders (org.aion.zero.impl.sync.msg.ResBlocksHeaders)3 A0BlockHeader (org.aion.zero.types.A0BlockHeader)3 ArrayList (java.util.ArrayList)1 BlockIdentifier (org.aion.mcf.types.BlockIdentifier)1 ReqBlocksHeaders (org.aion.zero.impl.sync.msg.ReqBlocksHeaders)1 Test (org.junit.Test)1