Example #1
0
        // IStreamSerializable
        public override void save(std::ostream os)
        {
            m_sync.save(os);

            StdOutputStream stream = new StdOutputStream(os);

            CryptoNote.BinaryOutputStreamSerializer s = new CryptoNote.BinaryOutputStreamSerializer(stream);
//C++ TO C# CONVERTER TODO TASK: There is no equivalent to 'const_cast' in C#:
            s.functorMethod(const_cast <uint&>(GlobalMembers.TRANSFERS_STORAGE_ARCHIVE_VERSION), "version");

            ulong subscriptionCount = m_consumers.Count;

            s.beginArray(ref subscriptionCount, "consumers");

            foreach (var consumer in m_consumers)
            {
                s.beginObject("");
//C++ TO C# CONVERTER TODO TASK: There is no equivalent to 'const_cast' in C#:
                s.functorMethod(const_cast <PublicKey&>(consumer.first), "view_key");

                std::stringstream consumerState = new std::stringstream();
                // synchronization state
                m_sync.getConsumerState(consumer.second.get()).save(consumerState);

                string blob = consumerState.str();
                s.functorMethod(blob, "state");

                List <AccountPublicAddress> subscriptions = new List <AccountPublicAddress>();
                consumer.second.getSubscriptions(subscriptions);
                ulong subCount = subscriptions.Count;

                s.beginArray(ref subCount, "subscriptions");

                foreach (var addr in subscriptions)
                {
                    var sub = consumer.second.getSubscription(addr);
                    if (sub != null)
                    {
                        s.beginObject("");

                        std::stringstream subState = new std::stringstream();
                        Debug.Assert(sub);
                        sub.getContainer().save(subState);
                        // store data block
                        string blob = subState.str();
                        s.functorMethod(addr, "address");
                        s.functorMethod(blob, "state");

                        s.EndObject();
                    }
                }

                s.EndArray();
                s.EndObject();
            }
        }
Example #2
0
        private void loadTransfersSynchronizer(CryptoNote.ISerializer serializer)
        {
            string transfersSynchronizerData;

            serializer.functorMethod(transfersSynchronizerData, "transfersSynchronizer");

            std::stringstream stream = new std::stringstream(transfersSynchronizerData);

            m_synchronizer.load(stream);
        }
Example #3
0
        private void saveTransfersSynchronizer(CryptoNote.ISerializer serializer)
        {
            std::stringstream stream = new std::stringstream();

            m_synchronizer.save(stream);
            stream.flush();

            string transfersSynchronizerData = stream.str();

            serializer.functorMethod(transfersSynchronizerData, "transfersSynchronizer");
        }
Example #4
0
        public void log_connections()
        {
            std::stringstream ss = new std::stringstream();

            ss << std::setw(25) << std::left << "Remote Host" << std::setw(20) << "Peer ID" << std::setw(25) << "Recv/Sent (inactive,sec)" << std::setw(25) << "State" << std::setw(20) << "Lifetime(seconds)" << std::endl;

            m_p2p.for_each_connection((CryptoNoteConnectionContext cntxt, ulong peer_id) =>
            {
                ss << std::setw(25) << std::left << (string)(cntxt.m_is_income ? "[INCOMING]" : "[OUTGOING]") + Common.ipAddressToString(cntxt.m_remote_ip) + ":" + Convert.ToString(cntxt.m_remote_port) << std::setw(20) << std::hex << peer_id << std::setw(25) << get_protocol_state_string(cntxt.m_state) << std::setw(20) << Convert.ToString(time(null) - cntxt.m_started) << std::endl;
            });
            logger.functorMethod(INFO) << "Connections: " << std::endl << ss.str();
        }
    //--------------------------------------------------------------------------------
    private string get_commands_str()
    {
        std::stringstream ss = new std::stringstream();

        ss << CryptoNote.CRYPTONOTE_NAME << " v" << PROJECT_VERSION_LONG << std::endl;
        ss << "Commands: " << std::endl;
        string usage = m_consoleHandler.getUsage();

        boost::replace_all(usage, "\n", "\n  ");
        usage = usage.Insert(0, "  ");
        ss << usage << std::endl;
        return(ss.str());
    }
Example #6
0
        /* This method is used by WalletService to determine if the mixin amount is correct
         * for the current block height */
        public static Tuple <bool, string, std::error_code> validate(uint mixin, uint height)
        {
            var(minMixin, maxMixin) = getMixinAllowableRange(height);

            std::stringstream str = new std::stringstream();

            if (mixin < minMixin)
            {
                str << "Mixin of " << (int)mixin << " under minimum mixin threshold of " << minMixin;
                return(new Tuple <bool, string, std::error_code>(false, str.str(), GlobalMembers.make_error_code(CryptoNote.error.MIXIN_BELOW_THRESHOLD)));
            }
            else if (mixin > maxMixin)
            {
                str << "Mixin of " << (int)mixin << " above maximum mixin threshold of " << maxMixin;
                return(new Tuple <bool, string, std::error_code>(false, str.str(), GlobalMembers.make_error_code(CryptoNote.error.MIXIN_ABOVE_THRESHOLD)));
            }

            return(new Tuple <bool, string, std::error_code>(true, string(), std::error_code()));
        }
Example #7
0
        /* This method is commonly used by the node to determine if the transaction has
         * the correct mixin (anonymity) as defined by the current rules */
        public static Tuple <bool, string> validate(CachedTransaction transaction, ulong minMixin, ulong maxMixin)
        {
            ulong ringSize = 1;

            var tx = createTransaction(transaction.getTransaction());

            for (uint i = 0; i < tx.getInputCount(); ++i)
            {
                if (tx.getInputType(i) != TransactionTypes.InputType.Key)
                {
                    continue;
                }

                KeyInput input = new KeyInput();
                tx.getInput(i, input);
                ulong currentRingSize = input.outputIndexes.Count;
                if (currentRingSize > ringSize)
                {
                    ringSize = currentRingSize;
                }
            }

            /* Ring size = mixin + 1 - your transaction plus the others you mix with */
            ulong mixin = ringSize - 1;

            std::stringstream str = new std::stringstream();

            if (mixin > maxMixin)
            {
                str << "Transaction " << transaction.getTransactionHash() << " is not valid. Reason: transaction mixin is too large (" << (int)mixin << "). Maximum mixin allowed is " << (int)maxMixin;

                return(new Tuple <bool, string>(false, str.str()));
            }
            else if (mixin < minMixin)
            {
                str << "Transaction " << transaction.getTransactionHash() << " is not valid. Reason: transaction mixin is too small (" << (int)mixin << "). Minimum mixin allowed is " << (int)minMixin;

                return(new Tuple <bool, string>(false, str.str()));
            }

            return(new Tuple <bool, string>(true, string()));
        }
Example #8
0
//C++ TO C# CONVERTER WARNING: 'const' methods are not available in C#:
//ORIGINAL LINE: string getUsage() const
        public string getUsage()
        {
            if (m_handlers.Count == 0)
            {
                return(string());
            }

            std::stringstream ss = new std::stringstream();

            ulong maxlen = std::max_element(m_handlers.GetEnumerator(), m_handlers.end(), (CommandHandlersMap.const_reference a, CommandHandlersMap.const_reference b) =>
            {
                return(a.first.size() < b.first.size());
            }).first.size();

            foreach (var x in m_handlers)
            {
                ss << std::left << std::setw(maxlen + 3) << x.Item1 << x.Item2.second << std::endl;
            }

            return(ss.str());
        }
Example #9
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);
        }