From e780feaafddee57d534bf6c041cd963964725b3c Mon Sep 17 00:00:00 2001 From: Harald Wolff Date: Sun, 24 Nov 2019 15:13:38 +0100 Subject: [PATCH] Develop RPCContainer --- rpc/RPCContainer.cs | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/rpc/RPCContainer.cs b/rpc/RPCContainer.cs index d562e43..f190090 100644 --- a/rpc/RPCContainer.cs +++ b/rpc/RPCContainer.cs @@ -13,9 +13,16 @@ namespace ln.types.rpc { Dictionary modules = new Dictionary(); + Func checkAccessHook; + public RPCContainer() { } + public RPCContainer(Func checkAccessHook) + { + this.checkAccessHook = checkAccessHook; + + } public void Add(object moduleInstance) => Add(moduleInstance.GetType().Name, moduleInstance); public void Add(string moduleName,object moduleInstance) @@ -23,7 +30,7 @@ namespace ln.types.rpc if (modules.ContainsKey(moduleName)) throw new ArgumentOutOfRangeException(nameof(moduleName), "Module with same name already added"); - RPCModule rpcModule = new RPCModule(moduleName,moduleInstance); + RPCModule rpcModule = new RPCModule(this,moduleName,moduleInstance); Logging.Log(LogLevel.DEBUG, "ServiceContainer: Adding RPC Module: {0}", moduleName); modules.Add(moduleName, rpcModule); } @@ -55,20 +62,26 @@ namespace ln.types.rpc public class RPCModule { + public RPCContainer Container { get; } + public String Name { get; } public object ModuleInstance { get; } public Dictionary methodInfos = new Dictionary(); - public RPCModule(string moduleName,object instance) + public RPCModule(RPCContainer container,string moduleName,object instance) { + Container = container; + Name = moduleName; ModuleInstance = instance; Initialize(ModuleInstance.GetType()); } - public RPCModule(string moduleName,Type type) + public RPCModule(RPCContainer container,string moduleName,Type type) { + Container = container; + Name = moduleName; ModuleInstance = null; @@ -130,7 +143,10 @@ namespace ln.types.rpc } } - object result = methodInfo.Invoke(ModuleInstance, parameters); + + object result = null; + if ((Container.checkAccessHook == null) || Container.checkAccessHook(Container,this,methodInfo)) + result = methodInfo.Invoke(ModuleInstance, parameters); return new RPCResult(call, result); } catch (Exception e)