public void onConnectionClosed(CryptoNoteConnectionContext context) { bool updated = false; lock (m_observedHeightMutex) { ulong prevHeight = m_observedHeight; recalculateMaxObservedHeight(context); if (prevHeight != m_observedHeight) { updated = true; } } if (updated) { logger.functorMethod(TRACE) << "Observed height updated: " << m_observedHeight; m_observerManager.notify(ICryptoNoteProtocolObserver.lastKnownBlockHeightUpdated, m_observedHeight); } if (context.m_state != CryptoNoteConnectionContext.state_befor_handshake) { m_peersCount--; m_observerManager.notify(ICryptoNoteProtocolObserver.peerCountUpdated, m_peersCount.load()); } }
public void requestMissingPoolTransactions(CryptoNoteConnectionContext context) { if (context.version < 1) { return; } NOTIFY_REQUEST_TX_POOL.request notification = new NOTIFY_REQUEST_TX_POOL.request(); notification.txs = m_core.GetPoolTransactionHashes(); bool ok = GlobalMembers.post_notify <NOTIFY_REQUEST_TX_POOL>(m_p2p, notification, context); if (!ok) { logger.functorMethod(Logging.Level.WARNING, Logging.BRIGHT_YELLOW) << "Failed to post notification NOTIFY_REQUEST_TX_POOL to " << context.m_connection_id; } }
public bool start_sync(CryptoNoteConnectionContext context) { logger.functorMethod(Logging.Level.TRACE) << context << "Starting synchronization"; if (context.m_state == CryptoNoteConnectionContext.state_synchronizing) { Debug.Assert(context.m_needed_objects.Count == 0); Debug.Assert(context.m_requested_objects.Count == 0); NOTIFY_REQUEST_CHAIN.request r = boost::value_initialized <NOTIFY_REQUEST_CHAIN.request>(); r.block_ids = new List <Crypto.Hash>(m_core.BuildSparseChain()); logger.functorMethod(Logging.Level.TRACE) << context << "-->>NOTIFY_REQUEST_CHAIN: m_block_ids.size()=" << r.block_ids.Count; GlobalMembers.post_notify <NOTIFY_REQUEST_CHAIN>(m_p2p, r, context); } return(true); }
//----------------- commands handlers ---------------------------------------------- private int handle_notify_new_block(int command, NOTIFY_NEW_BLOCK.request arg, CryptoNoteConnectionContext context) { logger.functorMethod(Logging.Level.TRACE) << context << "NOTIFY_NEW_BLOCK (hop " << arg.hop << ")"; updateObservedHeight(arg.current_blockchain_height, context); context.m_remote_blockchain_height = arg.current_blockchain_height; if (context.m_state != CryptoNoteConnectionContext.state_normal) { return(1); } var result = m_core.AddBlock(new RawBlock({ arg.b.block, arg.b.transactions }));
public bool process_payload_sync_data(CORE_SYNC_DATA hshd, CryptoNoteConnectionContext context, bool is_initial) { if (context.m_state == CryptoNoteConnectionContext.state_befor_handshake && !is_initial) { return(true); } if (context.m_state == CryptoNoteConnectionContext.state_synchronizing) { } else if (m_core.HasBlock(hshd.top_id)) { if (is_initial) { on_connection_synchronized(); context.m_state = CryptoNoteConnectionContext.state_pool_sync_required; } else { context.m_state = CryptoNoteConnectionContext.state_normal; } } else { ulong currentHeight = get_current_blockchain_height(); ulong remoteHeight = hshd.current_height; /* Find the difference between the remote and the local height */ long diff = (long)remoteHeight - (long)currentHeight; /* Find out how many days behind/ahead we are from the remote height */ ulong days = Math.Abs(diff) / (24 * 60 * 60 / m_currency.difficultyTarget()); std::stringstream ss = new std::stringstream(); ss << "Your " << CRYPTONOTE_NAME << " node is syncing with the network "; /* We're behind the remote node */ if (diff >= 0) { ss << "(" << Common.get_sync_percentage(currentHeight, remoteHeight) << "% complete) "; ss << "You are " << diff << " blocks (" << days << " days) behind "; } /* We're ahead of the remote node, no need to print percentages */ else { ss << "You are " << Math.Abs(diff) << " blocks (" << days << " days) ahead "; } ss << "the current peer you're connected to. Slow and steady wins the race! "; var logLevel = Logging.Level.TRACE; /* Log at different levels depending upon if we're ahead, behind, and if it's * a newly formed connection */ if (diff >= 0) { if (is_initial) { logLevel = Logging.Level.INFO; } else { logLevel = Logging.Level.DEBUGGING; } } logger.functorMethod(logLevel, Logging.BRIGHT_GREEN) << context << ss.str(); logger.functorMethod(Logging.Level.DEBUGGING) << "Remote top block height: " << hshd.current_height << ", id: " << hshd.top_id; //let the socket to send response to handshake, but request callback, to let send request data after response logger.functorMethod(Logging.Level.TRACE) << context << "requesting synchronization"; context.m_state = CryptoNoteConnectionContext.state_sync_required; } updateObservedHeight(new uint(hshd.current_height), context); //C++ TO C# CONVERTER TODO TASK: The following line was determined to be a copy assignment (rather than a reference assignment) - this should be verified and a 'CopyFrom' method should be created: //ORIGINAL LINE: context.m_remote_blockchain_height = hshd.current_height; context.m_remote_blockchain_height.CopyFrom(hshd.current_height); if (is_initial) { m_peersCount++; m_observerManager.notify(ICryptoNoteProtocolObserver.peerCountUpdated, m_peersCount.load()); } return(true); }
public void onConnectionOpened(CryptoNoteConnectionContext context) { }