Untrusted channel exception solved
This commit is contained in:
@@ -17,6 +17,7 @@ namespace mROA.Codegen
|
|||||||
new mROA.Implementation.AsyncMethodInvoker
|
new mROA.Implementation.AsyncMethodInvoker
|
||||||
{
|
{
|
||||||
IsVoid = <!L isVoid>,
|
IsVoid = <!L isVoid>,
|
||||||
|
IsTrusted = <!L isTrusted>,
|
||||||
ReturnType = typeof(<!L returnType>),
|
ReturnType = typeof(<!L returnType>),
|
||||||
ParameterTypes = new Type[] { <!L parametersType> },
|
ParameterTypes = new Type[] { <!L parametersType> },
|
||||||
SuitableType = typeof(<!L suitableType>),
|
SuitableType = typeof(<!L suitableType>),
|
||||||
@@ -26,6 +27,7 @@ namespace mROA.Codegen
|
|||||||
new mROA.Implementation.MethodInvoker
|
new mROA.Implementation.MethodInvoker
|
||||||
{
|
{
|
||||||
IsVoid = <!L isVoid>,
|
IsVoid = <!L isVoid>,
|
||||||
|
IsTrusted = <!L isTrusted>,
|
||||||
ReturnType = typeof(<!L returnType>),
|
ReturnType = typeof(<!L returnType>),
|
||||||
ParameterTypes = new Type[] { <!L parametersType> },
|
ParameterTypes = new Type[] { <!L parametersType> },
|
||||||
SuitableType = typeof(<!L suitableType>),
|
SuitableType = typeof(<!L suitableType>),
|
||||||
|
|||||||
@@ -380,6 +380,7 @@ namespace mROA.Codegen
|
|||||||
invokerTemplate.AddDefine("parametersType", parameterTypes);
|
invokerTemplate.AddDefine("parametersType", parameterTypes);
|
||||||
invokerTemplate.AddDefine("suitableType", baseInterace.ToUnityString());
|
invokerTemplate.AddDefine("suitableType", baseInterace.ToUnityString());
|
||||||
invokerTemplate.AddDefine("funcInvoking", funcInvoking);
|
invokerTemplate.AddDefine("funcInvoking", funcInvoking);
|
||||||
|
invokerTemplate.AddDefine("isTrusted", (!isUntrusted).ToString().ToLower());
|
||||||
backend = invokerTemplate.Compile();
|
backend = invokerTemplate.Compile();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@@ -390,6 +391,7 @@ namespace mROA.Codegen
|
|||||||
invokerTemplate.AddDefine("parametersType", parameterTypes);
|
invokerTemplate.AddDefine("parametersType", parameterTypes);
|
||||||
invokerTemplate.AddDefine("suitableType", baseInterace.ToUnityString());
|
invokerTemplate.AddDefine("suitableType", baseInterace.ToUnityString());
|
||||||
invokerTemplate.AddDefine("funcInvoking", funcInvoking);
|
invokerTemplate.AddDefine("funcInvoking", funcInvoking);
|
||||||
|
invokerTemplate.AddDefine("isTrusted", (!isUntrusted).ToString().ToLower());
|
||||||
backend = invokerTemplate.Compile();
|
backend = invokerTemplate.Compile();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -474,6 +476,7 @@ namespace mROA.Codegen
|
|||||||
invokerTemplate.AddDefine("parametersType", parameterTypes);
|
invokerTemplate.AddDefine("parametersType", parameterTypes);
|
||||||
invokerTemplate.AddDefine("suitableType", baseInterface.ToUnityString());
|
invokerTemplate.AddDefine("suitableType", baseInterface.ToUnityString());
|
||||||
invokerTemplate.AddDefine("funcInvoking", funcInvoking);
|
invokerTemplate.AddDefine("funcInvoking", funcInvoking);
|
||||||
|
invokerTemplate.AddDefine("isTrusted", "true");
|
||||||
var backend = invokerTemplate.Compile();
|
var backend = invokerTemplate.Compile();
|
||||||
_methodRepoTemplate.Insert("invoker", backend);
|
_methodRepoTemplate.Insert("invoker", backend);
|
||||||
|
|
||||||
@@ -507,6 +510,8 @@ namespace mROA.Codegen
|
|||||||
invokerTemplate.AddDefine("suitableType", baseInterace.ToUnityString());
|
invokerTemplate.AddDefine("suitableType", baseInterace.ToUnityString());
|
||||||
invokerTemplate.AddDefine("funcInvoking",
|
invokerTemplate.AddDefine("funcInvoking",
|
||||||
$"(i as {method.ContainingType.ToUnityString()})[{parameterInserts}]");
|
$"(i as {method.ContainingType.ToUnityString()})[{parameterInserts}]");
|
||||||
|
invokerTemplate.AddDefine("isTrusted", "true");
|
||||||
|
|
||||||
backend = invokerTemplate.Compile();
|
backend = invokerTemplate.Compile();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@@ -517,6 +522,8 @@ namespace mROA.Codegen
|
|||||||
invokerTemplate.AddDefine("suitableType", baseInterace.ToUnityString());
|
invokerTemplate.AddDefine("suitableType", baseInterace.ToUnityString());
|
||||||
invokerTemplate.AddDefine("funcInvoking",
|
invokerTemplate.AddDefine("funcInvoking",
|
||||||
$"(i as {method.ContainingType.ToUnityString()}).{(method.AssociatedSymbol as IPropertySymbol)!.Name}");
|
$"(i as {method.ContainingType.ToUnityString()}).{(method.AssociatedSymbol as IPropertySymbol)!.Name}");
|
||||||
|
invokerTemplate.AddDefine("isTrusted", "true");
|
||||||
|
|
||||||
backend = invokerTemplate.Compile();
|
backend = invokerTemplate.Compile();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -547,6 +554,8 @@ namespace mROA.Codegen
|
|||||||
invokerTemplate.AddDefine("suitableType", baseInterace.ToUnityString());
|
invokerTemplate.AddDefine("suitableType", baseInterace.ToUnityString());
|
||||||
invokerTemplate.AddDefine("funcInvoking",
|
invokerTemplate.AddDefine("funcInvoking",
|
||||||
$"(i as {method.ContainingType.ToUnityString()})[{parameterInserts}] = {valueInsert}");
|
$"(i as {method.ContainingType.ToUnityString()})[{parameterInserts}] = {valueInsert}");
|
||||||
|
invokerTemplate.AddDefine("isTrusted", "true");
|
||||||
|
|
||||||
backend = invokerTemplate.Compile();
|
backend = invokerTemplate.Compile();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@@ -560,6 +569,8 @@ namespace mROA.Codegen
|
|||||||
invokerTemplate.AddDefine("suitableType", baseInterace.ToUnityString());
|
invokerTemplate.AddDefine("suitableType", baseInterace.ToUnityString());
|
||||||
invokerTemplate.AddDefine("funcInvoking",
|
invokerTemplate.AddDefine("funcInvoking",
|
||||||
$"(i as {method.ContainingType.ToUnityString()}).{(method.AssociatedSymbol as IPropertySymbol)!.Name} = {Caster((method.AssociatedSymbol as IPropertySymbol)!.Type, "parameters[0]")}");
|
$"(i as {method.ContainingType.ToUnityString()}).{(method.AssociatedSymbol as IPropertySymbol)!.Name} = {Caster((method.AssociatedSymbol as IPropertySymbol)!.Type, "parameters[0]")}");
|
||||||
|
invokerTemplate.AddDefine("isTrusted", "true");
|
||||||
|
|
||||||
backend = invokerTemplate.Compile();
|
backend = invokerTemplate.Compile();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ namespace mROA.Abstract
|
|||||||
public interface IMethodInvoker
|
public interface IMethodInvoker
|
||||||
{
|
{
|
||||||
bool IsVoid { get; }
|
bool IsVoid { get; }
|
||||||
|
bool IsTrusted { get; }
|
||||||
Type[] ParameterTypes { get; }
|
Type[] ParameterTypes { get; }
|
||||||
Type? ReturnType { get; }
|
Type? ReturnType { get; }
|
||||||
Type SuitableType { get; }
|
Type SuitableType { get; }
|
||||||
|
|||||||
@@ -95,7 +95,8 @@ namespace mROA.Implementation.Backend
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static object GetContext(ICallRequest command, IContextRepository contextRepository, IMethodInvoker invoker)
|
private static object GetContext(ICallRequest command, IContextRepository contextRepository,
|
||||||
|
IMethodInvoker invoker)
|
||||||
{
|
{
|
||||||
var context = command.ObjectId.ContextId != -1
|
var context = command.ObjectId.ContextId != -1
|
||||||
? contextRepository.GetObject<object>(command.ObjectId)
|
? contextRepository.GetObject<object>(command.ObjectId)
|
||||||
@@ -147,7 +148,12 @@ namespace mROA.Implementation.Backend
|
|||||||
{
|
{
|
||||||
var finalResult = invoker.Invoke(instance, parameter, new object[] { executionContext });
|
var finalResult = invoker.Invoke(instance, parameter, new object[] { executionContext });
|
||||||
|
|
||||||
if (invoker.IsVoid)
|
if (!invoker.IsTrusted)
|
||||||
|
{
|
||||||
|
return new AsyncCommandExecution();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (invoker.IsVoid )
|
||||||
{
|
{
|
||||||
return new FinalCommandExecution
|
return new FinalCommandExecution
|
||||||
{
|
{
|
||||||
@@ -163,10 +169,15 @@ namespace mROA.Implementation.Backend
|
|||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
return new ExceptionCommandExecution
|
if (invoker.IsTrusted)
|
||||||
|
return new ExceptionCommandExecution
|
||||||
|
{
|
||||||
|
Id = command.Id,
|
||||||
|
Exception = e.ToString()
|
||||||
|
};
|
||||||
|
return new AsyncCommandExecution
|
||||||
{
|
{
|
||||||
Id = command.Id,
|
Id = command.Id
|
||||||
Exception = e.ToString()
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -198,7 +209,9 @@ namespace mROA.Implementation.Backend
|
|||||||
TransmissionConfig.OwnershipRepository as MultiClientOwnershipRepository;
|
TransmissionConfig.OwnershipRepository as MultiClientOwnershipRepository;
|
||||||
|
|
||||||
multiClientOwnershipRepository?.RegisterOwnership(representationModule.Id);
|
multiClientOwnershipRepository?.RegisterOwnership(representationModule.Id);
|
||||||
representationModule.PostCallMessage(command.Id, EMessageType.FinishedCommandExecution, payload);
|
if (invoker.IsTrusted)
|
||||||
|
representationModule.PostCallMessage(command.Id, EMessageType.FinishedCommandExecution,
|
||||||
|
payload);
|
||||||
multiClientOwnershipRepository?.FreeOwnership();
|
multiClientOwnershipRepository?.FreeOwnership();
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -209,10 +222,15 @@ namespace mROA.Implementation.Backend
|
|||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
return new ExceptionCommandExecution
|
if (invoker.IsTrusted)
|
||||||
|
return new ExceptionCommandExecution
|
||||||
|
{
|
||||||
|
Id = command.Id,
|
||||||
|
Exception = e.ToString()
|
||||||
|
};
|
||||||
|
return new AsyncCommandExecution
|
||||||
{
|
{
|
||||||
Id = command.Id,
|
Id = command.Id
|
||||||
Exception = e.ToString()
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ using System.Threading;
|
|||||||
using System.Threading.Channels;
|
using System.Threading.Channels;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using mROA.Abstract;
|
using mROA.Abstract;
|
||||||
|
using static mROA.Implementation.EMessageType;
|
||||||
|
|
||||||
namespace mROA.Implementation.Backend
|
namespace mROA.Implementation.Backend
|
||||||
{
|
{
|
||||||
@@ -56,7 +57,7 @@ namespace mROA.Implementation.Backend
|
|||||||
int channelId;
|
int channelId;
|
||||||
switch (parsed.MessageType)
|
switch (parsed.MessageType)
|
||||||
{
|
{
|
||||||
case EMessageType.UntrustedConnect:
|
case UntrustedConnect:
|
||||||
channelId = BitConverter.ToInt32(parsed.Data);
|
channelId = BitConverter.ToInt32(parsed.Data);
|
||||||
_reservedPorts[incoming.RemoteEndPoint] = channelId;
|
_reservedPorts[incoming.RemoteEndPoint] = channelId;
|
||||||
_ = UntrustedSend(_hub.GetInteraction(channelId), incoming.RemoteEndPoint);
|
_ = UntrustedSend(_hub.GetInteraction(channelId), incoming.RemoteEndPoint);
|
||||||
@@ -82,6 +83,10 @@ namespace mROA.Implementation.Backend
|
|||||||
{
|
{
|
||||||
await foreach (var post in interaction.UntrustedPostChanel.ReadAllAsync())
|
await foreach (var post in interaction.UntrustedPostChanel.ReadAllAsync())
|
||||||
{
|
{
|
||||||
|
if (post.MessageType is not (CallRequest or EMessageType.CancelRequest
|
||||||
|
or EventRequest))
|
||||||
|
continue;
|
||||||
|
|
||||||
var parsed = _serializationToolkit.Serialize(post);
|
var parsed = _serializationToolkit.Serialize(post);
|
||||||
await _client.SendAsync(parsed, parsed.Length, endpoint);
|
await _client.SendAsync(parsed, parsed.Length, endpoint);
|
||||||
}
|
}
|
||||||
|
|||||||
+5
-1
@@ -5,7 +5,7 @@ using System.Threading;
|
|||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using mROA.Abstract;
|
using mROA.Abstract;
|
||||||
|
|
||||||
namespace mROA.Implementation
|
namespace mROA.Implementation.Frontend
|
||||||
{
|
{
|
||||||
public class UdpUntrustedInteraction : IUntrustedInteractionModule
|
public class UdpUntrustedInteraction : IUntrustedInteractionModule
|
||||||
{
|
{
|
||||||
@@ -55,6 +55,10 @@ namespace mROA.Implementation
|
|||||||
|
|
||||||
await foreach (var post in _channelInteractionModule.UntrustedPostChanel.ReadAllAsync(token))
|
await foreach (var post in _channelInteractionModule.UntrustedPostChanel.ReadAllAsync(token))
|
||||||
{
|
{
|
||||||
|
if (post.MessageType is not (EMessageType.CallRequest or EMessageType.CancelRequest
|
||||||
|
or EMessageType.EventRequest))
|
||||||
|
continue;
|
||||||
|
|
||||||
var serialized = _serializationToolkit.Serialize(post);
|
var serialized = _serializationToolkit.Serialize(post);
|
||||||
#if TRACE
|
#if TRACE
|
||||||
Console.WriteLine("Untrusted write start");
|
Console.WriteLine("Untrusted write start");
|
||||||
@@ -6,6 +6,7 @@ namespace mROA.Implementation
|
|||||||
public class MethodInvoker : IMethodInvoker
|
public class MethodInvoker : IMethodInvoker
|
||||||
{
|
{
|
||||||
public bool IsVoid { get; set; }
|
public bool IsVoid { get; set; }
|
||||||
|
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 Func<object, object?[]?, object[], object?> Invoking { get; set; } = (_, _, _) => null;
|
public Func<object, object?[]?, object[], object?> Invoking { get; set; } = (_, _, _) => null;
|
||||||
@@ -32,6 +33,7 @@ namespace mROA.Implementation
|
|||||||
public class AsyncMethodInvoker : IMethodInvoker
|
public class AsyncMethodInvoker : IMethodInvoker
|
||||||
{
|
{
|
||||||
public bool IsVoid { get; set; }
|
public bool IsVoid { get; set; }
|
||||||
|
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; }
|
||||||
|
|||||||
Reference in New Issue
Block a user