Ejemplo n.º 1
0
            internal TestStore(bool useReadCache, ReadFlags readFlags, bool flush)
            {
                this.testDir = TestUtils.MethodTestDir;
                TestUtils.DeleteDirectory(this.testDir, wait: true);
                this.logDevice = Devices.CreateLogDevice($"{testDir}/hlog.log");
                this.flush     = flush;

                var logSettings = new LogSettings
                {
                    LogDevice         = logDevice,
                    ObjectLogDevice   = new NullDevice(),
                    ReadCacheSettings = useReadCache ? new ReadCacheSettings() : null,
                    ReadFlags         = readFlags,
                    // Use small-footprint values
                    PageSizeBits   = 12, // (4K pages)
                    MemorySizeBits = 20  // (1M memory for main log)
                };

                this.fkv = new FasterKV <Key, Value>(
                    size: 1L << 20,
                        logSettings: logSettings,
                        checkpointSettings: new CheckpointSettings {
                    CheckpointDir = $"{this.testDir}/CheckpointDir"
                        },
                        serializerSettings: null,
                        comparer: new Key.Comparer(),
                        disableLocking: true
                    );
            }
Ejemplo n.º 2
0
 void ProcessQuests(D2GameInfo gameInfo)
 {
     gameQuests = new List <QuestCollection>();
     if (ReadFlags.HasFlag(DataReaderEnableFlags.QuestBuffers))
     {
         gameQuests = ReadQuests(gameInfo);
     }
 }
Ejemplo n.º 3
0
        public Typeface Read(Stream stream, int streamStartOffset = 0, ReadFlags readFlags = ReadFlags.Full)
        {
            Typeface typeface = new Typeface();

            if (Read(typeface, null, stream, streamStartOffset, readFlags))
            {
                return(typeface);
            }
            return(null);
        }
Ejemplo n.º 4
0
        public Typeface Read(Stream stream, int streamStartOffset = 0, ReadFlags readFlags = ReadFlags.Full)
        {
            //bool little = BitConverter.IsLittleEndian;

            if (streamStartOffset > 0)
            {
                //eg. for ttc
                stream.Seek(streamStartOffset, SeekOrigin.Begin);
            }
            using (var input = new ByteOrderSwappingBinaryReader(stream))
            {
                ushort majorVersion = input.ReadUInt16();
                ushort minorVersion = input.ReadUInt16();

                if (KnownFontFiles.IsTtcf(majorVersion, minorVersion))
                {
                    //this font stream is 'The Font Collection'
                    //To read content of ttc=> one must specific the offset
                    //so use read preview first=> you will know that what are inside the ttc.

                    return(null);
                }
                else if (KnownFontFiles.IsWoff(majorVersion, minorVersion))
                {
                    //check if we enable woff or not
                    WebFont.WoffReader woffReader = new WebFont.WoffReader();
                    input.BaseStream.Position = 0;
                    return(woffReader.Read(input));
                }
                else if (KnownFontFiles.IsWoff2(majorVersion, minorVersion))
                {
                    //check if we enable woff2 or not
                    WebFont.Woff2Reader woffReader = new WebFont.Woff2Reader();
                    input.BaseStream.Position = 0;
                    return(woffReader.Read(input));
                }
                //-----------------------------------------------------------------


                ushort tableCount    = input.ReadUInt16();
                ushort searchRange   = input.ReadUInt16();
                ushort entrySelector = input.ReadUInt16();
                ushort rangeShift    = input.ReadUInt16();
                //------------------------------------------------------------------
                var tables = new TableEntryCollection();
                for (int i = 0; i < tableCount; i++)
                {
                    tables.AddEntry(new UnreadTableEntry(ReadTableHeader(input)));
                }
                //------------------------------------------------------------------
                return(ReadTableEntryCollection(tables, input));
            }
        }
Ejemplo n.º 5
0
 public Int64 Get(Txn txn, Int32 delta, ReadFlags flags)
 {
     if (txn != null)
     {
         lock (txn.rscLock) {
             DB_TXN *txp = txn.CheckDisposed();
             return(Get(txp, delta, flags));
         }
     }
     else
     {
         return(Get((DB_TXN *)null, delta, flags));
     }
 }
