Exemplo n.º 1
0
        public ChunkInfo(Dictionary <string, byte[]> fields, byte[] data)
        {
            StartTime = BitConverter.ToInt64(fields["start_time"], 0);
            EndTime   = BitConverter.ToInt64(fields["end_time"], 0);
            ChunkPos  = BitConverter.ToInt64(fields["chunk_pos"], 0);
            Count     = BitConverter.ToInt32(fields["count"], 0);

            for (var i = 0; i < Count; i++)
            {
                var conn  = BitConverter.ToInt32(data, (i * 8));
                var count = BitConverter.ToInt32(data, (i * 8) + 4);
                MessageCount.Add(conn, count);
            }
        }
Exemplo n.º 2
0
        public override void WriteLine(string message)
        {
            // PREFIX
            if ((verbosity & VerbosityType.Warn) == VerbosityType.Warn && (message.StartsWith("warn:") || message.StartsWith("quirks:")))
            {
                if (message.StartsWith("quirks:"))
                {
                    writer.Write("\r\n!!!! QUIRKS MODE: !!!!\r\n");
                }
                else
                {
                    writer.Write("WARN:");
                }
            }
            else if ((verbosity & VerbosityType.Error) == VerbosityType.Error && message.StartsWith("error:"))
            {
                writer.Write("ERROR:");
            }
            else if ((verbosity & VerbosityType.Fatal) == VerbosityType.Fatal && message.StartsWith("fatal:"))
            {
                writer.Write("\r\n-- FATAL --\r\n\r\n");
            }

            // Message
            if ((verbosity & VerbosityType.Debug) == VerbosityType.Debug && message.StartsWith("debug:") ||
                (verbosity & VerbosityType.Warn) == VerbosityType.Warn && (message.StartsWith("warn:") || message.StartsWith("quirks:")) ||
                (verbosity & VerbosityType.Fatal) == VerbosityType.Fatal && message.StartsWith("fatal:") ||
                (verbosity & VerbosityType.Error) == VerbosityType.Error && message.StartsWith("error:") ||
                (verbosity & VerbosityType.Information) == VerbosityType.Information && message.StartsWith("information:"))
            {
                writer.WriteLine(message.Substring(message.IndexOf(":") + 2));
            }

            // Count the message

            string category = null;

            if (message.Contains(":"))
            {
                category = message.Substring(0, message.IndexOf(":"));
            }

            if (!MessageCount.ContainsKey(category ?? ""))
            {
                MessageCount.Add(category ?? "", 0);
            }
            MessageCount[category ?? ""]++;
        }
        private void Check(PeerConnection peer, FetchInventoryDataMessage message)
        {
            MessageTypes.MsgType type = message.InventoryMessageType;

            if (type == MessageTypes.MsgType.TX)
            {
                foreach (SHA256Hash hash in message.GetHashList())
                {
                    if (peer.GetInventorySpread(new Item(hash, InventoryType.Trx)) == null)
                    {
                        throw new P2pException(P2pException.ErrorType.BAD_MESSAGE, "not spread inventory : " + hash);
                    }
                }

                int fetch_count = peer.NodeStatistics.MessageStatistics.MineralInTrxFetchInvDataElement.GetCount(10);
                int max_count   = Manager.Instance.AdvanceService.TxCount.GetCount(60);
                if (fetch_count > max_count)
                {
                    throw new P2pException(
                              P2pException.ErrorType.BAD_MESSAGE, "maxCount: " + max_count + ", fetchCount: " + fetch_count);
                }
            }
            else
            {
                bool is_advance = true;
                foreach (SHA256Hash hash in message.GetHashList())
                {
                    if (peer.GetInventorySpread(new Item(hash, InventoryType.Block)) == null)
                    {
                        is_advance = false;
                        break;
                    }
                }

                if (is_advance)
                {
                    MessageCount out_advance_block = peer.NodeStatistics.MessageStatistics.MineralOutAdvBlock;
                    out_advance_block.Add(message.GetHashList().Count);

                    int out_block_count_1min = out_advance_block.GetCount(60);
                    int produced_block_2min  = 120000 / Parameter.ChainParameters.BLOCK_PRODUCED_INTERVAL;
                    if (out_block_count_1min > produced_block_2min)
                    {
                        throw new P2pException(
                                  P2pException.ErrorType.BAD_MESSAGE,
                                  "producedBlockIn2min: " + produced_block_2min + ", outBlockCountIn1min: " + out_block_count_1min);
                    }
                }
                else
                {
                    if (!peer.IsNeedSyncUs)
                    {
                        throw new P2pException(
                                  P2pException.ErrorType.BAD_MESSAGE, "no need sync");
                    }

                    foreach (SHA256Hash hash in message.GetHashList())
                    {
                        long block_num     = new BlockId(hash).Num;
                        long min_block_num = peer.LastSyncBlockId.Num - 2 * Parameter.NodeParameters.SYNC_FETCH_BATCH_NUM;

                        if (block_num < min_block_num)
                        {
                            throw new P2pException(
                                      P2pException.ErrorType.BAD_MESSAGE, "minBlockNum: " + min_block_num + ", blockNum: " + block_num);
                        }

                        if (peer.GetSyncBlockId(hash) != null)
                        {
                            throw new P2pException(
                                      P2pException.ErrorType.BAD_MESSAGE, new BlockId(hash).GetString() + " is exist");
                        }

                        peer.AddSyncBlockId(hash, Helper.CurrentTimeMillis());
                    }
                }
            }
        }