Search in sources :

Example 1 with VersionEvent

use of io.nuls.network.message.entity.VersionEvent in project nuls by nuls-io.

the class VersionEventHandler method process.

@Override
public NetworkEventResult process(BaseEvent networkEvent, Node node) {
    VersionEvent event = (VersionEvent) networkEvent;
    if (event.getBestBlockHeight() < 0) {
        throw new NetworkMessageException(ErrorCode.NET_MESSAGE_ERROR);
    }
    node.setVersionMessage(event);
    checkVersion(event.getNulsVersion());
    if (!node.isHandShake()) {
        node.setStatus(Node.HANDSHAKE);
        node.setPort(event.getExternalPort());
        node.setLastTime(TimeService.currentTimeMillis());
        getNodeDao().saveChange(NodeTransferTool.toPojo(node));
    }
    return null;
}
Also used : VersionEvent(io.nuls.network.message.entity.VersionEvent) NetworkMessageException(io.nuls.network.exception.NetworkMessageException)

Example 2 with VersionEvent

use of io.nuls.network.message.entity.VersionEvent in project nuls by nuls-io.

the class GetVersionEventHandler method process.

@Override
public NetworkEventResult process(BaseEvent networkEvent, Node node) {
    GetVersionEvent event = (GetVersionEvent) networkEvent;
    // String key = event.getHeader().getEventType() + "-" + node.getId();
    // if (cacheService.existEvent(key)) {
    // Log.info("----------GetVersionEventHandler  cacheService  existEvent--------");
    // getNetworkService().removeNode(node.getId());
    // return null;
    // }
    // cacheService.putEvent(key, event, true);
    Block block = NulsContext.getInstance().getBestBlock();
    while (block == null) {
        try {
            Thread.sleep(1000);
            block = NulsContext.getInstance().getBestBlock();
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }
    VersionEvent replyMessage = new VersionEvent(getNetworkService().getNetworkParam().getExternalPort(), block.getHeader().getHeight(), block.getHeader().getHash().getDigestHex());
    node.setPort(event.getExternalPort());
    return new NetworkEventResult(true, replyMessage);
}
Also used : GetVersionEvent(io.nuls.network.message.entity.GetVersionEvent) VersionEvent(io.nuls.network.message.entity.VersionEvent) GetVersionEvent(io.nuls.network.message.entity.GetVersionEvent) Block(io.nuls.core.chain.entity.Block) NetworkEventResult(io.nuls.network.message.NetworkEventResult)

Aggregations

VersionEvent (io.nuls.network.message.entity.VersionEvent)2 Block (io.nuls.core.chain.entity.Block)1 NetworkMessageException (io.nuls.network.exception.NetworkMessageException)1 NetworkEventResult (io.nuls.network.message.NetworkEventResult)1 GetVersionEvent (io.nuls.network.message.entity.GetVersionEvent)1