Ejemplo n.º 6
0
            internal static ushort GetOperationFlags(ReadFlags readFlags, bool noKey = false)
            {
                Debug.Assert((ushort)ReadFlags.DisableReadCacheUpdates >> 1 == kDisableReadCacheUpdates);
                Debug.Assert((ushort)ReadFlags.DisableReadCacheReads >> 1 == kDisableReadCacheReads);
                Debug.Assert((ushort)ReadFlags.CopyReadsToTail >> 1 == kCopyReadsToTail);
                Debug.Assert((ushort)ReadFlags.CopyFromDeviceOnly >> 1 == kCopyFromDeviceOnly);
                ushort flags = (ushort)((int)(readFlags & (ReadFlags.DisableReadCacheUpdates | ReadFlags.DisableReadCacheReads | ReadFlags.CopyReadsToTail | ReadFlags.CopyFromDeviceOnly)) >> 1);

                if (noKey)
                {
                    flags |= kNoKey;
                }
                return(flags);
            }
Ejemplo n.º 7
0
            internal static byte GetOperationFlags(ReadFlags readFlags, bool noKey = false)
            {
                Debug.Assert((byte)ReadFlags.SkipReadCache == kSkipReadCache);
                byte flags = (byte)(readFlags & ReadFlags.SkipReadCache);

                if (noKey)
                {
                    flags |= kNoKey;
                }

                // This is always set true for the Read overloads (Reads by address) that call this method.
                flags |= kSkipCopyReadsToTail;
                return(flags);
            }
Ejemplo n.º 8
0
        Int64 Get(DB_TXN *txp, Int32 delta, ReadFlags flags)
        {
            Int64    value;
            DbRetVal ret;

            lock (rscLock) {
                DB_SEQUENCE *seqp = CheckDisposed();
                if (SeqGet == null)
                {
                    throw new BdbException("Sequence must be open.");
                }
                ret = SeqGet(seqp, txp, delta, out value, unchecked ((UInt32)flags));
            }
            Util.CheckRetVal(ret);
            return(value);
        }
Ejemplo n.º 9
0
 public ReadRequest(byte[] buffer, int offset) : base(buffer, offset)
 {
     StructureSize         = LittleEndianConverter.ToUInt16(buffer, offset + SMB2Header.Length + 0);
     Padding               = ByteReader.ReadByte(buffer, offset + SMB2Header.Length + 2);
     Flags                 = (ReadFlags)ByteReader.ReadByte(buffer, offset + SMB2Header.Length + 3);
     ReadLength            = LittleEndianConverter.ToUInt32(buffer, offset + SMB2Header.Length + 4);
     Offset                = LittleEndianConverter.ToUInt64(buffer, offset + SMB2Header.Length + 8);
     FileId                = new FileID(buffer, offset + SMB2Header.Length + 16);
     MinimumCount          = LittleEndianConverter.ToUInt32(buffer, offset + SMB2Header.Length + 32);
     Channel               = LittleEndianConverter.ToUInt32(buffer, offset + SMB2Header.Length + 36);
     RemainingBytes        = LittleEndianConverter.ToUInt32(buffer, offset + SMB2Header.Length + 40);
     ReadChannelInfoOffset = LittleEndianConverter.ToUInt16(buffer, offset + SMB2Header.Length + 44);
     ReadChannelInfoLength = LittleEndianConverter.ToUInt16(buffer, offset + SMB2Header.Length + 46);
     if (ReadChannelInfoLength > 0)
     {
         ReadChannelInfo = ByteReader.ReadBytes(buffer, offset + ReadChannelInfoOffset, ReadChannelInfoLength);
     }
 }
Ejemplo n.º 10
0
            /// <summary>
            /// Resume (continue) prior client session with FASTER, used during
            /// recovery from failure.
            /// </summary>
            /// <param name="sessionName">Name of previous session to resume</param>
            /// <param name="commitPoint">Prior commit point of durability for session</param>
            /// <param name="sessionVariableLengthStructSettings">Session-specific variable-length struct settings</param>
            /// <param name="readFlags">ReadFlags for this session; override those specified at FasterKV level, and may be overridden on individual Read operations</param>
            /// <returns>Session instance</returns>
            public ClientSession <Key, Value, Input, Output, Context, Functions> ResumeSession <Functions>(string sessionName, out CommitPoint commitPoint,
                                                                                                           SessionVariableLengthStructSettings <Value, Input> sessionVariableLengthStructSettings = null, ReadFlags readFlags = ReadFlags.Default)
                where Functions : IFunctions <Key, Value, Input, Output, Context>
            {
                if (_functions == null)
                {
                    throw new FasterException("Functions not provided for session");
                }

                return(_fasterKV.ResumeSession <Input, Output, Context, Functions>((Functions)_functions, sessionName, out commitPoint, sessionVariableLengthStructSettings, readFlags));
            }
 /// <summary>
 /// Parse the RopSetMessageReadFlagRequest structure.
 /// </summary>
 /// <param name="s">An stream containing RopSetMessageReadFlagRequest structure</param>
 public override void Parse(Stream s)
 {
     base.Parse(s);
     this.RopId = (RopIdType)ReadByte();
     this.LogonId = ReadByte();
     this.ResponseHandleIndex = ReadByte();
     this.InputHandleIndex = ReadByte();
     this.ReadFlags = (ReadFlags)this.ReadByte();
     if ((((byte)DecodingContext.SessionLogonFlagMapLogId[MapiInspector.MAPIInspector.currentParsingSessionID][this.LogonId] & (byte)LogonFlags.Private) != (byte)LogonFlags.Private))
     {
         this.ClientData = ConvertArray(ReadBytes(24));
     }
 }
