public async Task WriteLargeDataBinary(int length) { byte[] data = new byte[length]; new Random(length).NextBytes(data); using (var memoryPool = new MemoryPool()) { var readerWriter = new PipelineReaderWriter(memoryPool); var output = readerWriter.Alloc(); output.Write(data); var foo = output.Memory.IsEmpty; // trying to see if .Memory breaks await output.FlushAsync(); readerWriter.CompleteWriter(); int offset = 0; while (true) { var result = await readerWriter.ReadAsync(); var input = result.Buffer; if (input.Length == 0) break; Assert.True(input.Equals(new Span<byte>(data, offset, input.Length))); offset += input.Length; readerWriter.Advance(input.End); } Assert.Equal(data.Length, offset); } }
public void DataIsWrittenIn16MBChunks() { int dataWrites = 0; int timeWrites = 0; GlobalEvents.Hook<LogFileWriteAction>((x) => { Assert.AreEqual(null, x.File); Assert.AreEqual("test", x.Group); // Count the write actions);); if (x.FileType == LogFileType.Data) dataWrites++; if (x.FileType == LogFileType.Time) timeWrites++; }, false); int counter = 0; var source = new MemoryPool("test", MemoryAddress.StaticAbsolute, 0x123456, 0, 0x1234); source.Add(new MemoryFieldFunc<int>("testInt", (pool) => counter++)); source.Add(new MemoryFieldFunc<string>("test", (pool) => "test")); var group = new LogGroup(null, "test", source); // Fill up a data file for (int i = 0; i < 1441792; i++) // 28 * 1441792 = 38.5MiB group.Update(i); // +28 bytes Assert.AreEqual(38, dataWrites); // 38*1MiB Assert.AreEqual(10, timeWrites); group.Close(); Assert.AreEqual(39, dataWrites); // last 0.5MiB Assert.AreEqual(11, timeWrites); }
public void PoolContainerNonZeroSize() { InitTest(); var p = new MemoryPool("MyPool", MemoryAddress.StaticAbsolute, 0, 0, 4); var provider = new MemoryProvider(reader); provider.Add(p); provider.Refresh(); Assert.AreEqual("MyPool", p.Name); Assert.AreEqual(MemoryAddress.StaticAbsolute, p.AddressType); Assert.AreEqual(0, p.Address); Assert.AreEqual(4, p.Size); Assert.AreEqual(0, p.Offset); Assert.False(p.IsDynamic); Assert.False(p.IsConstant); Assert.True(p.IsStatic); Assert.False(p.IsSignature); Assert.False(p.IsTemplate); Assert.AreEqual(1, actionLogbook.Count); Assert.AreEqual(0, actionLogbook[0].Address); Assert.AreEqual(4, actionLogbook[0].Size); }
private KestrelEngine(IApplicationShutdown appShutdownService) { AppShutdown = appShutdownService; Threads = new List<KestrelThread>(); Listeners = new List<Listener>(); Memory = new MemoryPool(); }
/// <summary> /// Initializes a new instance of the <see cref="HeapProperties"/> struct with <see cref="HeapType.Custom"/> /// </summary> /// <param name="cpuPageProperty">The cpu page properties.</param> /// <param name="memoryPoolPreference">The memory pool preference.</param> public HeapProperties(CpuPageProperty cpuPageProperty, MemoryPool memoryPoolPreference) { Type = HeapType.Custom; CPUPageProperty = cpuPageProperty; MemoryPoolPreference = memoryPoolPreference; this.CreationNodeMask = 1; this.VisibleNodeMask = 1; }
public MemoryManager( long capacity, int bufferSize) { long availableCells = capacity / bufferSize; int cellNumber = (int)Math.Min((long)Constants.MemoryManagerCellsMaximum, availableCells); this.memoryPool = new MemoryPool(cellNumber, bufferSize); }
public async Task CanWriteNothingToBuffer() { using (var memoryPool = new MemoryPool()) { var readerWriter = new PipelineReaderWriter(memoryPool); var buffer = readerWriter.Alloc(); buffer.Advance(0); // doing nothing, the hard way await buffer.FlushAsync(); } }
public TestInput() { var memory = new MemoryPool(); FrameContext = new FrameContext { SocketInput = new SocketInput(memory), Memory = memory, ConnectionControl = this, FrameControl = this }; }
public WebSocketHandler(MemoryPool memoryPool, ILoggerFactory loggerFactory, int? maxIncomingMessageSize) { _maxIncomingMessageSize = maxIncomingMessageSize; _memoryPool = memoryPool; _logger = loggerFactory.CreateLogger<WebSocketHandler>(); OnOpenAction = () => { }; OnMessageTextAction = msg => { }; OnMessageByteAction = msg => { }; OnCloseAction = () => { }; OnErrorAction = e => { }; }
public async Task CanWriteUInt64ToBuffer(ulong value, string valueAsString) { using (var memoryPool = new MemoryPool()) { var readerWriter = new PipelineReaderWriter(memoryPool); var buffer = readerWriter.Alloc(); buffer.Append(value, EncodingData.InvariantUtf8); await buffer.FlushAsync(); var result = await readerWriter.ReadAsync(); var inputBuffer = result.Buffer; Assert.Equal(valueAsString, inputBuffer.GetUtf8String()); } }
public KestrelEngine(ILibraryManager libraryManager, IApplicationShutdown appShutdownService) { AppShutdown = appShutdownService; Threads = new List<KestrelThread>(); Listeners = new List<Listener>(); Memory = new MemoryPool(); Libuv = new Libuv(); var libraryPath = default(string); if (libraryManager != null) { var library = libraryManager.GetLibraryInformation("Microsoft.AspNet.Server.Kestrel"); libraryPath = library.Path; if (library.Type == "Project") { libraryPath = Path.GetDirectoryName(libraryPath); } if (Libuv.IsWindows) { var architecture = IntPtr.Size == 4 ? "x86" : "amd64"; libraryPath = Path.Combine( libraryPath, "native", "windows", architecture, "libuv.dll"); } else if (Libuv.IsDarwin) { libraryPath = Path.Combine( libraryPath, "native", "darwin", "universal", "libuv.dylib"); } else { libraryPath = "libuv.so.1"; } } Libuv.Load(libraryPath); }
public void Create() { int counter = 0; var source = new MemoryPool("test", MemoryAddress.StaticAbsolute, 0x123456, 0, 0x1234); source.Add(new MemoryFieldFunc<int>("testInt", (pool) => counter++)); source.Add(new MemoryFieldFunc<string>("test", (pool) => "test")); var group = new LogGroup(null, "test", source); Assert.AreEqual("test", group.Name); Assert.AreEqual(2, group.Fields.Count()); Assert.AreEqual("testInt", group.Fields.FirstOrDefault().Name); Assert.AreEqual("test", group.Fields.Skip(1).FirstOrDefault().Name); Assert.True(group.Subscribed); }
public void InitTest() { if (Process.GetProcessesByName("rfactor").Length == 0) Assert.Ignore(); actionLogbook = new List<MemoryReadAction>(); GlobalEvents.Hook<MemoryReadAction>(x => { actionLogbook.Add(x); Debug.WriteLine(string.Format("Reading 0x{0:X}[0x{1:X}]", x.Address, x.Size)); }, true); reader = new DiagnosticMemoryReader(); reader.Open(Process.GetProcessesByName("rfactor")[0]); memory = new MemoryProvider(reader); drvPool = new MemoryPool("Test", MemoryAddress.StaticAbsolute, 0, 0); memory.Add(drvPool); }
private void RegisterDefaultServices() { var traceManager = new Lazy<TraceManager>(() => new TraceManager()); Register(typeof(ITraceManager), () => traceManager.Value); var newMessageBus = new Lazy<IMessageBus>(() => new MessageBus(this)); Register(typeof(IMessageBus), () => newMessageBus.Value); var stringMinifier = new Lazy<IStringMinifier>(() => new StringMinifier()); Register(typeof(IStringMinifier), () => stringMinifier.Value); var jsonSerializer = new Lazy<JsonSerializer>(); Register(typeof(JsonSerializer), () => jsonSerializer.Value); var transportManager = new Lazy<TransportManager>(() => new TransportManager(this)); Register(typeof(ITransportManager), () => transportManager.Value); var configurationManager = new DefaultConfigurationManager(); Register(typeof(IConfigurationManager), () => configurationManager); var transportHeartbeat = new Lazy<TransportHeartbeat>(() => new TransportHeartbeat(this)); Register(typeof(ITransportHeartbeat), () => transportHeartbeat.Value); var connectionManager = new Lazy<ConnectionManager>(() => new ConnectionManager(this)); Register(typeof(IConnectionManager), () => connectionManager.Value); var ackHandler = new Lazy<AckHandler>(); Register(typeof(IAckHandler), () => ackHandler.Value); var serverMessageHandler = new Lazy<AckSubscriber>(() => new AckSubscriber(this)); Register(typeof(AckSubscriber), () => serverMessageHandler.Value); var perfCounterWriter = new Lazy<PerformanceCounterManager>(() => new PerformanceCounterManager(this)); Register(typeof(IPerformanceCounterManager), () => perfCounterWriter.Value); var userIdProvider = new PrincipalUserIdProvider(); Register(typeof(IUserIdProvider), () => userIdProvider); var pool = new MemoryPool(); Register(typeof(IMemoryPool), () => pool); }
private static async Task ProcessConnection <TContext>(IHttpApplication <TContext> application, MemoryPool <byte> memoryPool, Socket socket) { using (var ns = new NetworkStream(socket)) { using (var connection = new StreamDuplexPipe(new PipeOptions(memoryPool), ns)) { await ProcessClient(application, connection); } } }
public TcpSslSession(Socket socket, ATcpOptions options, PipeScheduler scheduler, MemoryPool <byte> pool, SslFeature sslFeature, FilterPipeline <ITcpSession> filterPipeline) : base(socket, options, scheduler, pool, filterPipeline) { var inputPipeOptions = StreamPipeOptionsHelper.ReaderOptionsCreator(pool); var outputPipeOptions = StreamPipeOptionsHelper.WriterOptionsCreator(pool); var sslDuplexPipe = new SslStreamDuplexPipe(base.Transport, inputPipeOptions, outputPipeOptions, sslFeature.sslStreamFactory); this.sslTransport = sslDuplexPipe; this.sslOptions = sslFeature.sslOptions; }
static IMemoryOwner <TSource> ToArrayAt <TList, TSource, TPredicate>(this TList source, TPredicate predicate, int offset, int count, MemoryPool <TSource> pool) where TList : IReadOnlyList <TSource> where TPredicate : struct, IFunction <TSource, int, bool> { using var arrayBuilder = ToArrayBuilderAt(source, predicate, offset, count, ArrayPool <TSource> .Shared); return(arrayBuilder.ToArray(pool)); }
public void PoolStaticAbsolute() { InitTest(); var p = new MemoryPool("MyPool", MemoryAddress.StaticAbsolute, 0x7154c0, 0x6000); var provider = new MemoryProvider(reader); provider.Add(p); provider.Refresh(); Assert.AreEqual("MyPool", p.Name); Assert.AreEqual(MemoryAddress.StaticAbsolute, p.AddressType); Assert.AreEqual(0x7154c0, p.Address); Assert.AreEqual(0x6000, p.Size); Assert.AreEqual(0, p.Offset); Assert.False(p.IsDynamic); Assert.False(p.IsConstant); Assert.True(p.IsStatic); Assert.False(p.IsSignature); Assert.False(p.IsTemplate); Assert.AreEqual(1, p.AddressTree.Length); Assert.AreEqual(0x7154C0, p.AddressTree[0]); Assert.AreEqual(1, actionLogbook.Count); Assert.AreEqual(0x7154C0, actionLogbook[0].Address); Assert.AreEqual(0x6000, actionLogbook[0].Size); provider.Refresh(); Assert.AreEqual(2, actionLogbook.Count); Assert.AreEqual(0x7154C0, actionLogbook[0].Address); Assert.AreEqual(0x6000, actionLogbook[0].Size); Assert.AreEqual(0x7154C0, actionLogbook[1].Address); Assert.AreEqual(0x6000, actionLogbook[1].Size); }
public TestMemoryPool() { _pool = new CustomMemoryPool <byte>(); }
public SignatureReader(PipeReader reader, MemoryPool <byte> memoryPool) { _reader = reader; _memoryPool = memoryPool; }
public void Add(MemoryPool pool) { _pools.Add(pool); pool.SetProvider(this); }
public void PoolSignature() { InitTest(); var p = new MemoryPool("MyPool", MemoryAddress.StaticAbsolute, "A0XXXXXXXX8B0D????????F6D81BC0", 0x4); var provider = new MemoryProvider(reader); provider.Add(p); provider.Scanner.Enable(); provider.Refresh(); provider.Scanner.Disable(); Assert.AreEqual("MyPool", p.Name); Assert.AreEqual(MemoryAddress.StaticAbsolute, p.AddressType); Assert.AreEqual(0x71528C, p.Address); Assert.AreEqual(0x4, p.Size); Assert.AreEqual(0, p.Offset); Assert.AreEqual(0, p.Pointers.Count()); Assert.False(p.IsDynamic); Assert.False(p.IsConstant); Assert.True(p.IsSignature); Assert.True(p.IsStatic); Assert.False(p.IsTemplate); Assert.AreEqual(1, p.AddressTree.Length); Assert.AreEqual(0x71528C, p.AddressTree[0]); Assert.Greater(actionLogbook.Count, 1); var preRefreshCount = actionLogbook.Count; Assert.AreEqual(0x71528C, actionLogbook[actionLogbook.Count - 1].Address); Assert.AreEqual(0x4, actionLogbook[actionLogbook.Count - 1].Size); // re-read // it will only read what was initially found by the signature. provider.Refresh(); var postRefreshCount = actionLogbook.Count; Assert.AreEqual(1, postRefreshCount - preRefreshCount); Assert.AreEqual(0x71528C, actionLogbook[actionLogbook.Count - 2].Address); Assert.AreEqual(0x71528C, actionLogbook[actionLogbook.Count - 1].Address); Assert.AreEqual(0x4, actionLogbook[actionLogbook.Count - 2].Size); Assert.AreEqual(0x4, actionLogbook[actionLogbook.Count - 1].Size); }
public void PoolDynamic() { InitTest(); var driversPool = new MemoryPool("Drivers", MemoryAddress.Static, 0x315298, 0x200); var provider = new MemoryProvider(reader); provider.Add(driversPool); provider.Refresh(); Assert.AreEqual("Drivers", driversPool.Name); Assert.AreEqual(MemoryAddress.Static, driversPool.AddressType); Assert.AreEqual(0x315298, driversPool.Address); Assert.AreEqual(0x200, driversPool.Size); Assert.AreEqual(0, driversPool.Offset); Assert.False(driversPool.IsDynamic); Assert.False(driversPool.IsConstant); Assert.True(driversPool.IsStatic); Assert.False(driversPool.IsSignature); Assert.False(driversPool.IsTemplate); Assert.AreEqual(1, actionLogbook.Count); Assert.AreEqual(0x715298, actionLogbook[0].Address); Assert.AreEqual(0x200, actionLogbook[0].Size); var driver1 = new MemoryPool("Driver1", MemoryAddress.Dynamic, driversPool, 0x0, 0x6000); var driver2 = new MemoryPool("Driver2", MemoryAddress.Dynamic, driversPool, 0x4, 0x6000); provider.Add(driver1); provider.Add(driver2); provider.Refresh(); Assert.AreEqual("Driver1", driver1.Name); Assert.AreEqual(MemoryAddress.Dynamic, driver1.AddressType); Assert.AreEqual(0, driver1.Address); Assert.AreEqual(0x6000, driver1.Size); Assert.AreEqual(0, driver1.Offset); Assert.AreEqual(driversPool, driver1.Pool); Assert.True(driver1.IsDynamic); Assert.False(driver1.IsConstant); Assert.False(driver1.IsStatic); Assert.False(driver1.IsSignature); Assert.False(driver1.IsTemplate); Assert.AreEqual("Driver2", driver2.Name); Assert.AreEqual(MemoryAddress.Dynamic, driver2.AddressType); Assert.AreEqual(0, driver2.Address); Assert.AreEqual(0x6000, driver2.Size); Assert.AreEqual(4, driver2.Offset); Assert.AreEqual(driversPool, driver2.Pool); Assert.True(driver2.IsDynamic); Assert.False(driver2.IsConstant); Assert.False(driver2.IsStatic); Assert.False(driver2.IsSignature); Assert.False(driver2.IsTemplate); Assert.AreEqual(4, actionLogbook.Count); Assert.AreEqual(0x715298, actionLogbook[0].Address); Assert.AreEqual(0x200, actionLogbook[0].Size); Assert.AreEqual(0x715298, actionLogbook[1].Address); Assert.AreEqual(0x200, actionLogbook[1].Size); Assert.AreEqual(0x7154c0, actionLogbook[2].Address); Assert.AreEqual(0x6000, actionLogbook[2].Size); Assert.AreEqual(0x71b408, actionLogbook[3].Address); Assert.AreEqual(0x6000, actionLogbook[3].Size); }
public void PoolTemplate() { InitTest(); var driversPool = new MemoryPool("Drivers", MemoryAddress.Static, 0x315298, 0x200); driversPool.SetTemplate(true); var provider = new MemoryProvider(reader); provider.Add(driversPool); provider.Refresh(); Assert.AreEqual("Drivers", driversPool.Name); Assert.AreEqual(MemoryAddress.Static, driversPool.AddressType); Assert.AreEqual(0x315298, driversPool.Address); Assert.AreEqual(0x200, driversPool.Size); Assert.AreEqual(0, driversPool.Offset); Assert.False(driversPool.IsDynamic); Assert.False(driversPool.IsConstant); Assert.True(driversPool.IsStatic); Assert.False(driversPool.IsSignature); Assert.True(driversPool.IsTemplate); Assert.AreEqual(0, actionLogbook.Count); for (int i = 0; i < 100; i++) provider.Refresh(); Assert.AreEqual(0, actionLogbook.Count); driversPool.SetTemplate(false); provider.Refresh(); Assert.AreEqual(0x715298, actionLogbook[0].Address); Assert.AreEqual(0x200, actionLogbook[0].Size); }
public void PoolStaticPointer() { InitTest(); var p = new MemoryPool("MyPool", MemoryAddress.Static, 0x315298, new[] { 0 }, 0x6000); var provider = new MemoryProvider(reader); provider.Add(p); provider.Refresh(); Assert.AreEqual("MyPool", p.Name); Assert.AreEqual(MemoryAddress.Static, p.AddressType); Assert.AreEqual(0x315298, p.Address); Assert.AreEqual(0x6000, p.Size); Assert.AreEqual(0, p.Offset); Assert.AreEqual(1, p.Pointers.Count()); Assert.AreEqual(0, p.Pointers.FirstOrDefault().Offset); Assert.False(p.IsDynamic); Assert.False(p.IsConstant); Assert.True(p.IsStatic); Assert.False(p.IsSignature); Assert.False(p.IsTemplate); Assert.AreEqual(2, p.AddressTree.Length); Assert.AreEqual(0x715298, p.AddressTree[0]); Assert.AreEqual(0x7154C0, p.AddressTree[1]); Assert.AreEqual(2, actionLogbook.Count); Assert.AreEqual(0x715298, actionLogbook[0].Address); Assert.AreEqual(0x7154C0, actionLogbook[1].Address); Assert.AreEqual(0x4, actionLogbook[0].Size); Assert.AreEqual(0x6000, actionLogbook[1].Size); // re-read // it will follow the pointer every refresh cycle. provider.Refresh(); Assert.AreEqual(4, actionLogbook.Count); Assert.AreEqual(0x715298, actionLogbook[0].Address); Assert.AreEqual(0x7154C0, actionLogbook[1].Address); Assert.AreEqual(0x715298, actionLogbook[2].Address); Assert.AreEqual(0x7154C0, actionLogbook[3].Address); Assert.AreEqual(0x4, actionLogbook[0].Size); Assert.AreEqual(0x6000, actionLogbook[1].Size); Assert.AreEqual(0x4, actionLogbook[2].Size); Assert.AreEqual(0x6000, actionLogbook[3].Size); }
public void PoolStaticAbsolutePointerSignature() { InitTest(); var p = new MemoryPool("MyPool", MemoryAddress.StaticAbsolute, 0x715298, new[] { new MemoryFieldSignaturePointer(0, false), new MemoryFieldSignaturePointer("7CD5D9XX????????518BCFD91C24E8", true), }, 0x4); var provider = new MemoryProvider(reader); provider.Add(p); provider.Scanner.Enable(); provider.Refresh(); provider.Scanner.Disable(); Assert.AreEqual("MyPool", p.Name); Assert.AreEqual(MemoryAddress.StaticAbsolute, p.AddressType); Assert.AreEqual(0x715298, p.Address); Assert.AreEqual(0x4, p.Size); Assert.AreEqual(0, p.Offset); Assert.AreEqual(2, p.Pointers.Count()); Assert.AreEqual(0, p.Pointers.FirstOrDefault().Offset); Assert.AreEqual(0x317C, p.Pointers.ToList()[1].Offset); Assert.False(p.IsDynamic); Assert.False(p.IsConstant); Assert.True(p.IsStatic); Assert.False(p.IsSignature); Assert.False(p.IsTemplate); Assert.AreEqual(3, p.AddressTree.Length); Assert.AreEqual(0x715298, p.AddressTree[0]); Assert.AreEqual(0x7154C0, p.AddressTree[1]); Assert.AreEqual(0x71863C, p.AddressTree[2]); Assert.Greater(actionLogbook.Count, 2); int preLogBookSize = actionLogbook.Count; Assert.AreEqual(0x715298, actionLogbook[actionLogbook.Count-2].Address); Assert.AreEqual(0x71863C, actionLogbook[actionLogbook.Count-1].Address); Assert.AreEqual(0x4, actionLogbook[actionLogbook.Count - 2].Size); Assert.AreEqual(0x4, actionLogbook[actionLogbook.Count - 1].Size); // re-read // it will follow the pointer every refresh cycle. provider.Refresh(); int postLogBookSize = actionLogbook.Count; Assert.AreEqual(postLogBookSize - preLogBookSize, 2); Assert.AreEqual(0x715298, actionLogbook[actionLogbook.Count - 4].Address); Assert.AreEqual(0x71863C, actionLogbook[actionLogbook.Count - 3].Address); Assert.AreEqual(0x715298, actionLogbook[actionLogbook.Count - 2].Address); Assert.AreEqual(0x71863C, actionLogbook[actionLogbook.Count - 1].Address); Assert.AreEqual(0x4, actionLogbook[actionLogbook.Count - 4].Size); Assert.AreEqual(0x4, actionLogbook[actionLogbook.Count - 3].Size); Assert.AreEqual(0x4, actionLogbook[actionLogbook.Count - 2].Size); Assert.AreEqual(0x4, actionLogbook[actionLogbook.Count - 1].Size); }
public void TestSetup() { // protect against external changes on TimeProvider TimeProvider.ResetToDefault(); if (TheNeoSystem == null) { var mockSnapshot = new Mock <Snapshot>(); mockSnapshot.SetupGet(p => p.Blocks).Returns(new TestDataCache <UInt256, BlockState>()); mockSnapshot.SetupGet(p => p.Transactions).Returns(new TestDataCache <UInt256, TransactionState>()); mockSnapshot.SetupGet(p => p.Accounts).Returns(new TestDataCache <UInt160, AccountState>()); mockSnapshot.SetupGet(p => p.UnspentCoins).Returns(new TestDataCache <UInt256, UnspentCoinState>()); mockSnapshot.SetupGet(p => p.SpentCoins).Returns(new TestDataCache <UInt256, SpentCoinState>()); mockSnapshot.SetupGet(p => p.Validators).Returns(new TestDataCache <ECPoint, ValidatorState>()); mockSnapshot.SetupGet(p => p.Assets).Returns(new TestDataCache <UInt256, AssetState>()); mockSnapshot.SetupGet(p => p.Contracts).Returns(new TestDataCache <UInt160, ContractState>()); mockSnapshot.SetupGet(p => p.Storages).Returns(new TestDataCache <StorageKey, StorageItem>()); mockSnapshot.SetupGet(p => p.HeaderHashList) .Returns(new TestDataCache <UInt32Wrapper, HeaderHashList>()); mockSnapshot.SetupGet(p => p.ValidatorsCount).Returns(new TestMetaDataCache <ValidatorsCountState>()); mockSnapshot.SetupGet(p => p.BlockHashIndex).Returns(new TestMetaDataCache <HashIndexState>()); mockSnapshot.SetupGet(p => p.HeaderHashIndex).Returns(new TestMetaDataCache <HashIndexState>()); var mockStore = new Mock <Store>(); var defaultTx = CreateRandomHashInvocationMockTransaction().Object; defaultTx.Outputs = new TransactionOutput[1]; defaultTx.Outputs[0] = new TransactionOutput { AssetId = Blockchain.UtilityToken.Hash, Value = new Fixed8(1000000), ScriptHash = UInt160.Zero // doesn't matter for our purposes. }; mockStore.Setup(p => p.GetBlocks()).Returns(new TestDataCache <UInt256, BlockState>()); mockStore.Setup(p => p.GetTransactions()).Returns(new TestDataCache <UInt256, TransactionState>( new TransactionState { BlockIndex = 1, Transaction = defaultTx })); mockStore.Setup(p => p.GetAccounts()).Returns(new TestDataCache <UInt160, AccountState>()); mockStore.Setup(p => p.GetUnspentCoins()).Returns(new TestDataCache <UInt256, UnspentCoinState>()); mockStore.Setup(p => p.GetSpentCoins()).Returns(new TestDataCache <UInt256, SpentCoinState>()); mockStore.Setup(p => p.GetValidators()).Returns(new TestDataCache <ECPoint, ValidatorState>()); mockStore.Setup(p => p.GetAssets()).Returns(new TestDataCache <UInt256, AssetState>()); mockStore.Setup(p => p.GetContracts()).Returns(new TestDataCache <UInt160, ContractState>()); mockStore.Setup(p => p.GetStorages()).Returns(new TestDataCache <StorageKey, StorageItem>()); mockStore.Setup(p => p.GetHeaderHashList()).Returns(new TestDataCache <UInt32Wrapper, HeaderHashList>()); mockStore.Setup(p => p.GetValidatorsCount()).Returns(new TestMetaDataCache <ValidatorsCountState>()); mockStore.Setup(p => p.GetBlockHashIndex()).Returns(new TestMetaDataCache <HashIndexState>()); mockStore.Setup(p => p.GetHeaderHashIndex()).Returns(new TestMetaDataCache <HashIndexState>()); mockStore.Setup(p => p.GetSnapshot()).Returns(mockSnapshot.Object); Console.WriteLine("initialize NeoSystem"); TheNeoSystem = new NeoSystem(mockStore.Object); // new Mock<NeoSystem>(mockStore.Object); } // Create a MemoryPool with capacity of 100 _unit = new MemoryPool(TheNeoSystem, 100); // Verify capacity equals the amount specified _unit.Capacity.ShouldBeEquivalentTo(100); _unit.VerifiedCount.ShouldBeEquivalentTo(0); _unit.UnVerifiedCount.ShouldBeEquivalentTo(0); _unit.Count.ShouldBeEquivalentTo(0); }
public ReadOnlySequenceBuilder(MemoryPool <T>?pool = default) { _pool = pool ?? MemoryPool <T> .Shared; _first = new Segment(null, _pool.Rent(BlockSize)); _head = _first; }
public ServiceContext() { Memory = new MemoryPool(); }
public ListenerContext(ServiceContext serviceContext) : base(serviceContext) { Memory = new MemoryPool(); WriteReqPool = new Queue <UvWriteReq>(SocketOutput.MaxPooledWriteReqs); }
public FireflyService() { Trace = NullServerTrace.Instance; Memory = new MemoryPool(); }
public StreamPartitioner(Stream stream, MemoryPool <byte> memoryPool = default) { this.stream = stream; this.memoryPool = memoryPool ?? MemoryPool <byte> .Shared; }
public void PoolSignaturePointerWithSignature() { InitTest(); var p = new MemoryPool("MyPool", MemoryAddress.StaticAbsolute, "A0XXXXXXXX8B0D????????F6D81BC0", new[] { new MemoryFieldSignaturePointer(0, false), new MemoryFieldSignaturePointer("7CD5D9XX????????518BCFD91C24E8", true), }, 0x4); var provider = new MemoryProvider(reader); provider.Add(p); provider.Scanner.Enable(); provider.Refresh(); provider.Scanner.Disable(); Assert.AreEqual("MyPool", p.Name); Assert.AreEqual(MemoryAddress.StaticAbsolute, p.AddressType); Assert.AreEqual(0x71528C, p.Address); Assert.AreEqual(0x4, p.Size); Assert.AreEqual(0, p.Offset); Assert.AreEqual(2, p.Pointers.Count()); Assert.AreEqual(0, p.Pointers.FirstOrDefault().Offset); Assert.AreEqual(0x317C, p.Pointers.ToList()[1].Offset); Assert.False(p.IsDynamic); Assert.False(p.IsConstant); Assert.True(p.IsSignature); Assert.True(p.IsStatic); Assert.False(p.IsTemplate); Assert.AreEqual(3, p.AddressTree.Length); Assert.AreEqual(0x71528C, p.AddressTree[0]); Assert.AreEqual(0x7154c0, p.AddressTree[1]); Assert.AreEqual(0x71863C, p.AddressTree[2]); Assert.Greater(actionLogbook.Count, 2); var preRefreshCount = actionLogbook.Count; Assert.AreEqual(0x71528C, actionLogbook[actionLogbook.Count - 2].Address); Assert.AreEqual(0x71863C, actionLogbook[actionLogbook.Count - 1].Address); Assert.AreEqual(0x4, actionLogbook[actionLogbook.Count - 2].Size); Assert.AreEqual(0x4, actionLogbook[actionLogbook.Count - 1].Size); // re-read // it will only read what was initially found by the signatures. provider.Refresh(); var postRefreshCount = actionLogbook.Count; Assert.AreEqual(2, postRefreshCount - preRefreshCount); Assert.AreEqual(0x71528C, actionLogbook[actionLogbook.Count - 4].Address); Assert.AreEqual(0x71863C, actionLogbook[actionLogbook.Count - 3].Address); Assert.AreEqual(0x71528C, actionLogbook[actionLogbook.Count - 2].Address); Assert.AreEqual(0x71863C, actionLogbook[actionLogbook.Count - 1].Address); Assert.AreEqual(0x4, actionLogbook[actionLogbook.Count - 4].Size); Assert.AreEqual(0x4, actionLogbook[actionLogbook.Count - 3].Size); Assert.AreEqual(0x4, actionLogbook[actionLogbook.Count - 2].Size); Assert.AreEqual(0x4, actionLogbook[actionLogbook.Count - 1].Size); }
public void Remove(MemoryPool pool) { _pools.Remove(pool); }
public void RecordTestData() { float[] rpmWave; float[] speedWave; GetWaves(out rpmWave, out speedWave); int index = 0; var provider = new MemoryProvider(null); var fakePool = new MemoryPool("Driver", MemoryAddress.StaticAbsolute, 0, 0); fakePool.Add(new MemoryFieldFunc<float>("Speed", (pool) => speedWave[index], true)); fakePool.Add(new MemoryFieldFunc<float>("RPM", (pool) => rpmWave[index++], true)); fakePool.Add(new MemoryFieldConstant<bool>("IsAI", false)); fakePool.Add(new MemoryFieldConstant<bool>("IsPlayer", true)); provider.Add(fakePool); var fakeDriver = new TelemetryDriver(fakePool); var fakeDrivers = new List<TelemetryDriver>(new[] {fakeDriver}); TelemetryLogger logger = new TelemetryLogger("testSim", new TelemetryLoggerConfiguration(true, true, true, true)); logger.SetDatasource(provider); logger.SetAnnotater( new TelemetryArchive()); GlobalEvents.Fire(new SessionStarted(), true); GlobalEvents.Fire(new DriversAdded(null, fakeDrivers), true); for(int i = 0 ; i <1024;i++) logger.Update(i*25); GlobalEvents.Fire(new SessionStopped(), true); Thread.Sleep(500); ZipStorer checkFile = ZipStorer.Open("tmp.zip", FileAccess.Read); var files = checkFile.ReadCentralDir(); Assert.AreEqual(3, files.Count); Assert.AreEqual(1024 * 2 * 12 + 2 * 8, files.Where(x => x.FilenameInZip.Contains("Data.bin")).FirstOrDefault().FileSize); Assert.AreEqual(1024*8, files.Where(x => x.FilenameInZip.Contains("Time.bin")).FirstOrDefault().FileSize); }
public FileReader(MemoryPool pool) : base(pool) { }
public void Initialize(MemoryProvider provider) { MemoryPool simulator = new MemoryPool("Simulator", MemoryAddress.Static, 0, 0); simulator.Add(new MemoryFieldLazy<int>("CarPlayer", MemoryAddress.Static, 0x31528c, 4)); simulator.Add(new MemoryFieldLazy<int[]>("Drivers", MemoryAddress.Static, 0x315298, 0x19C)); simulator.Add(new MemoryFieldLazy<string>("LocationGame", MemoryAddress.Static, 0x6EB320, 0, 256)); MemoryPool session = new MemoryPool("Session", MemoryAddress.Static, 0, 0); session.Add(new MemoryFieldLazy<int>("Cars", MemoryAddress.Static, 0x315290, 4)); session.Add(new MemoryFieldLazy<float>("Time", MemoryAddress.Static, 0x60022C, 4)); session.Add(new MemoryFieldLazy<float>("Clock", MemoryAddress.Static, 0x6E2CD8, 4)); session.Add(new MemoryFieldLazy<string>("LocationTrack", MemoryAddress.Static, 0x309D28, 0, 256)); session.Add(new MemoryFieldLazy<bool>("IsOffline", MemoryAddress.Static, 0x315444, 1, (x) => !x)); session.Add(new MemoryFieldLazy<bool>("IsActive", MemoryAddress.Static, 0x30FEE4, 1)); session.Add(new MemoryFieldLazy<bool>("IsReplay", MemoryAddress.Static, 0x315444, 1)); session.Add(new MemoryFieldFunc<bool>("IsLoading", (pool) => !pool.ReadAs<bool>("IsActive") && pool.ReadAs<int>("Cars") > 0 && pool.ReadAs<string>("LocationTrack").Length != 0 )); MemoryPool templateDriver = new MemoryPool("DriverTemplate", MemoryAddress.StaticAbsolute, 0, 0x5F48); // base, 0x5F48 size templateDriver.Add(new MemoryFieldConstant<bool>("IsActive", true)); templateDriver.Add(new MemoryFieldLazy<int>("Index", MemoryAddress.Dynamic, 0, 0x8, 32)); templateDriver.Add(new MemoryFieldLazy<string>("Name", MemoryAddress.Dynamic, 0, 0x5B08, 32)); templateDriver.Add(new MemoryFieldLazy<string>("CarTeam", MemoryAddress.Dynamic, 0, 0x5C22, 64)); templateDriver.Add(new MemoryFieldLazy<string>("CarModel", MemoryAddress.Dynamic, 0, 0x5C62, 64)); templateDriver.Add(new MemoryFieldLazy<string>("CarClasses", MemoryAddress.Dynamic, 0, 0x39BC, 64)); templateDriver.Add(new MemoryFieldLazy<float>("Meter", MemoryAddress.Dynamic, 0, 0x3D04, 4)); templateDriver.Add(new MemoryFieldLazy<float>("Speed", MemoryAddress.Dynamic, 0, 0x57C0, 4)); templateDriver.Add(new MemoryFieldLazy<float>("RPM", MemoryAddress.Dynamic, 0, 0x317C, 4)); templateDriver.Add(new MemoryFieldLazy<float>("RPMMax", MemoryAddress.Dynamic, 0, 0x3180, 4)); templateDriver.Add(new MemoryFieldLazy<int>("Gear", MemoryAddress.Dynamic, 0, 0x321C, 1)); templateDriver.Add(new MemoryFieldLazy<float>("Mass", MemoryAddress.Dynamic, 0, 0x28DC, 4)); templateDriver.Add(new MemoryFieldLazy<float>("Fuel", MemoryAddress.Dynamic, 0, 0x315C, 4)); templateDriver.Add(new MemoryFieldLazy<float>("FuelCapacity", MemoryAddress.Dynamic, 0, 0x3160, 4)); templateDriver.Add(new MemoryFieldLazy<float>("TyreWearLF", MemoryAddress.Dynamic, 0, 0x2A34, 4)); templateDriver.Add(new MemoryFieldLazy<float>("TyreWearRF", MemoryAddress.Dynamic, 0, 0x2C1C, 4)); templateDriver.Add(new MemoryFieldLazy<float>("TyreWearLR", MemoryAddress.Dynamic, 0, 0x2E04, 4)); templateDriver.Add(new MemoryFieldLazy<float>("TyreWearRR", MemoryAddress.Dynamic, 0, 0x2FEC, 4)); templateDriver.Add(new MemoryFieldLazy<float>("InputThrottle", MemoryAddress.Dynamic, 0, 0x2938, 4)); templateDriver.Add(new MemoryFieldLazy<float>("InputBrake", MemoryAddress.Dynamic, 0, 0x2940, 4)); templateDriver.Add(new MemoryFieldLazy<float>("CoordinateX", MemoryAddress.Dynamic, 0, 0x289C, 4)); templateDriver.Add(new MemoryFieldLazy<float>("CoordinateY", MemoryAddress.Dynamic, 0, 0x28A4, 4)); templateDriver.Add(new MemoryFieldLazy<float>("CoordinateZ", MemoryAddress.Dynamic, 0, 0x28A0, 4)); templateDriver.Add(new MemoryFieldLazy<float>("CoordinateX-Replay", MemoryAddress.Dynamic, 0, 0x10, 4)); templateDriver.Add(new MemoryFieldLazy<float>("CoordinateY-Replay", MemoryAddress.Dynamic, 0, 0x18, 4)); templateDriver.Add(new MemoryFieldLazy<float>("CoordinateZ-Replay", MemoryAddress.Dynamic, 0, 0x14, 4)); templateDriver.Add(new MemoryFieldLazy<float>("RotationX", MemoryAddress.Dynamic, 0, 0x40, 4)); templateDriver.Add(new MemoryFieldLazy<float>("RotationY", MemoryAddress.Dynamic, 0, 0x48, 4)); templateDriver.Add(new MemoryFieldLazy<float>("RotationZ", MemoryAddress.Dynamic, 0, 0x44, 4)); templateDriver.Add(new MemoryFieldFunc<float>("Yaw", (pool) => (float)Math.Atan2(pool.ReadAs<float>("RotationX"), pool.ReadAs<float>("RotationY")), true)); templateDriver.Add(new MemoryFieldLazy<float>("AccelerationX", MemoryAddress.Dynamic, 0, 0x57C8, 4)); templateDriver.Add(new MemoryFieldLazy<int>("Pitstops", MemoryAddress.Dynamic, 0, 0x3D2C, 4)); templateDriver.Add(new MemoryFieldLazy<int>("Position", MemoryAddress.Dynamic, 0, 0x3D20, 4)); templateDriver.Add(new MemoryFieldLazy<int>("Laps", MemoryAddress.Dynamic, 0, 0x3CF8, 1)); templateDriver.Add(new MemoryFieldLazy<bool>("IsAI", MemoryAddress.Dynamic, 0, 0x59C8, 1)); templateDriver.Add(new MemoryFieldLazy<bool>("IsRetired", MemoryAddress.Dynamic, 0, 0x4160, 1)); templateDriver.Add(new MemoryFieldLazy<bool>("IsLimiter", MemoryAddress.Dynamic, 0, 0x17B1, 1)); templateDriver.Add(new MemoryFieldLazy<bool>("IsPits", MemoryAddress.Dynamic, 0, 0x27A8, 1)); templateDriver.Add(new MemoryFieldLazy<bool>("IsDriving", MemoryAddress.Dynamic, 0, 0x3CBF, 1)); templateDriver.Add(new MemoryFieldLazy<byte>("IsDisqualified", MemoryAddress.Dynamic, 0x3D24, 1, (v) => (byte)((v == 3) ? 1 : 0))); templateDriver.Add(new MemoryFieldLazy<bool>("FlagYellow", MemoryAddress.Dynamic, 0, 0x104, 1, (x) => !x)); templateDriver.Add(new MemoryFieldLazy<bool>("FlagBlue", MemoryAddress.Dynamic, 0, 0x3E39, 1)); templateDriver.Add(new MemoryFieldLazy<bool>("FlagBlack", MemoryAddress.Dynamic, 0, 0x3D24, 1)); templateDriver.Add(new MemoryFieldLazy<bool>("Ignition", MemoryAddress.Dynamic, 0, 0xAA, 1)); var laps = new MemoryPool("Laps", MemoryAddress.Dynamic, templateDriver, 0x3D90, 6 * 4 * 200); // 200 laps, 6 floats each. templateDriver.Add(laps); provider.Add(simulator); provider.Add(session); provider.Add(templateDriver); provider.Refresh(); templateDriver.SetTemplate(true); DriverPositionOffset = templateDriver.Fields["Position"].Offset; NamePositionOffset = templateDriver.Fields["Name"].Offset; }
public MemoryManager(int bufferSize, long capacity = 0x4000000L) { long num = capacity / ((long)bufferSize); int cellsCount = (int)Math.Min(0x2000L, num); _memoryPool = new MemoryPool(cellsCount, bufferSize); }
public void CreateDriver(MemoryPool pool, bool isPlayer) { if (isPlayer) { //pool.Add(new MemoryFieldLazy<float>("", MemoryAddress.Static, 0, 4)); // I can now add tyre temperatures, pressure, brake info etc. pool.Add(new MemoryFieldConstant<bool>("IsPlayer", true)); pool.Add(new MemoryFieldLazy<double>("EngineLifetime", MemoryAddress.Static, 0x006DC0AC, 8)); pool.Add(new MemoryFieldLazy<double>("EngineOil", MemoryAddress.Static, 0x006DC044, 8, Conversions.Kelvin2Celsius)); pool.Add(new MemoryFieldLazy<double>("EngineWater", MemoryAddress.Static, 0x006DC084, 8, Conversions.Kelvin2Celsius)); pool.Add(new MemoryFieldLazy<byte>("EngineMode", MemoryAddress.Static, 0x006DBF70, 1)); pool.Add(new MemoryFieldLazy<byte>("EngineTorque", MemoryAddress.Static, 0x006DC224, 1)); pool.Add(new MemoryFieldLazy<int>("FuelStop1", MemoryAddress.Static, 0x006E1EAC, 4)); pool.Add(new MemoryFieldLazy<int>("FuelStop1", MemoryAddress.Static, 0x006E1EEC, 4)); pool.Add(new MemoryFieldLazy<int>("FuelStop1", MemoryAddress.Static, 0x006E1F2C, 4)); pool.Add(new MemoryFieldLazy<double>("RideheightLF", MemoryAddress.Static, 0x006DB778, 8)); pool.Add(new MemoryFieldLazy<double>("RideheightRF", MemoryAddress.Static, 0x006DB780, 8)); pool.Add(new MemoryFieldLazy<double>("RideheightLR", MemoryAddress.Static, 0x006DB788, 8)); pool.Add(new MemoryFieldLazy<double>("RideheightRR", MemoryAddress.Static, 0x006DB790, 8)); pool.Add(new MemoryFieldLazy<string>("TyreCompoundFront", MemoryAddress.Static, 0x006E1177, 16)); pool.Add(new MemoryFieldLazy<string>("TyreCompoundRear", MemoryAddress.Static, 0x006E11B7, 16)); pool.Add(new MemoryFieldLazy<double>("TyrePressureLF", MemoryAddress.Static, 0x006D9F5C, 8)); pool.Add(new MemoryFieldLazy<double>("TyrePressureRF", MemoryAddress.Static, 0x006DA55C, 8)); pool.Add(new MemoryFieldLazy<double>("TyrePressureLR", MemoryAddress.Static, 0x006DAB5C, 8)); pool.Add(new MemoryFieldLazy<double>("TyrePressureRR", MemoryAddress.Static, 0x006DB15C, 8)); pool.Add(new MemoryFieldLazy<double>("TyreSpeedLF", MemoryAddress.Static, 0x006D9C04, 8)); pool.Add(new MemoryFieldLazy<double>("TyreSpeedRF", MemoryAddress.Static, 0x006DA204, 8)); pool.Add(new MemoryFieldLazy<double>("TyreSpeedLR", MemoryAddress.Static, 0x006DA804, 8)); pool.Add(new MemoryFieldLazy<double>("TyreSpeedRR", MemoryAddress.Static, 0x006DAE04, 8)); pool.Add(new MemoryFieldLazy<double>("TyreTemperatureInsideLF", MemoryAddress.Static, 0x006D9F44, 8)); pool.Add(new MemoryFieldLazy<double>("TyreTemperatureInsideRF", MemoryAddress.Static, 0x006DA534, 8)); pool.Add(new MemoryFieldLazy<double>("TyreTemperatureInsideLR", MemoryAddress.Static, 0x006DAB44, 8)); pool.Add(new MemoryFieldLazy<double>("TyreTemperatureInsideRR", MemoryAddress.Static, 0x006DB134, 8)); pool.Add(new MemoryFieldLazy<double>("TyreTemperatureMiddleLF", MemoryAddress.Static, 0x006D9F3C, 8)); pool.Add(new MemoryFieldLazy<double>("TyreTemperatureMiddleRF", MemoryAddress.Static, 0x006DA53C, 8)); pool.Add(new MemoryFieldLazy<double>("TyreTemperatureMiddleLR", MemoryAddress.Static, 0x006DAB3C, 8)); pool.Add(new MemoryFieldLazy<double>("TyreTemperatureMiddleRR", MemoryAddress.Static, 0x006DB13C, 8)); pool.Add(new MemoryFieldLazy<double>("TyreTemperatureOutsideLF", MemoryAddress.Static, 0x006D9F34, 8)); pool.Add(new MemoryFieldLazy<double>("TyreTemperatureOutsideRF", MemoryAddress.Static, 0x006DA544, 8)); pool.Add(new MemoryFieldLazy<double>("TyreTemperatureOutsideLR", MemoryAddress.Static, 0x006DAB34, 8)); pool.Add(new MemoryFieldLazy<double>("TyreTemperatureOutsideRR", MemoryAddress.Static, 0x006DB144, 8)); pool.Add(new MemoryFieldLazy<int>("AerodyanmicFrontwingSetting", MemoryAddress.Static, 0x006E182C, 4)); pool.Add(new MemoryFieldLazy<int>("AerodyanmicRearwingSetting", MemoryAddress.Static, 0x006E186C, 4)); pool.Add(new MemoryFieldLazy<int>("AerodyanmicRadiatorSetting", MemoryAddress.Static, 0x006E18AC, 4)); pool.Add(new MemoryFieldLazy<int>("AerodyanmicBrakeductSetting", MemoryAddress.Static, 0x006E18EC, 4)); pool.Add(new MemoryFieldLazy<double>("BrakeTemperatureLF", MemoryAddress.Static, 0x006DA0E0, 8)); pool.Add(new MemoryFieldLazy<double>("BrakeTemperatureRF", MemoryAddress.Static, 0x006DA6E0, 8)); pool.Add(new MemoryFieldLazy<double>("BrakeTemperatureLR", MemoryAddress.Static, 0x006DACE0, 8)); pool.Add(new MemoryFieldLazy<double>("BrakeTemperatureRR", MemoryAddress.Static, 0x006DB2E0, 8)); pool.Add(new MemoryFieldLazy<double>("BrakeThicknessLF", MemoryAddress.Static, 0x006DA110, 8)); pool.Add(new MemoryFieldLazy<double>("BrakeThicknessRF", MemoryAddress.Static, 0x006DA710, 8)); pool.Add(new MemoryFieldLazy<double>("BrakeThicknessLR", MemoryAddress.Static, 0x006DAD10, 8)); pool.Add(new MemoryFieldLazy<double>("BrakeThicknessRR", MemoryAddress.Static, 0x006DB310, 8)); pool.Add(new MemoryFieldLazy<double>("InputClutch", MemoryAddress.Static, 0x006D9744, 8)); pool.Add(new MemoryFieldLazy<double>("InputSteering", MemoryAddress.Static, 0x006D972C, 8)); pool.Add(new MemoryFieldLazy<byte>("HelpsABS", MemoryAddress.Static, 0x006D9786, 1)); pool.Add(new MemoryFieldLazy<byte>("HelpsTC", MemoryAddress.Static, 0x006D977E, 1)); pool.Add(new MemoryFieldLazy<byte>("HelpsSteer", MemoryAddress.Static, 0x006D9785, 1)); pool.Add(new MemoryFieldLazy<bool>("HelpsLock", MemoryAddress.Static, 0x006D9784, 1)); pool.Add(new MemoryFieldLazy<bool>("HelpsSpin", MemoryAddress.Static, 0x006D9787, 1)); pool.Add(new MemoryFieldLazy<bool>("HelpsStability", MemoryAddress.Static, 0x006D9780, 1)); pool.Add(new MemoryFieldLazy<bool>("HelpsClutch", MemoryAddress.Static, 0x006D9785, 1)); //pool.Add(new MemoryFieldLazy<byte>("HelpsShift", MemoryAddress.Static, 0x006D9782, 1)); } else pool.Add(new MemoryFieldConstant<bool>("IsPlayer", false)); }