Exemple #1
0
        private void writeHandshake(P2pMessage message)
        {
            CORE_SYNC_DATA coreSync = new CORE_SYNC_DATA();

            LevinProtocol.decode(message.data, coreSync);

            if (m_context.isIncoming())
            {
                // response
                COMMAND_HANDSHAKE.response res = new COMMAND_HANDSHAKE.response();
//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: res.node_data = m_node.getNodeData();
                res.node_data.CopyFrom(m_node.getNodeData());
//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: res.payload_data = coreSync;
                res.payload_data.CopyFrom(coreSync);
                res.local_peerlist = new LinkedList <PeerlistEntry>(m_node.getLocalPeerList());
                m_context.writeMessage(makeReply(COMMAND_HANDSHAKE.ID, LevinProtocol.encode(res), GlobalMembers.LEVIN_PROTOCOL_RETCODE_SUCCESS));
                m_node.tryPing(m_context);
            }
            else
            {
                // request
                COMMAND_HANDSHAKE.request req = new COMMAND_HANDSHAKE.request();
//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: req.node_data = m_node.getNodeData();
                req.node_data.CopyFrom(m_node.getNodeData());
//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: req.payload_data = coreSync;
                req.payload_data.CopyFrom(coreSync);
                m_context.writeMessage(makeRequest(COMMAND_HANDSHAKE.ID, LevinProtocol.encode(req)));
            }
        }
Exemple #2
0
        public bool get_payload_sync_data(CORE_SYNC_DATA hshd)
        {
//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: hshd.top_id = m_core.getTopBlockHash();
            hshd.top_id.CopyFrom(m_core.GetTopBlockHash());
//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: hshd.current_height = m_core.getTopBlockIndex() + 1;
            hshd.current_height.CopyFrom(m_core.GetTopBlockIndex() + 1);
            return(true);
        }
Exemple #3
0
//C++ TO C# CONVERTER TODO TASK: 'rvalue references' have no equivalent in C#:
        public P2pContext(Dispatcher dispatcher, TcpConnection && conn, bool isIncoming, NetworkAddress remoteAddress, std::chrono.nanoseconds timedSyncInterval, CORE_SYNC_DATA timedSyncData)
        {
            this.incoming      = isIncoming;
            this.remoteAddress = new NetworkAddress(remoteAddress);
            this.dispatcher    = dispatcher;
            this.contextGroup  = dispatcher;
            this.timeStarted   = Clock.now();
//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: this.timedSyncInterval = timedSyncInterval;
            this.timedSyncInterval.CopyFrom(timedSyncInterval);
            this.timedSyncData     = new CryptoNote.CORE_SYNC_DATA(timedSyncData);
            this.timedSyncTimer    = dispatcher;
            this.timedSyncFinished = dispatcher;
            this.connection        = new System.TcpConnection(std::move(conn));
            this.writeEvent        = dispatcher;
            this.readEvent         = dispatcher;
            writeEvent.set();
            readEvent.set();
//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: lastReadTime = timeStarted;
            lastReadTime.CopyFrom(timeStarted); // use current time
            contextGroup.spawn(std::bind(this.timedSyncLoop, this));
        }
Exemple #4
0
        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);
        }