Ejemplo n.º 12
0
        public TtfTypeface Read(Stream stream, ReadFlags readFlags = ReadFlags.Full)
        {
            var little = BitConverter.IsLittleEndian;

            using (var input = new ByteOrderSwappingBinaryReader(stream))
            {
                ushort majorVersion  = input.ReadUInt16();
                ushort minorVersion  = input.ReadUInt16();
                ushort tableCount    = input.ReadUInt16();
                ushort searchRange   = input.ReadUInt16();
                ushort entrySelector = input.ReadUInt16();
                ushort rangeShift    = input.ReadUInt16();
                var    tables        = new TableEntryCollection();
                for (int i = 0; i < tableCount; i++)
                {
                    tables.AddEntry(new UnreadTableEntry(ReadTableHeader(input)));
                }
                //------------------------------------------------------------------
                OS2Table  os2Table  = ReadTableIfExists(tables, input, new OS2Table());
                NameEntry nameEntry = ReadTableIfExists(tables, input, new NameEntry());


                Head              header            = ReadTableIfExists(tables, input, new Head());
                MaxProfile        maximumProfile    = ReadTableIfExists(tables, input, new MaxProfile());
                HorizontalHeader  horizontalHeader  = ReadTableIfExists(tables, input, new HorizontalHeader());
                HorizontalMetrics horizontalMetrics = ReadTableIfExists(tables, input, new HorizontalMetrics(horizontalHeader.HorizontalMetricsCount, maximumProfile.GlyphCount));

                //--------------
                Cmap           cmaps          = ReadTableIfExists(tables, input, new Cmap());
                GlyphLocations glyphLocations = ReadTableIfExists(tables, input, new GlyphLocations(maximumProfile.GlyphCount, header.WideGlyphLocations));
                Glyf           glyf           = ReadTableIfExists(tables, input, new Glyf(glyphLocations));
                //--------------
                Gasp gaspTable             = ReadTableIfExists(tables, input, new Gasp());
                VerticalDeviceMetrics vdmx = ReadTableIfExists(tables, input, new VerticalDeviceMetrics());
                //--------------
                PostTable postTable = ReadTableIfExists(tables, input, new PostTable());
                Kern      kern      = ReadTableIfExists(tables, input, new Kern());
                //--------------
                //advanced typography
                GDEF           gdef      = ReadTableIfExists(tables, input, new GDEF());
                GSUB           gsub      = ReadTableIfExists(tables, input, new GSUB());
                GPOS           gpos      = ReadTableIfExists(tables, input, new GPOS());
                BASE           baseTable = ReadTableIfExists(tables, input, new BASE());
                COLR           colr      = ReadTableIfExists(tables, input, new COLR());
                CPAL           cpal      = ReadTableIfExists(tables, input, new CPAL());
                VerticalHeader vhea      = ReadTableIfExists(tables, input, new VerticalHeader());
                if (vhea != null)
                {
                    VerticalMatric vmtx = ReadTableIfExists(tables, input, new VerticalMatric(vhea.NumOfLongVerMetrics));
                }

                EBLCTable fontBmpTable = ReadTableIfExists(tables, input, new EBLCTable());
                //---------------------------------------------
                //about truetype instruction init

                //---------------------------------------------
                var typeface = new TtfTypeface(
                    nameEntry,
                    header.Bounds,
                    header.UnitsPerEm,
                    glyf.Glyphs,
                    horizontalMetrics,
                    os2Table);
                //----------------------------
                typeface.CmapTable  = cmaps;
                typeface.KernTable  = kern;
                typeface.GaspTable  = gaspTable;
                typeface.MaxProfile = maximumProfile;
                typeface.HheaTable  = horizontalHeader;
                //----------------------------
                FpgmTable fpgmTable = ReadTableIfExists(tables, input, new FpgmTable());
                //control values table
                CvtTable cvtTable = ReadTableIfExists(tables, input, new CvtTable());
                if (cvtTable != null)
                {
                    typeface.ControlValues = cvtTable.controlValues;
                }
                if (fpgmTable != null)
                {
                    typeface.FpgmProgramBuffer = fpgmTable.programBuffer;
                }
                PrepTable propProgramTable = ReadTableIfExists(tables, input, new PrepTable());
                if (propProgramTable != null)
                {
                    typeface.PrepProgramBuffer = propProgramTable.programBuffer;
                }
                //-------------------------
                typeface.LoadOpenFontLayoutInfo(
                    gdef,
                    gsub,
                    gpos,
                    baseTable,
                    colr,
                    cpal);
                return(typeface);
            }
        }
