public static bool broadcastNewBlock(Block b, RemoteEndpoint skipEndpoint = null, RemoteEndpoint endpoint = null, bool force_broadcast = false) { if (!Node.isMasterNode()) { return(true); } if (endpoint != null) { if (endpoint.isConnected()) { endpoint.sendData(ProtocolMessageCode.blockData, b.getBytes(false), BitConverter.GetBytes(b.blockNum)); return(true); } return(false); } else { if (force_broadcast) { return(CoreProtocolMessage.broadcastProtocolMessage(new char[] { 'M', 'H' }, ProtocolMessageCode.blockData, b.getBytes(false), BitConverter.GetBytes(b.blockNum), skipEndpoint)); } else { return(CoreProtocolMessage.addToInventory(new char[] { 'M', 'H' }, new InventoryItemBlock(b.blockChecksum, b.blockNum), skipEndpoint, ProtocolMessageCode.blockData, b.getBytes(false), BitConverter.GetBytes(b.blockNum))); } } }
// Handle timer routines static public void mainLoop() { byte[] primaryAddress = IxianHandler.getWalletStorage().getPrimaryAddress(); if (primaryAddress == null) { return; } byte[] getBalanceBytes; using (MemoryStream mw = new MemoryStream()) { using (BinaryWriter writer = new BinaryWriter(mw)) { writer.WriteIxiVarInt(primaryAddress.Length); writer.Write(primaryAddress); } getBalanceBytes = mw.ToArray(); } while (running) { try { // Update the friendlist FriendList.Update(); // Request initial wallet balance if (balance.blockHeight == 0 || balance.lastUpdate + 300 < Clock.getTimestamp()) { CoreProtocolMessage.broadcastProtocolMessage(new char[] { 'M', 'H' }, ProtocolMessageCode.getBalance2, getBalanceBytes, null); } if (Config.enablePushNotifications) { OfflinePushMessages.fetchPushMessages(); } // Cleanup the presence list // TODO: optimize this by using a different thread perhaps PresenceList.performCleanup(); } catch (Exception e) { Logging.error("Exception occured in mainLoop: " + e); } Thread.Sleep(2500); } }
// Broadcast the current block height. Called after accepting a new block once the node is fully synced // Returns false when no RemoteEndpoints found to send the message to public static bool broadcastBlockHeight(ulong blockNum, byte[] checksum) { using (MemoryStream mw = new MemoryStream()) { using (BinaryWriter writerw = new BinaryWriter(mw)) { Block tmp_block = IxianHandler.getLastBlock(); // Send the block height writerw.Write(blockNum); // Send the block checksum for this balance writerw.Write(checksum.Length); writerw.Write(checksum); return(CoreProtocolMessage.broadcastProtocolMessage(new char[] { 'C' }, ProtocolMessageCode.blockHeight, mw.ToArray(), null, null)); } } }