Search in sources :

Example 26 with Node

use of io.nuls.network.model.Node in project nuls by nuls-io.

the class MessageBusServiceImplTest method sendToNode.

/**
 * send msg to one node
 */
@Test
public void sendToNode() {
    BlockMessage blockMessage = new BlockMessage();
    Node node = new Node("192.168.1.90", 8003, 1);
    boolean aysn = true;
    assertTrue(messageBusService.sendToNode(blockMessage, node, aysn).isSuccess());
}
Also used : BlockMessage(io.nuls.protocol.message.BlockMessage) Node(io.nuls.network.model.Node) Test(org.junit.Test)

Example 27 with Node

use of io.nuls.network.model.Node in project nuls by nuls-io.

the class MessageBusServiceImplTest method broadcastAndCache.

/**
 * 广播消息
 * broadcast to nodes except "excludeNode"
 */
@Test
public void broadcastAndCache() {
    BlockMessage blockMessage = new BlockMessage();
    Node node = new Node("192.168.1.90", 8003, 1);
    boolean aysn = true;
    Result<List<String>> result = messageBusService.broadcast(blockMessage, node, aysn, 100);
    assertTrue(result.isSuccess());
    assertTrue(result.getData().size() > 0);
}
Also used : BlockMessage(io.nuls.protocol.message.BlockMessage) Node(io.nuls.network.model.Node) List(java.util.List) Test(org.junit.Test)

Example 28 with Node

use of io.nuls.network.model.Node in project nuls by nuls-io.

the class BroadcastHandler method broadcastToHalfNode.

public BroadcastResult broadcastToHalfNode(BaseMessage msg, Node excludeNode, boolean asyn) {
    Collection<Node> nodes = nodeManager.getAvailableNodes();
    if (nodes.isEmpty()) {
        return new BroadcastResult(false, NetworkErrorCode.NET_BROADCAST_NODE_EMPTY);
    }
    List<Node> nodeList = new ArrayList<>();
    int i = 0;
    for (Node node : nodes) {
        i++;
        if (i % 2 == 1) {
            nodeList.add(node);
        }
    }
    return broadcastToList(nodeList, msg, excludeNode, asyn, 50);
}
Also used : BroadcastResult(io.nuls.network.model.BroadcastResult) Node(io.nuls.network.model.Node)

Example 29 with Node

use of io.nuls.network.model.Node in project nuls by nuls-io.

the class Bootstrap method sysStart.