Ejemplo n.º 13
0
        public ValueTask <FasterKV <Key, Value> .ReadAsyncResult <Input, Output, Context> > ReadAtAddressAsync(long address, ref Input input, ReadFlags readFlags = ReadFlags.None,
                                                                                                               Context userContext = default, long serialNo = 0, CancellationToken cancellationToken = default)
        {
            Debug.Assert(SupportAsync, NotAsyncSessionErr);
            Key key            = default;
            var operationFlags = FasterKV <Key, Value> .PendingContext <Input, Output, Context> .GetOperationFlags(readFlags, noKey : true);

            return(fht.ReadAsync(this.FasterSession, this.ctx, ref key, ref input, address, userContext, serialNo, cancellationToken, operationFlags));
        }
Ejemplo n.º 14
0
 public Status ReadAtAddress(long address, ref Input input, ref Output output, ReadFlags readFlags = ReadFlags.None, Context userContext = default, long serialNo = 0)
 {
     if (SupportAsync)
     {
         UnsafeResumeThread();
     }
     try
     {
         return(fht.ContextReadAtAddress(address, ref input, ref output, readFlags, userContext, FasterSession, serialNo, ctx));
     }
     finally
     {
         if (SupportAsync)
         {
             UnsafeSuspendThread();
         }
     }
 }
Ejemplo n.º 15
0
 void ProcessCurrentDifficulty(D2GameInfo gameInfo)
 {
     currentDifficulty = ReadFlags.HasFlag(DataReaderEnableFlags.CurrentDifficulty)
         ? (GameDifficulty)gameInfo.Game.Difficulty : GameDifficulty.Normal;
 }
Ejemplo n.º 16
0
 internal void SetOperationFlags(ReadFlags readFlags, long address, bool noKey = false)
 => this.SetOperationFlags(GetOperationFlags(readFlags, noKey), address);
Ejemplo n.º 17
0
 int ProcessCurrentPlayersX()
 {
     return(ReadFlags.HasFlag(DataReaderEnableFlags.CurrentPlayersX)
         ? Math.Max(reader.ReadByte(memory.Address.PlayersX, AddressingMode.Relative), (byte)1)
         : -1);
 }
Ejemplo n.º 18
0
 int ProcessCurrentArea()
 {
     return(ReadFlags.HasFlag(DataReaderEnableFlags.CurrentArea)
         ? reader.ReadByte(memory.Address.Area, AddressingMode.Relative)
         : -1);
 }
