Merge remote-tracking branch 'origin/Untrusted' into Untrusted

This commit is contained in:
2025-05-14 12:58:29 +03:00
29 changed files with 87 additions and 210 deletions
+3 -3
View File
@@ -30,11 +30,11 @@ class Program
builder.Modules.Add(new CreativeRepresentationModuleProducer( builder.Modules.Add(new CreativeRepresentationModuleProducer(
new IInjectableModule[] { builder.GetModule<IContextualSerializationToolKit>()! }, new IInjectableModule[] { builder.GetModule<IContextualSerializationToolKit>()! },
typeof(RepresentationModule))); typeof(RepresentationModule)));
builder.Modules.Add(new RemoteContextRepository()); builder.Modules.Add(new RemoteInstanceRepository());
// builder.UseCollectableContextRepository(typeof(PrinterFactory).Assembly); // builder.UseCollectableContextRepository(typeof(PrinterFactory).Assembly);
builder.Modules.Add(new MultiClientContextRepository(i => builder.Modules.Add(new MultiClientInstanceRepository(i =>
{ {
var repo = new ContextRepository(); var repo = new InstanceRepository();
repo.FillSingletons(typeof(PrinterFactory).Assembly); repo.FillSingletons(typeof(PrinterFactory).Assembly);
repo.Inject(builder.Modules.OfType<CreativeRepresentationModuleProducer>().First()); repo.Inject(builder.Modules.OfType<CreativeRepresentationModuleProducer>().First());
return repo; return repo;
+18 -16
View File
@@ -1,6 +1,6 @@
using System; using System;
using System.Diagnostics;
using System.Net; using System.Net;
using System.Net.Sockets;
using System.Text; using System.Text;
using System.Threading; using System.Threading;
using System.Threading.Tasks; using System.Threading.Tasks;
@@ -23,7 +23,7 @@ class Program
builder.Modules.Add(new CborSerializationToolkit()); builder.Modules.Add(new CborSerializationToolkit());
builder.Modules.Add(new EndPointContext()); builder.Modules.Add(new EndPointContext());
builder.Modules.Add(new RemoteContextRepository()); builder.Modules.Add(new RemoteInstanceRepository());
builder.Modules.Add(new ChannelInteractionModule()); builder.Modules.Add(new ChannelInteractionModule());
builder.Modules.Add(new UdpUntrustedInteraction()); builder.Modules.Add(new UdpUntrustedInteraction());
builder.Modules.Add(new RepresentationModule()); builder.Modules.Add(new RepresentationModule());
@@ -43,7 +43,7 @@ class Program
_ = builder.GetModule<RequestExtractor>()!.StartExtraction(); _ = builder.GetModule<RequestExtractor>()!.StartExtraction();
_ = builder.GetModule<UdpUntrustedInteraction>().Start(serverEndPoint); _ = builder.GetModule<UdpUntrustedInteraction>().Start(serverEndPoint);
Console.WriteLine(builder.GetModule<IEndPointContext>().HostId); Console.WriteLine(builder.GetModule<IEndPointContext>().HostId);
var context = builder.GetModule<RemoteContextRepository>(); var context = builder.GetModule<RemoteInstanceRepository>();
var factory = var factory =
context.GetSingleObject(typeof(IPrinterFactory), context.GetSingleObject(typeof(IPrinterFactory),
@@ -126,23 +126,25 @@ class Program
Console.WriteLine($"Token state {cts.Token.IsCancellationRequested}"); Console.WriteLine($"Token state {cts.Token.IsCancellationRequested}");
DemoCheck.TaskCancelation = true; DemoCheck.TaskCancelation = true;
const int iterations = 10000;
var timer = Stopwatch.StartNew();
var x = 0;
for (int i = 0; i < iterations; i++)
{
x = loadSingleton.Next(x);
}
timer.Stop();
Console.WriteLine("X is {0}", x);
Console.WriteLine("Time : {0}", timer.Elapsed.TotalMilliseconds);
Console.WriteLine($"Time per call: {timer.Elapsed.TotalMilliseconds / iterations} ms");
frontendBridge.Disconnect(); frontendBridge.Disconnect();
DemoCheck.Show(); DemoCheck.Show();
Console.ReadKey(); Console.ReadKey();
//
// const int iterations = 10000;
// var timer = Stopwatch.StartNew();
// var x = 0;
// for (int i = 0; i < iterations; i++)
// {
// x = loadSingleton.Next(x);
// }
//
// timer.Stop();
// Console.WriteLine("X is {0}", x);
// Console.WriteLine("Time : {0}", timer.Elapsed.TotalMilliseconds);
// Console.WriteLine($"Time per call: {timer.Elapsed.TotalMilliseconds / iterations} ms");
} }
} }
+2 -2
View File
@@ -11,11 +11,11 @@ namespace mROA.Codegen
public sealed class RemoteTypeBinder public sealed class RemoteTypeBinder
{ {
static RemoteTypeBinder(){ static RemoteTypeBinder(){
RemoteContextRepository.RemoteTypes = new Dictionary<Type, Type> { RemoteInstanceRepository.RemoteTypes = new Dictionary<Type, Type> {
<!I remoteTypePair r sep typesSep><!D typesSep>, <!I remoteTypePair r sep typesSep><!D typesSep>,
<!D> <!D>
}; };
ContextRepository.EventBinders = new object[] { InstanceRepository.EventBinders = new object[] {
<!I eventBinder r sep typesSep> <!I eventBinder r sep typesSep>
<!T objectBinderTemplate> <!T objectBinderTemplate>
new EventBinder<<!L type>> new EventBinder<<!L type>>
@@ -1,5 +1,4 @@
using System; using System;
using System.IO;
using System.Threading.Channels; using System.Threading.Channels;
using System.Threading.Tasks; using System.Threading.Tasks;
using mROA.Implementation; using mROA.Implementation;
@@ -9,7 +8,6 @@ namespace mROA.Abstract
public interface IChannelInteractionModule : IInjectableModule, IDisposable public interface IChannelInteractionModule : IInjectableModule, IDisposable
{ {
int ConnectionId { get; set; } int ConnectionId { get; set; }
IEndPointContext Context { get; set; }
Channel<NetworkMessageHeader> ReceiveChanel { get; } Channel<NetworkMessageHeader> ReceiveChanel { get; }
ChannelReader<NetworkMessageHeader> TrustedPostChanel { get; } ChannelReader<NetworkMessageHeader> TrustedPostChanel { get; }
ChannelReader<NetworkMessageHeader> UntrustedPostChanel { get; } ChannelReader<NetworkMessageHeader> UntrustedPostChanel { get; }
+1 -1
View File
@@ -2,7 +2,7 @@ namespace mROA.Abstract
{ {
public interface IContextRepositoryHub public interface IContextRepositoryHub
{ {
IContextRepository GetRepository(int clientId); IInstanceRepository GetRepository(int clientId);
void FreeRepository(int clientId); void FreeRepository(int clientId);
} }
} }
+2 -2
View File
@@ -2,8 +2,8 @@
{ {
public interface IEndPointContext : IInjectableModule public interface IEndPointContext : IInjectableModule
{ {
IContextRepository RealRepository { get; } IInstanceRepository RealRepository { get; }
IContextRepository RemoteRepository { get; } IInstanceRepository RemoteRepository { get; }
int HostId { get; set; } int HostId { get; set; }
int OwnerId { get; set; } int OwnerId { get; set; }
} }
+1 -1
View File
@@ -4,7 +4,7 @@ namespace mROA.Abstract
{ {
public interface IExecuteModule : IInjectableModule public interface IExecuteModule : IInjectableModule
{ {
ICommandExecution Execute(ICallRequest command, IContextRepository contextRepository, ICommandExecution Execute(ICallRequest command, IInstanceRepository instanceRepository,
IRepresentationModule representationModule, IEndPointContext context); IRepresentationModule representationModule, IEndPointContext context);
} }
} }
@@ -3,9 +3,8 @@ using mROA.Implementation;
namespace mROA.Abstract namespace mROA.Abstract
{ {
public interface IContextRepository : IInjectableModule public interface IInstanceRepository : IInjectableModule
{ {
int HostId { get; set; }
int ResisterObject<T>(object o, IEndPointContext context); int ResisterObject<T>(object o, IEndPointContext context);
void ClearObject(ComplexObjectIdentifier id, IEndPointContext context); void ClearObject(ComplexObjectIdentifier id, IEndPointContext context);
T GetObject<T>(ComplexObjectIdentifier id, IEndPointContext context); T GetObject<T>(ComplexObjectIdentifier id, IEndPointContext context);
+1 -3
View File
@@ -1,6 +1,4 @@
using System; namespace mROA.Abstract
namespace mROA.Abstract
{ {
// public interface IContextualSerializationToolKit : IInjectableModule // public interface IContextualSerializationToolKit : IInjectableModule
// { // {
-1
View File
@@ -1,5 +1,4 @@
using System; using System;
using System.Net;
using System.Threading.Tasks; using System.Threading.Tasks;
namespace mROA.Abstract namespace mROA.Abstract
@@ -21,7 +21,7 @@ namespace mROA.Implementation.Backend
public static void UseCollectableContextRepository(this FullMixBuilder builder, params Assembly[] assemblies) public static void UseCollectableContextRepository(this FullMixBuilder builder, params Assembly[] assemblies)
{ {
var repo = new ContextRepository(); var repo = new InstanceRepository();
repo.FillSingletons(assemblies); repo.FillSingletons(assemblies);
builder.Modules.Add(repo); builder.Modules.Add(repo);
} }
@@ -27,13 +27,13 @@ namespace mROA.Implementation.Backend
} }
} }
public ICommandExecution Execute(ICallRequest command, IContextRepository contextRepository, public ICommandExecution Execute(ICallRequest command, IInstanceRepository instanceRepository,
IRepresentationModule representationModule, IEndPointContext endPointContext) IRepresentationModule representationModule, IEndPointContext endPointContext)
{ {
try try
{ {
ThrowIfNotInjected(contextRepository); ThrowIfNotInjected(instanceRepository);
if (command is CancelRequest) if (command is CancelRequest)
{ {
return CancelExecution(command); return CancelExecution(command);
@@ -43,7 +43,7 @@ namespace mROA.Implementation.Backend
if (invoker == null) if (invoker == null)
throw new Exception($"Command {command.CommandId} not found"); throw new Exception($"Command {command.CommandId} not found");
var context = GetContext(command, contextRepository, invoker, endPointContext); var context = GetContext(command, instanceRepository, invoker, endPointContext);
if (context == null) if (context == null)
throw new NullReferenceException("Instance can't be null"); throw new NullReferenceException("Instance can't be null");
@@ -70,7 +70,7 @@ namespace mROA.Implementation.Backend
var result = Execute((invoker as MethodInvoker)!, context, castedParams!, command, execContext); var result = Execute((invoker as MethodInvoker)!, context, castedParams!, command, execContext);
if (command.CommandId == -1) if (command.CommandId == -1)
{ {
contextRepository.ClearObject(command.ObjectId, endPointContext); instanceRepository.ClearObject(command.ObjectId, endPointContext);
} }
return result; return result;
@@ -86,12 +86,12 @@ namespace mROA.Implementation.Backend
} }
} }
private static object GetContext(ICallRequest command, IContextRepository contextRepository, private static object GetContext(ICallRequest command, IInstanceRepository instanceRepository,
IMethodInvoker invoker, IEndPointContext endPointContext) IMethodInvoker invoker, IEndPointContext endPointContext)
{ {
var context = command.ObjectId.ContextId != -1 var context = command.ObjectId.ContextId != -1
? contextRepository.GetObject<object>(command.ObjectId, endPointContext) ? instanceRepository.GetObject<object>(command.ObjectId, endPointContext)
: contextRepository.GetSingleObject(invoker.SuitableType, endPointContext); : instanceRepository.GetSingleObject(invoker.SuitableType, endPointContext);
return context; return context;
} }
@@ -106,7 +106,7 @@ namespace mROA.Implementation.Backend
return castedParams; return castedParams;
} }
private void ThrowIfNotInjected(IContextRepository contextRepository) private void ThrowIfNotInjected(IInstanceRepository instanceRepository)
{ {
if (_cancellationRepo is null) if (_cancellationRepo is null)
throw new NullReferenceException("Method repository was not defined"); throw new NullReferenceException("Method repository was not defined");
@@ -114,7 +114,7 @@ namespace mROA.Implementation.Backend
if (_methodRepo is null) if (_methodRepo is null)
throw new NullReferenceException("Method repository was not defined"); throw new NullReferenceException("Method repository was not defined");
if (contextRepository is null) if (instanceRepository is null)
throw new NullReferenceException("Context repository was not defined"); throw new NullReferenceException("Context repository was not defined");
} }
@@ -7,8 +7,8 @@ namespace mROA.Implementation.Backend
{ {
private IConnectionHub? _hub; private IConnectionHub? _hub;
private IContextRepository? _contextRepository; private IInstanceRepository? _contextRepository;
private IContextRepository? _remoteContextRepository; private IInstanceRepository? _remoteContextRepository;
private IMethodRepository? _methodRepository; private IMethodRepository? _methodRepository;
private IContextualSerializationToolKit? _serializationToolkit; private IContextualSerializationToolKit? _serializationToolkit;
private IExecuteModule? _executeModule; private IExecuteModule? _executeModule;
@@ -21,11 +21,11 @@ namespace mROA.Implementation.Backend
_hub = connectionHub; _hub = connectionHub;
_hub.OnConnected += HubOnOnConnected; _hub.OnConnected += HubOnOnConnected;
break; break;
case MultiClientContextRepository: case MultiClientInstanceRepository:
case ContextRepository: case InstanceRepository:
_contextRepository = dependency as IContextRepository; _contextRepository = dependency as IInstanceRepository;
break; break;
case RemoteContextRepository remoteContextRepository: case RemoteInstanceRepository remoteContextRepository:
_remoteContextRepository = remoteContextRepository; _remoteContextRepository = remoteContextRepository;
break; break;
case IMethodRepository methodRepository: case IMethodRepository methodRepository:
@@ -2,13 +2,12 @@
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Reflection; using System.Reflection;
using System.Threading.Tasks;
using mROA.Abstract; using mROA.Abstract;
using mROA.Implementation.Attributes; using mROA.Implementation.Attributes;
namespace mROA.Implementation.Backend namespace mROA.Implementation.Backend
{ {
public class ContextRepository : IContextRepository public class InstanceRepository : IInstanceRepository
{ {
public static object[] EventBinders = { }; public static object[] EventBinders = { };
@@ -22,7 +21,7 @@ namespace mROA.Implementation.Backend
private IStorage<object> _storage; private IStorage<object> _storage;
public ContextRepository() public InstanceRepository()
{ {
_storage = new ExtensibleStorage<object>(); _storage = new ExtensibleStorage<object>();
} }
@@ -4,12 +4,12 @@ using mROA.Abstract;
namespace mROA.Implementation.Backend namespace mROA.Implementation.Backend
{ {
public class MultiClientContextRepository : IContextRepository, IContextRepositoryHub public class MultiClientInstanceRepository : IInstanceRepository, IContextRepositoryHub
{ {
private readonly Func<int, IContextRepository> _produceRepository; private readonly Func<int, IInstanceRepository> _produceRepository;
private readonly Dictionary<int, IContextRepository> _repositories = new(); private readonly Dictionary<int, IInstanceRepository> _repositories = new();
public MultiClientContextRepository(Func<int, IContextRepository> produceRepository) public MultiClientInstanceRepository(Func<int, IInstanceRepository> produceRepository)
{ {
_produceRepository = produceRepository; _produceRepository = produceRepository;
} }
@@ -50,7 +50,7 @@ namespace mROA.Implementation.Backend
return repository.GetObjectIndex<T>(o, context); return repository.GetObjectIndex<T>(o, context);
} }
public IContextRepository GetRepository(int clientId) public IInstanceRepository GetRepository(int clientId)
{ {
var repository = GetRepositoryByClientId(clientId); var repository = GetRepositoryByClientId(clientId);
return repository; return repository;
@@ -61,7 +61,7 @@ namespace mROA.Implementation.Backend
_repositories.Remove(clientId); _repositories.Remove(clientId);
} }
private IContextRepository GetRepositoryByClientId(int clientId) private IInstanceRepository GetRepositoryByClientId(int clientId)
{ {
if (_repositories.TryGetValue(clientId, out var repository)) if (_repositories.TryGetValue(clientId, out var repository))
return repository; return repository;
@@ -3,7 +3,6 @@ using System.Collections.Generic;
using System.Net; using System.Net;
using System.Net.Sockets; using System.Net.Sockets;
using System.Threading; using System.Threading;
using System.Threading.Channels;
using System.Threading.Tasks; using System.Threading.Tasks;
using mROA.Abstract; using mROA.Abstract;
@@ -3,7 +3,6 @@ using System.Collections.Generic;
using System.Net; using System.Net;
using System.Net.Sockets; using System.Net.Sockets;
using System.Threading; using System.Threading;
using System.Threading.Channels;
using System.Threading.Tasks; using System.Threading.Tasks;
using mROA.Abstract; using mROA.Abstract;
using static mROA.Implementation.EMessageType; using static mROA.Implementation.EMessageType;
+16 -26
View File
@@ -14,12 +14,11 @@ namespace mROA.Implementation
private readonly ChannelWriter<NetworkMessageHeader> _untrustedWriter; private readonly ChannelWriter<NetworkMessageHeader> _untrustedWriter;
private readonly Channel<NetworkMessageHeader> _outputTrustedChannel; private readonly Channel<NetworkMessageHeader> _outputTrustedChannel;
private readonly Channel<NetworkMessageHeader> _outputUntrustedChannel; private readonly Channel<NetworkMessageHeader> _outputUntrustedChannel;
private Task<NetworkMessageHeader>? _currentReceiving;
private IContextualSerializationToolKit? _serialization; private IContextualSerializationToolKit? _serialization;
private bool _isConnected = true; private bool _isConnected = true;
private bool _isActive = true; private bool _isActive = true;
private TaskCompletionSource<Stream> _reconnection; private TaskCompletionSource<Stream> _reconnection;
public IEndPointContext Context { get; set; } private IEndPointContext? _context;
public ChannelInteractionModule() public ChannelInteractionModule()
{ {
@@ -50,7 +49,7 @@ namespace mROA.Implementation
public ChannelReader<NetworkMessageHeader> TrustedPostChanel => _outputTrustedChannel.Reader; public ChannelReader<NetworkMessageHeader> TrustedPostChanel => _outputTrustedChannel.Reader;
public ChannelReader<NetworkMessageHeader> UntrustedPostChanel => _outputUntrustedChannel.Reader; public ChannelReader<NetworkMessageHeader> UntrustedPostChanel => _outputUntrustedChannel.Reader;
public Func<bool> IsConnected { get; set; } public Func<bool> IsConnected { get; set; } = () => false;
public void Inject<T>(T dependency) public void Inject<T>(T dependency)
{ {
@@ -63,7 +62,7 @@ namespace mROA.Implementation
ConnectionId = identityGenerator.GetNextIdentity(); ConnectionId = identityGenerator.GetNextIdentity();
break; break;
case IEndPointContext endpointContext: case IEndPointContext endpointContext:
Context = endpointContext; _context = endpointContext;
break; break;
} }
} }
@@ -93,8 +92,7 @@ namespace mROA.Implementation
{ {
if (_serialization == null) if (_serialization == null)
throw new NullReferenceException("Serialization toolkit is not initialized"); throw new NullReferenceException("Serialization toolkit is not initialized");
bool withError = false;
while (true) while (true)
{ {
if (await PostMessageInternal(messageHeader)) if (await PostMessageInternal(messageHeader))
@@ -106,8 +104,7 @@ namespace mROA.Implementation
} }
_isConnected = false; _isConnected = false;
withError = true; await MakeRecovery();
await MakeRecovery("OUT");
} }
} }
@@ -123,23 +120,21 @@ namespace mROA.Implementation
if (sendRecovery) if (sendRecovery)
{ {
await PostMessageAsync( await PostMessageAsync(
new NetworkMessageHeader(_serialization!, new ClientRecovery(Math.Abs(ConnectionId)), Context)); new NetworkMessageHeader(_serialization!, new ClientRecovery(Math.Abs(ConnectionId)), _context));
var ping = await ReceiveChanel.Reader.ReadAsync(); await ReceiveChanel.Reader.ReadAsync();
} }
else else
{ {
await _trustedWriter.WriteAsync(new NetworkMessageHeader()); await _trustedWriter.WriteAsync(new NetworkMessageHeader());
} }
var setting = _reconnection.TrySetResult(null); _reconnection.TrySetResult(Stream.Null);
// _isInReconnectionState = false;
_isConnected = true; _isConnected = true;
_reconnection = new TaskCompletionSource<Stream>(); _reconnection = new TaskCompletionSource<Stream>();
} }
private async Task MakeRecovery(string source) private async Task MakeRecovery()
{ {
//TODO переделать реконнект
lock (_reconnection) lock (_reconnection)
{ {
OnDisconnected?.Invoke(ConnectionId); OnDisconnected?.Invoke(ConnectionId);
@@ -154,10 +149,6 @@ namespace mROA.Implementation
public void Dispose() public void Dispose()
{ {
_isActive = false; _isActive = false;
if (_currentReceiving is { IsCompleted: true })
{
_currentReceiving?.Dispose();
}
} }
public class StreamExtractor public class StreamExtractor
@@ -167,15 +158,14 @@ namespace mROA.Implementation
private const int BufferSize = ushort.MaxValue; private const int BufferSize = ushort.MaxValue;
private readonly Memory<byte> _buffer = new byte[BufferSize]; private readonly Memory<byte> _buffer = new byte[BufferSize];
private bool _manualConnectionState = true; private bool _manualConnectionState = true;
private IEndPointContext Context; private readonly IEndPointContext _context;
public readonly int Id = new Random().Next();
public StreamExtractor(Stream ioStream, IContextualSerializationToolKit serializationToolkit, public StreamExtractor(Stream ioStream, IContextualSerializationToolKit serializationToolkit,
IEndPointContext context) IEndPointContext context)
{ {
_ioStream = ioStream; _ioStream = ioStream;
_serializationToolkit = serializationToolkit; _serializationToolkit = serializationToolkit;
Context = context; _context = context;
} }
public Action<NetworkMessageHeader> MessageReceived = _ => { }; public Action<NetworkMessageHeader> MessageReceived = _ => { };
@@ -197,14 +187,14 @@ namespace mROA.Implementation
return len; return len;
} }
public async Task SingleReceive(CancellationToken Token = default) public async Task SingleReceive(CancellationToken token = default)
{ {
var len = ReadMessageLength(); var len = ReadMessageLength();
var localSpan = _buffer[..len]; var localSpan = _buffer[..len];
await _ioStream.ReadExactlyAsync(localSpan, cancellationToken: Token); await _ioStream.ReadExactlyAsync(localSpan, cancellationToken: token);
var message = _serializationToolkit.Deserialize<NetworkMessageHeader>(localSpan, Context); var message = _serializationToolkit.Deserialize<NetworkMessageHeader>(localSpan, _context);
MessageReceived(message); MessageReceived(message);
} }
@@ -216,9 +206,9 @@ namespace mROA.Implementation
} }
} }
public async Task Send(NetworkMessageHeader message, CancellationToken token = default) private async Task Send(NetworkMessageHeader message, CancellationToken token = default)
{ {
var rawMessage = _serializationToolkit.Serialize(message, Context); var rawMessage = _serializationToolkit.Serialize(message, _context);
var header = BitConverter.GetBytes((ushort)rawMessage.Length).AsMemory(0, sizeof(ushort)); var header = BitConverter.GetBytes((ushort)rawMessage.Length).AsMemory(0, sizeof(ushort));
await _ioStream.WriteAsync(header, token); await _ioStream.WriteAsync(header, token);
@@ -5,7 +5,7 @@ using mROA.Abstract;
namespace mROA.Implementation namespace mROA.Implementation
{ {
public class ComplexContextRepository : IContextRepository public class ComplexInstanceRepository : IInstanceRepository
{ {
private List<KeyValuePair<int, ExtensibleStorage<object>>> _storages = new(); private List<KeyValuePair<int, ExtensibleStorage<object>>> _storages = new();
public static object[] EventBinders = { }; public static object[] EventBinders = { };
+4 -5
View File
@@ -1,4 +1,3 @@
using System;
using mROA.Abstract; using mROA.Abstract;
using mROA.Implementation.Backend; using mROA.Implementation.Backend;
@@ -6,8 +5,8 @@ namespace mROA.Implementation
{ {
public class EndPointContext : IEndPointContext public class EndPointContext : IEndPointContext
{ {
public IContextRepository RealRepository { get; set; } public IInstanceRepository RealRepository { get; set; }
public IContextRepository RemoteRepository { get; set; } public IInstanceRepository RemoteRepository { get; set; }
public int HostId { get; set; } public int HostId { get; set; }
public int OwnerId { get; set; } public int OwnerId { get; set; }
@@ -16,10 +15,10 @@ namespace mROA.Implementation
{ {
switch (dependency) switch (dependency)
{ {
case RemoteContextRepository remoteRepository: case RemoteInstanceRepository remoteRepository:
RemoteRepository = remoteRepository; RemoteRepository = remoteRepository;
break; break;
case ContextRepository realRepository: case InstanceRepository realRepository:
RealRepository = realRepository; RealRepository = realRepository;
break; break;
} }
+3 -2
View File
@@ -1,10 +1,11 @@
using System; using System;
using mROA.Abstract;
namespace mROA.Abstract namespace mROA.Implementation
{ {
public class EventBinder<T> : IEventBinder<T> public class EventBinder<T> : IEventBinder<T>
{ {
public Action<T, IEndPointContext, IRepresentationModuleProducer, int> BindAction { get; set; } public Action<T, IEndPointContext, IRepresentationModuleProducer, int> BindAction { get; set; } = (_, _, _, _) => { };
public void BindEvents(T source, IEndPointContext context, public void BindEvents(T source, IEndPointContext context,
IRepresentationModuleProducer representationModuleProducer, int index) IRepresentationModuleProducer representationModuleProducer, int index)
@@ -1,61 +0,0 @@
using System;
using System.Text.Json;
using mROA.Abstract;
namespace mROA.Implementation
{
// public class JsonSerializationToolkit : IContextualSerializationToolKit
// {
// public byte[] Serialize<T>(T objectToSerialize)
// {
// return JsonSerializer.SerializeToUtf8Bytes(objectToSerialize);
// }
//
// public byte[] Serialize(object objectToSerialize, Type type)
// {
// return JsonSerializer.SerializeToUtf8Bytes(objectToSerialize, type);
// }
//
// public T? Deserialize<T>(byte[] rawData)
// {
// return JsonSerializer.Deserialize<T>(rawData);
// }
//
// public object? Deserialize(byte[] rawData, Type type)
// {
// return JsonSerializer.Deserialize(rawData, type);
// }
//
// public T? Deserialize<T>(Span<byte> rawData)
// {
// return JsonSerializer.Deserialize<T>(rawData);
// }
//
// public object? Deserialize(Span<byte> rawData, Type type)
// {
// return JsonSerializer.Deserialize(rawData, type);
// }
//
// public T Cast<T>(object nonCasted)
// {
// return nonCasted switch
// {
// JsonElement jsonElement => jsonElement.Deserialize<T>()!,
// T casted => casted,
// _ => throw new JsonException("Cannot cast object to type " + typeof(T).FullName)
// };
// }
//
// public object Cast(object nonCasted, Type type)
// {
// if (nonCasted is JsonElement jsonElement)
// return jsonElement.Deserialize(type)!;
//
// throw new JsonException("Cannot cast object to type " + type.FullName);
// }
//
// public void Inject<T>(T dependency)
// {
// }
// }
}
+1 -1
View File
@@ -36,7 +36,7 @@ namespace mROA.Implementation
public bool IsTrusted { get; set; } = true; public bool IsTrusted { get; set; } = true;
public Type[] ParameterTypes { get; set; } = Type.EmptyTypes; public Type[] ParameterTypes { get; set; } = Type.EmptyTypes;
public Type? ReturnType { get; set; } public Type? ReturnType { get; set; }
public Type SuitableType { get; set; } public Type SuitableType { get; set; } = typeof(object);
public Action<object, object?[]?, object[], Action<object?>> Invoking { get; set; } = public Action<object, object?[]?, object[], Action<object?>> Invoking { get; set; } =
(_, _, _, post) => { post.Invoke(null); }; (_, _, _, post) => { post.Invoke(null); };
+1 -13
View File
@@ -1,7 +1,5 @@
using System; using System;
using System.Text.Json.Serialization;
using mROA.Abstract; using mROA.Abstract;
using mROA.Implementation.Attributes;
// ReSharper disable UnusedMember.Global // ReSharper disable UnusedMember.Global
@@ -9,7 +7,7 @@ namespace mROA.Implementation
{ {
public class NetworkMessageHeader public class NetworkMessageHeader
{ {
protected bool Equals(NetworkMessageHeader other) private bool Equals(NetworkMessageHeader other)
{ {
return Id.Equals(other.Id) && MessageType == other.MessageType; return Id.Equals(other.Id) && MessageType == other.MessageType;
} }
@@ -22,11 +20,6 @@ namespace mROA.Implementation
return Equals((NetworkMessageHeader)obj); return Equals((NetworkMessageHeader)obj);
} }
public override int GetHashCode()
{
return HashCode.Combine(Id, (int)MessageType);
}
public static readonly NetworkMessageHeader Null = new(); public static readonly NetworkMessageHeader Null = new();
public NetworkMessageHeader() public NetworkMessageHeader()
{ {
@@ -43,13 +36,8 @@ namespace mROA.Implementation
} }
public Guid Id { get; set; } public Guid Id { get; set; }
[JsonConverter(typeof(JsonStringEnumConverter))]
public EMessageType MessageType { get; set; } public EMessageType MessageType { get; set; }
public byte[] Data { get; set; } public byte[] Data { get; set; }
[JsonIgnore]
[SerializationIgnore]
public object Parced { get; set; }
} }
} }
@@ -5,7 +5,7 @@ using mROA.Abstract;
namespace mROA.Implementation namespace mROA.Implementation
{ {
public class RemoteContextRepository : IContextRepository public class RemoteInstanceRepository : IInstanceRepository
{ {
private List<RemoteObjectBase> _producedRemoteEndpoints = new(); private List<RemoteObjectBase> _producedRemoteEndpoints = new();
public static Dictionary<Type, Type> RemoteTypes = new(); public static Dictionary<Type, Type> RemoteTypes = new();
-1
View File
@@ -1,5 +1,4 @@
using System; using System;
using System.Net;
using System.Threading; using System.Threading;
using System.Threading.Tasks; using System.Threading.Tasks;
using mROA.Abstract; using mROA.Abstract;
@@ -5,6 +5,7 @@ using System.Runtime.CompilerServices;
using System.Threading; using System.Threading;
using System.Threading.Tasks; using System.Threading.Tasks;
using mROA.Abstract; using mROA.Abstract;
#pragma warning disable CS8602 // Dereference of a possibly null reference.
namespace mROA.Implementation namespace mROA.Implementation
{ {
+6 -4
View File
@@ -20,12 +20,14 @@ namespace mROA.Implementation
{ {
private ComplexObjectIdentifier _identifier = ComplexObjectIdentifier.Null; private ComplexObjectIdentifier _identifier = ComplexObjectIdentifier.Null;
private T _value; private T? _value;
// ReSharper disable once MemberCanBePrivate.Global // ReSharper disable once MemberCanBePrivate.Global
// ReSharper disable once UnusedMember.Global // ReSharper disable once UnusedMember.Global
public SharedObjectShellShell() public SharedObjectShellShell()
{ {
_value = default;
EndPointContext = new EndPointContext();
} }
// ReSharper disable once UnusedMember.Global // ReSharper disable once UnusedMember.Global
@@ -41,7 +43,7 @@ namespace mROA.Implementation
// ReSharper disable once MemberCanBePrivate.Global // ReSharper disable once MemberCanBePrivate.Global
public T Value public T Value
{ {
get => _value; get => _value!;
set set
{ {
_value = value; _value = value;
@@ -76,11 +78,11 @@ namespace mROA.Implementation
public object UniversalValue public object UniversalValue
{ {
get => _value; get => _value!;
set => _value = (T)value; set => _value = (T)value;
} }
private IContextRepository GetDefaultContextRepository() => private IInstanceRepository GetDefaultContextRepository() =>
(_identifier.OwnerId == EndPointContext.HostId (_identifier.OwnerId == EndPointContext.HostId
? EndPointContext.RealRepository ? EndPointContext.RealRepository
: EndPointContext.RemoteRepository) ?? : EndPointContext.RemoteRepository) ??
-35
View File
@@ -1,35 +0,0 @@
using System;
using mROA.Abstract;
namespace mROA.Implementation
{
#pragma warning disable CS8618, CS9264
public static class TransmissionConfig
{
#if TRACE
public static int TotalTransmittedBytes { get; set; }
#endif
// private static IContextRepository? _realContextRepository;
// private static IContextRepository? _remoteEndpointContextRepository;
// private static IOwnershipRepository? _ownershipRepository;
//
// public static IContextRepository RealContextRepository
// {
// get => _realContextRepository ?? throw new NullReferenceException("RealContextRepository is null");
// set => _realContextRepository = value;
// }
//
// public static IContextRepository RemoteEndpointContextRepository
// {
// get => _remoteEndpointContextRepository ??
// throw new NullReferenceException("RemoteEndpointContextRepository is null");
// set => _remoteEndpointContextRepository = value;
// }
//
// public static IOwnershipRepository OwnershipRepository
// {
// get => _ownershipRepository ?? throw new NullReferenceException("OwnershipRepository is null");
// set => _ownershipRepository = value;
// }
}
}