private static void sysStart() throws Exception {
    do {
        MicroKernelBootstrap mk = MicroKernelBootstrap.getInstance();
        mk.init();
        mk.start();
        WalletVersionManager.start();
        initModules();
        String ip = NulsConfig.MODULES_CONFIG.getCfgValue(RpcConstant.CFG_RPC_SECTION, RpcConstant.CFG_RPC_SERVER_IP, RpcConstant.DEFAULT_IP);
        int port = NulsConfig.MODULES_CONFIG.getCfgValue(RpcConstant.CFG_RPC_SECTION, RpcConstant.CFG_RPC_SERVER_PORT, RpcConstant.DEFAULT_PORT);
        copyWebFiles();
        if (NULSParams.BOOTSTRAP.getRpcIp() != null) {
            ip = NULSParams.BOOTSTRAP.getRpcIp();
        }
        if (NULSParams.BOOTSTRAP.getRpcPort() != null) {
            port = NULSParams.BOOTSTRAP.getRpcPort();
        }
        RpcServerManager.getInstance().startServer(ip, port);
        LanguageService languageService = NulsContext.getServiceBean(LanguageService.class);
        String languageDB = (String) languageService.getLanguage().getData();
        String language = null == languageDB ? I18nUtils.getLanguage() : languageDB;
        I18nUtils.setLanguage(language);
        if (null == languageDB) {
            languageService.saveLanguage(language);
        }
    } while (false);
    // if isDaemon flag is true, don't launch the WebView
    boolean isDaemon = NulsConfig.MODULES_CONFIG.getCfgValue(RpcConstant.CFG_RPC_SECTION, RpcConstant.CFG_RPC_DAEMON, false);
    if (!isDaemon) {
        TaskManager.asynExecuteRunnable(new WebViewBootstrap());
    }
    int i = 0;
    Map<NulsDigestData, List<Node>> map = new HashMap<>();
    NulsContext context = NulsContext.getInstance();
    DownloadService downloadService = NulsContext.getServiceBean(DownloadService.class);
    while (true) {
        if (context.getStop() > 0) {
            if (context.getStop() == 2) {
                Runtime.getRuntime().addShutdownHook(new ShutdownHook());
            }
            System.exit(0);
        }
        if (NulsContext.mastUpGrade) {
            // 如果强制升级标志开启,停止网络连接
            ModuleManager.getInstance().stopModule(NetworkConstant.NETWORK_MODULE_ID);
            Log.error(">>>>>> The new protocol version has taken effect, the network connection has been disconnected,please upgrade immediately **********");
        }
        try {
            Thread.sleep(1000L);
        } catch (InterruptedException e) {
            Log.error(e);
        }
        if (i > 10) {
            i = 0;
            if (!downloadService.isDownloadSuccess().isSuccess() && CollectThread.getInstance().getStartHeight() > 0) {
                Log.info("collect-start:{},request-start:{},BlockQueueSize:{}", CollectThread.getInstance().getStartHeight(), CollectThread.getInstance().getRequestStartHeight(), BlockQueueProvider.getInstance().size());
            }
            Block bestBlock = NulsContext.getInstance().getBestBlock();
            Collection<Node> nodes = NulsContext.getServiceBean(NetworkService.class).getAvailableNodes();
            Log.info("bestHeight:" + bestBlock.getHeader().getHeight() + " , txCount : " + bestBlock.getHeader().getTxCount() + " , tx memory pool count : " + TxMemoryPool.getInstance().size() + " - " + TxMemoryPool.getInstance().getOrphanPoolSize() + " , hash : " + bestBlock.getHeader().getHash() + ",nodeCount:" + nodes.size());
            map.clear();
            for (Node node : nodes) {
                List<Node> ips = map.get(node.getBestBlockHash());
                if (null == ips) {
                    ips = new ArrayList<>();
                    map.put(node.getBestBlockHash(), ips);
                }
                ips.add(node);
            }
            for (NulsDigestData key : map.keySet()) {
                if (key == null)
                    continue;
                List<Node> nodeList = map.get(key);
                long height = nodeList.get(0).getBestBlockHeight();
                StringBuilder ids = new StringBuilder();
                for (Node node : nodeList) {
                    ids.append("," + node.getId());
                }
                Log.info("height:" + height + ",count:" + nodeList.size() + ", hash:" + key.getDigestHex() + ids);
            }
        } else {
            i++;
        }
    }
}
Also used : ShutdownHook(io.nuls.client.rpc.resources.thread.ShutdownHook) Node(io.nuls.network.model.Node) DownloadService(io.nuls.protocol.service.DownloadService) MicroKernelBootstrap(io.nuls.kernel.MicroKernelBootstrap) WebViewBootstrap(io.nuls.client.web.view.WebViewBootstrap) LanguageService(io.nuls.client.storage.LanguageService) NulsContext(io.nuls.kernel.context.NulsContext) NulsDigestData(io.nuls.kernel.model.NulsDigestData) Block(io.nuls.kernel.model.Block) NetworkService(io.nuls.network.service.NetworkService)

Example 30 with Node

use of io.nuls.network.model.Node in project nuls by nuls-io.

the class ClientChannelHandler method channelRegistered.

@Override
public void channelRegistered(ChannelHandlerContext ctx) throws Exception {
    super.channelRegistered(ctx);
    Attribute<Node> nodeAttribute = ctx.channel().attr(NodeAttributeKey.NODE_KEY);
    Node node = nodeAttribute.get();
    if (node != null && node.getRegisterListener() != null) {
        node.getRegisterListener().action();
    }
}
Also used : Node(io.nuls.network.model.Node)

Aggregations

Node (io.nuls.network.model.Node)48 Result (io.nuls.kernel.model.Result)4 NodesContainer (io.nuls.network.netty.container.NodesContainer)4 Block (io.nuls.kernel.model.Block)3 NulsDigestData (io.nuls.kernel.model.NulsDigestData)3 RpcClientResult (io.nuls.kernel.model.RpcClientResult)3 BroadcastResult (io.nuls.network.model.BroadcastResult)3 BlockMessage (io.nuls.protocol.message.BlockMessage)3 ApiOperation (io.swagger.annotations.ApiOperation)3 ApiResponses (io.swagger.annotations.ApiResponses)3 IOException (java.io.IOException)3 GET (javax.ws.rs.GET)3 Path (javax.ws.rs.Path)3 Produces (javax.ws.rs.Produces)3 Test (org.junit.Test)3 ByteBuf (io.netty.buffer.ByteBuf)2 SocketChannel (io.netty.channel.socket.SocketChannel)2 TooLongFrameException (io.netty.handler.codec.TooLongFrameException)2 NodeMessageBody (io.nuls.network.protocol.message.NodeMessageBody)2 NodesMessage (io.nuls.network.protocol.message.NodesMessage)2