Ejemplo n.º 19
0
 List <QuestCollection> ProcessQuests(D2GameInfo gameInfo)
 {
     return(ReadFlags.HasFlag(DataReaderEnableFlags.QuestBuffers)
         ? ReadQuests(gameInfo)
         : new List <QuestCollection>());
 }
 Int64 Get(DB_TXN* txp, Int32 delta, ReadFlags flags) {
   Int64 value;
   DbRetVal ret;
   lock (rscLock) {
     DB_SEQUENCE* seqp = CheckDisposed();
     if (SeqGet == null)
       throw new BdbException("Sequence must be open.");
     ret = SeqGet(seqp, txp, delta, out value, unchecked((UInt32)flags));
   }
   Util.CheckRetVal(ret);
   return value;
 }
 public Int64 Get(Txn txn, Int32 delta, ReadFlags flags) {
   if (txn != null) {
     lock (txn.rscLock) {
       DB_TXN* txp = txn.CheckDisposed();
       return Get(txp, delta, flags);
     }
   }
   else
     return Get((DB_TXN*)null, delta, flags);
 }
 /// <summary>
 /// Parse the RopSetReadFlagsRequest structure.
 /// </summary>
 /// <param name="s">An stream containing RopSetReadFlagsRequest structure</param>
 public override void Parse(Stream s)
 {
     base.Parse(s);
     this.RopId = (RopIdType)ReadByte();
     this.LogonId = ReadByte();
     this.InputHandleIndex = ReadByte();
     this.WantAsynchronous = ReadBoolean();
     this.ReadFlags = (ReadFlags)ReadByte();
     this.MessageIdCount = ReadUshort();
     List<MessageID> messageIDs = new List<MessageID>();
     for (int i = 0; i < this.MessageIdCount; i++)
     {
         MessageID messageID = new MessageID();
         messageID.Parse(s);
         messageIDs.Add(messageID);
     }
     this.MessageIds = messageIDs.ToArray();
 }
Ejemplo n.º 23
0
 GameDifficulty ProcessCurrentDifficulty(D2GameInfo gameInfo)
 {
     return(ReadFlags.HasFlag(DataReaderEnableFlags.CurrentDifficulty)
         ? (GameDifficulty)gameInfo.Game.Difficulty
         : GameDifficulty.Normal);
 }
Ejemplo n.º 24
0
 public static extern int ReadEventLog(IntPtr hEventLog, ReadFlags dwReadFlags, int dwRecordOffset, byte [] buffer, int nNumberOfBytesToRead, ref int pnBytesRead, ref int pnMinNumberOfBytesNeeded);
			public static int ReadEventLog (IntPtr hEventLog, ReadFlags dwReadFlags, int dwRecordOffset, byte [] buffer, int nNumberOfBytesToRead, ref int pnBytesRead, ref int pnMinNumberOfBytesNeeded)
			{
				throw new System.NotImplementedException();
			}
Ejemplo n.º 26
0
 public Status Read(ref Key key, ref Input input, ref Output output, ref RecordInfo recordInfo, ReadFlags readFlags = ReadFlags.None, Context userContext = default, long serialNo = 0)
 {
     if (SupportAsync)
     {
         UnsafeResumeThread();
     }
     try
     {
         return(fht.ContextRead(ref key, ref input, ref output, ref recordInfo, readFlags, userContext, FasterSession, serialNo, ctx));
     }
     finally
     {
         if (SupportAsync)
         {
             UnsafeSuspendThread();
         }
     }
 }
Ejemplo n.º 27
0
 public static int ReadEventLog(IntPtr hEventLog, ReadFlags dwReadFlags, int dwRecordOffset, byte [] buffer, int nNumberOfBytesToRead, ref int pnBytesRead, ref int pnMinNumberOfBytesNeeded)
 {
     throw new System.NotImplementedException();
 }
Ejemplo n.º 28
0
 public Status Read(ref Key key, ref Input input, ref Output output, ref RecordInfo recordInfo, ReadFlags readFlags = ReadFlags.None, Context userContext = default, long serialNo = 0)
 => throw new FasterException(AdvancedOnlyMethodErr);
Ejemplo n.º 29
0
        List <int> ProcessInventoryItemIds()
        {
            var enabled = ReadFlags.HasFlag(DataReaderEnableFlags.InventoryItemIds);

            return(enabled ? ReadInventoryItemIds() : new List <int>());
        }
Ejemplo n.º 30
0
 public ValueTask <FasterKV <Key, Value> .ReadAsyncResult <Input, Output, Context> > ReadAsync(ref Key key, ref Input input, long startAddress, ReadFlags readFlags = ReadFlags.None,
                                                                                               Context userContext = default, long serialNo = 0, CancellationToken cancellationToken = default)
 => throw new FasterException(AdvancedOnlyMethodErr);
Ejemplo n.º 31
0
 internal void SetOperationFlags(ReadFlags readFlags, ref ReadOptions readOptions, bool noKey = false)
 => this.SetOperationFlags(GetOperationFlags(readFlags, noKey), readOptions.StopAddress);
Ejemplo n.º 32
0
			public static extern int ReadEventLog (IntPtr hEventLog, ReadFlags dwReadFlags, int dwRecordOffset, byte [] buffer, int nNumberOfBytesToRead, ref int pnBytesRead, ref int pnMinNumberOfBytesNeeded);
Ejemplo n.º 33
0
 /// <summary>
 /// Resume (continue) prior client session with FASTER; used during recovery from failure.
 /// </summary>
 /// <param name="functions">Callback functions</param>
 /// <param name="sessionName">Name of previous session to resume</param>
 /// <param name="commitPoint">Prior commit point of durability for session</param>
 /// <param name="sessionVariableLengthStructSettings">Session-specific variable-length struct settings</param>
 /// <param name="readFlags">ReadFlags for this session; override those specified at FasterKV level, and may be overridden on individual Read operations</param>
 /// <returns>Session instance</returns>
 public ClientSession <Key, Value, Input, Output, Context, Functions> ResumeSession <Functions>(Functions functions, string sessionName, out CommitPoint commitPoint,
                                                                                                SessionVariableLengthStructSettings <Value, Input> sessionVariableLengthStructSettings = null, ReadFlags readFlags = ReadFlags.Default)
     where Functions : IFunctions <Key, Value, Input, Output, Context>
 {
     return(_fasterKV.ResumeSession <Input, Output, Context, Functions>(functions, sessionName, out commitPoint, sessionVariableLengthStructSettings, readFlags));
 }
Ejemplo n.º 34
0
 Dictionary <BodyLocation, string> ProcessEquippedItemStrings()
 {
     return(ReadFlags.HasFlag(DataReaderEnableFlags.EquippedItemStrings)
         ? ReadEquippedItemStrings()
         : new Dictionary <BodyLocation, string>());
 }
Ejemplo n.º 35
0
        } // End ToBytes()

        public ReloadMessage FromBytes(byte[] bytes, ref long offset, ReadFlags flags)
        {
            if (bytes == null)
            {
                m_ReloadConfig.Logger(ReloadGlobals.TRACEFLAGS.T_ERROR,
                  "FromBytes: bytes = null!!");
                return null;
            }

            if (offset != 0)
                offset = 0;

            var ms = new MemoryStream(bytes, (int)offset, (int)(bytes.Count() - offset));
            //prepare variable for return (ref value)
            offset = 0;

            using (var reader = new BinaryReader(ms))
            {
                try
                {
                    UInt32 RELO_Tag;
                    //first check if this is a RELOAD message by checking th RELO tag
                    RELO_Tag = (UInt32)IPAddress.NetworkToHostOrder(reader.ReadInt32());

                    if (RELO_Tag != RELOTAG)
                    {
                        m_ReloadConfig.Logger(ReloadGlobals.TRACEFLAGS.T_ERROR,
                          String.Format("==> message has no RELO tag"));
                        return null;
                    }
                    forwarding_header.overlay = (UInt32)IPAddress.NetworkToHostOrder(
                      reader.ReadInt32());

                    if (forwarding_header.overlay != m_ReloadConfig.OverlayHash)
                        throw new System.Exception("Message from wrong overlay! (probably invalid hash)");

                    /* configuration_sequence */
                    forwarding_header.configuration_sequence = (UInt16)IPAddress.NetworkToHostOrder(reader.ReadInt16());
                    /* version */
                    forwarding_header.version = reader.ReadByte();
                    /* ttl */
                    forwarding_header.ttl = reader.ReadByte();
                    /* fragment */
                    forwarding_header.fragment = (UInt32)IPAddress.NetworkToHostOrder(reader.ReadInt32());
                    /* length */
                    forwarding_header.length = (UInt32)IPAddress.NetworkToHostOrder(reader.ReadInt32());

                    // obsolete -> auto fragmentation if message too large
                    //if (forwarding_header.length >= ReloadGlobals.MAX_PACKET_BUFFER_SIZE) {
                    //  m_ReloadConfig.Logger(ReloadGlobals.TRACEFLAGS.T_ERROR,
                    //    String.Format("==> forwarding header exceeds maximum value of {0}",
                    //    ReloadGlobals.MAX_PACKET_BUFFER_SIZE));
                    //  return null;
                    //}

                    /* transaction_id */
                    forwarding_header.transaction_id = (UInt64)IPAddress.NetworkToHostOrder(reader.ReadInt64());
                    /* max_response_length */
                    forwarding_header.max_response_length = (UInt32)IPAddress.NetworkToHostOrder(reader.ReadInt32());
                    /* via list length */
                    forwarding_header.via_list_length = (UInt16)IPAddress.NetworkToHostOrder(reader.ReadInt16());
                    /* destination list length */
                    forwarding_header.destination_list_length = (UInt16)IPAddress.NetworkToHostOrder(reader.ReadInt16());
                    /* options length */
                    forwarding_header.options_length = (UInt16)IPAddress.NetworkToHostOrder(reader.ReadInt16());

                    if (forwarding_header.via_list_length != 0)
                        forwarding_header.via_list = ReadDestList(reader, forwarding_header.via_list_length);

                    if (forwarding_header.destination_list_length != 0)
                        forwarding_header.destination_list = ReadDestList(reader, forwarding_header.destination_list_length);

                    if (forwarding_header.options_length != 0)
                        forwarding_header.fw_options = ReadOptionList(reader, forwarding_header.options_length);

                    long reload_msg_begin = ms.Position;

                    if (0 != (forwarding_header.fragment & 0x80000000))
                    { //is this a fragment?
                        uint fragment_offset = (forwarding_header.fragment & 0x3FFFFFFF);
                        bool last_fragment = ((forwarding_header.fragment & 0x40000000) != 0);

                        if (fragment_offset == 0 && last_fragment == true)
                        {
                            //single fragment message (means not fragmented) => process as usual
                        }
                        else
                        {
                            m_ReloadConfig.Logger(ReloadGlobals.TRACEFLAGS.T_FRAGMENTATION, String.Format("Fragmented Message: offset " + fragment_offset + "READ bytes " + (forwarding_header.length - reload_msg_begin)) + " left " + (reader.BaseStream.Length - ms.Position));
                            reload_message_body = new MessageFragment(RELOAD_MessageCode.Invalid, fragment_offset, last_fragment).FromReader(this, reader, forwarding_header.length - reload_msg_begin);  //this should be the fragmentsize instead of ms.Length better use forwardingheader.length TODO: FIX it
                            offset = ms.Position;
                            return this;
                        }
                    }

                    // now turn to message body
                    RELOAD_MessageCode MsgCode = (RELOAD_MessageCode)(UInt16)IPAddress.NetworkToHostOrder(reader.ReadInt16());
                    // now read message length          
                    long reload_msg_size = (UInt32)IPAddress.NetworkToHostOrder(reader.ReadInt32());

                    /* set pointer before msg code that the message routines itself
                     * can read it again
                     */
                    ms.Seek(reload_msg_begin, SeekOrigin.Begin);
                    switch (MsgCode)
                    {
                        case RELOAD_MessageCode.Probe_Request:
                        case RELOAD_MessageCode.Probe_Answer:
                            break;
                        case RELOAD_MessageCode.Attach_Request:
                        case RELOAD_MessageCode.Attach_Answer:
                            reload_message_body = new AttachReqAns().FromReader(this, reader, reload_msg_size);
                            break;
                        case RELOAD_MessageCode.Store_Request:
                            reload_message_body = new StoreReq(
                              m_ReloadConfig.ThisMachine.UsageManager).FromReader(this, reader, reload_msg_size);
                            break;
                        case RELOAD_MessageCode.Store_Answer:
                            reload_message_body = new StoreAns().FromReader(this, reader, reload_msg_size);
                            break;
                        case RELOAD_MessageCode.Fetch_Request:
                            reload_message_body = new FetchReq(m_ReloadConfig.ThisMachine.UsageManager).FromReader(this, reader, reload_msg_size);
                            break;
                        case RELOAD_MessageCode.Fetch_Answer:
                            reload_message_body = new FetchAns(m_ReloadConfig.ThisMachine.UsageManager).FromReader(this, reader, reload_msg_size);
                            break;
                        case RELOAD_MessageCode.Remove_Request:
                        case RELOAD_MessageCode.Remove_Answer:
                            //reload_message_body = new RemoveReqAns().FromReader(this, reader, reload_msg_size);
                            break;
                        case RELOAD_MessageCode.Find_Request:
                        case RELOAD_MessageCode.Find_Answer:
                            break;
                        case RELOAD_MessageCode.Join_Request:
                        case RELOAD_MessageCode.Join_Answer:
                            reload_message_body = new JoinReqAns().FromReader(this, reader, reload_msg_size);
                            break;
                        case RELOAD_MessageCode.Leave_Request:
                        case RELOAD_MessageCode.Leave_Answer:
                            reload_message_body = new LeaveReqAns().FromReader(this, reader, reload_msg_size);
                            break;
                        case RELOAD_MessageCode.Update_Request:
                        case RELOAD_MessageCode.Update_Answer:
                            reload_message_body = new UpdateReqAns().FromReader(this, reader, reload_msg_size);
                            break;
                        case RELOAD_MessageCode.Route_Query_Request:
                        case RELOAD_MessageCode.Route_Query_Answer:
                            break;
                        case RELOAD_MessageCode.Ping_Request:
                            reload_message_body = new PingReqAns().FromReader(this, reader, reload_msg_size);
                            break;
                        case RELOAD_MessageCode.Ping_Answer:
                            reload_message_body = new PingReqAns().FromReader(this, reader, reload_msg_size);
                            break;
                        case RELOAD_MessageCode.Stat_Request:
                        case RELOAD_MessageCode.Stat_Answer:
                            break;
                        case RELOAD_MessageCode.App_Attach_Request:
                        case RELOAD_MessageCode.App_Attach_Answer:
                            reload_message_body = new AppAttachReqAns().FromReader(this, reader, reload_msg_size);
                            break;
                        case RELOAD_MessageCode.Error:
                            reload_message_body = new ErrorResponse().FromReader(this, reader, reload_msg_size);
                            break;
                        case RELOAD_MessageCode.Unused:
                        case RELOAD_MessageCode.Unused2:
                        default:
                            throw new System.Exception(String.Format("Invalid RELOAD message type {0}", MsgCode));
                    }
                    if (reload_message_body != null)
                        reload_message_body.RELOAD_MsgCode = MsgCode;

                    // now read message extension length
                    UInt32 message_extension_size = (UInt32)IPAddress.NetworkToHostOrder(
                      reader.ReadInt32());
                    if (message_extension_size != 0)
                    {
                        //skip message extension length
                        reader.ReadBytes((int)message_extension_size);
                    }
                    if (ReloadGlobals.TLS)
                    {
                        /* Obtain security block */
                        security_block = new SecurityBlock(m_ReloadConfig).FromReader(reader, reload_msg_size);
                    }
                    else
                    { // do the FAKE
                        int iNodeIDLen = reader.ReadByte();

                        if (iNodeIDLen != 0)
                        {
                            NodeId nodeid = new NodeId(reader.ReadBytes(iNodeIDLen));
                            if (flags != ReadFlags.no_certcheck)
                            {
                                if (ReloadGlobals.TLS && nodeid != security_block.OriginatorNodeID)
                                    throw new System.Exception("Wrong message Originator!");
                                security_block.OriginatorNodeID = nodeid;
                            }
                        }
                        else
                            throw new System.Exception("Originator of message cannot be read!");
                        int iLHNodeIDLen = reader.ReadByte();
                        if (iLHNodeIDLen != 0)
                            LastHopNodeId = new NodeId(reader.ReadBytes(iLHNodeIDLen));
                    }
                    offset = ms.Position;
                    return this;
                } // End mok security
                catch (Exception ex)
                {
                    m_ReloadConfig.Logger(ReloadGlobals.TRACEFLAGS.T_ERROR,
                      "ReloadMesssage.FromBytes(): " + ex.Message);
                    return null;
                }
            }
        }
Ejemplo n.º 36
0
        internal Status ContextReadAtAddress <Input, Output, Context, FasterSession>(long address, ref Input input, ref Output output, ReadFlags readFlags, Context context, FasterSession fasterSession, long serialNo,
                                                                                     FasterExecutionContext <Input, Output, Context> sessionCtx)
            where FasterSession : IFasterSession <Key, Value, Input, Output, Context>
        {
            var pcontext = default(PendingContext <Input, Output, Context>);

            pcontext.SetOperationFlags(readFlags, address, noKey: true);
            Key key            = default;
            var internalStatus = InternalRead(ref key, ref input, ref output, address, ref context, ref pcontext, fasterSession, sessionCtx, serialNo);

            Debug.Assert(internalStatus != OperationStatus.RETRY_NOW);

            Status status;

            if (internalStatus == OperationStatus.SUCCESS || internalStatus == OperationStatus.NOTFOUND)
            {
                status = (Status)internalStatus;
            }
            else
            {
                status = HandleOperationStatus(sessionCtx, sessionCtx, ref pcontext, fasterSession, internalStatus, false, out _);
            }

            Debug.Assert(serialNo >= sessionCtx.serialNum, "Operation serial numbers must be non-decreasing");
            sessionCtx.serialNum = serialNo;
            return(status);
        }
Ejemplo n.º 37
0
 List <int> ProcessInventoryItemIds()
 {
     return(ReadFlags.HasFlag(DataReaderEnableFlags.InventoryItemIds)
         ? ReadInventoryItemIds()
         : new List <int>());
 }