2
0
mirror of https://github.com/esiur/esiur-dotnet.git synced 2026-03-31 10:28:21 +00:00

renaming 2

This commit is contained in:
2026-03-17 22:15:43 +03:00
parent 9d936c0812
commit e22e0d952d
88 changed files with 1685 additions and 1866 deletions

View File

@@ -1,25 +1,25 @@
using Esiur.Core;
using Esiur.Net.IIP;
using Esiur.Net.Packets;
using Esiur.Protocol;
using Esiur.Resource;
using System;
using System.Collections.Generic;
using System.Text;
namespace Esiur.Net.HTTP;
public class IIPoHTTP : HTTPFilter
public class EPoHTTP : HTTPFilter
{
[Attribute]
EntryPoint EntryPoint { get; set; }
public override AsyncReply<bool> Execute(HTTPConnection sender)
{
if (sender.Request.URL != "iip")
if (sender.Request.URL != "EP")
return new AsyncReply<bool>(false);
IIPPacketRequest action = (IIPPacketRequest)Convert.ToByte(sender.Request.Query["a"]);
EpPacketRequest action = (EpPacketRequest)Convert.ToByte(sender.Request.Query["a"]);
if (action == IIPPacketRequest.Query)
if (action == EpPacketRequest.Query)
{
EntryPoint.Query(sender.Request.Query["l"], null).Then(x =>
{

View File

@@ -28,15 +28,15 @@ using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Esiur.Resource;
using Esiur.Net.IIP;
using Esiur.Net.Sockets;
using Esiur.Core;
using Esiur.Protocol;
namespace Esiur.Net.HTTP;
public class IIPoWS : HTTPFilter
public class EPoWS : HTTPFilter
{
[Attribute]
public DistributedServer Server
public EpServer Server
{
get;
set;
@@ -59,10 +59,10 @@ public class IIPoWS : HTTPFilter
var wsSocket = new WSocket(tcpSocket);
httpServer.Remove(sender);
var iipConnection = new DistributedConnection();
var EPConnection = new EpConnection();
Server.Add(iipConnection);
iipConnection.Assign(wsSocket);
Server.Add(EPConnection);
EPConnection.Assign(wsSocket);
wsSocket.Begin();
return new AsyncReply<bool>(true);

View File

@@ -1,13 +0,0 @@
using System;
using System.Collections.Generic;
using System.Text;
namespace Esiur.Net.IIP
{
public enum ConnectionStatus
{
Closed,
Connecting,
Connected
}
}

File diff suppressed because it is too large Load Diff

View File

@@ -1,36 +0,0 @@
using Esiur.Core;
using Esiur.Data;
using Esiur.Net.Packets;
using Esiur.Security.Membership;
using System;
using System.Collections.Generic;
using System.Text;
namespace Esiur.Net.IIP
{
public class DistributedConnectionConfig
{
public ExceptionLevel ExceptionLevel { get; set; }
= ExceptionLevel.Code | ExceptionLevel.Message | ExceptionLevel.Source | ExceptionLevel.Trace;
public Func<AuthorizationRequest, AsyncReply<object>> Authenticator { get; set; }
public bool AutoReconnect { get; set; } = false;
public uint ReconnectInterval { get; set; } = 5;
public string Username { get; set; }
public bool UseWebSocket { get; set; }
public bool SecureWebSocket { get; set; }
public string Password { get; set; }
public string Token { get; set; }
public ulong TokenIndex { get; set; }
public string Domain { get; set; }
}
}

File diff suppressed because it is too large Load Diff

View File

@@ -1,560 +0,0 @@
/*
Copyright (c) 2017 Ahmed Kh. Zamil
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
using System;
using System.Collections.Generic;
using System.Text;
using System.Reflection;
using System.IO;
using System.Collections;
using System.ComponentModel;
using Esiur.Misc;
using Esiur.Data;
using System.Dynamic;
using System.Security.Cryptography;
using Esiur.Core;
using System.Runtime.CompilerServices;
using System.Reflection.Emit;
using System.Linq;
using System.Linq.Expressions;
using System.Threading.Tasks;
using Esiur.Resource;
using Esiur.Net.Packets;
using Esiur.Data.Types;
namespace Esiur.Net.IIP;
//[System.Runtime.InteropServices.ComVisible(true)]
public class DistributedResource : DynamicObject, IResource, INotifyPropertyChanged, IDynamicResource
{
/// <summary>
/// Raised when the distributed resource is destroyed.
/// </summary>
public event DestroyedEvent OnDestroy;
//public event PropertyModifiedEvent PropertyModified;
public event PropertyChangedEventHandler PropertyChanged;
uint instanceId;
TypeDef typeDef;
DistributedConnection connection;
bool attached = false;
bool destroyed = false;
bool suspended = false;
//Structure properties = new Structure();
string link;
ulong age;
protected object[] properties;
internal List<DistributedResource> parents = new List<DistributedResource>();
internal List<DistributedResource> children = new List<DistributedResource>();
DistributedResourceEvent[] events;
/// <summary>
/// Connection responsible for the distributed resource.
/// </summary>
public DistributedConnection DistributedResourceConnection
{
get { return connection; }
}
/// <summary>
/// Resource link
/// </summary>
public string DistributedResourceLink
{
get { return link; }
}
/// <summary>
/// Instance Id given by the other end.
/// </summary>
public uint DistributedResourceInstanceId
{
get { return instanceId; }
internal set { instanceId = value; }
}
/// <summary>
/// IDestructible interface.
/// </summary>
public void Destroy()
{
destroyed = true;
attached = false;
connection.SendDetachRequest(instanceId);
OnDestroy?.Invoke(this);
}
/// <summary>
/// Suspend resource
/// </summary>
internal void Suspend()
{
suspended = true;
attached = false;
}
/// <summary>
/// Resource is attached when all its properties are received.
/// </summary>
public bool DistributedResourceAttached => attached;
public bool DistributedResourceSuspended => suspended;
// public DistributedResourceStack Stack
//{
// get { return stack; }
//}
/// <summary>
/// Create a new distributed resource.
/// </summary>
/// <param name="connection">Connection responsible for the distributed resource.</param>
/// <param name="template">Resource template.</param>
/// <param name="instanceId">Instance Id given by the other end.</param>
/// <param name="age">Resource age.</param>
public DistributedResource(DistributedConnection connection, uint instanceId, ulong age, string link)
{
this.link = link;
this.connection = connection;
this.instanceId = instanceId;
this.age = age;
}
internal bool _Attach(PropertyValue[] properties)
{
if (attached)
return false;
else
{
suspended = false;
this.properties = new object[properties.Length];
this.events = new DistributedResourceEvent[Instance.Definition.Events.Length];
for (byte i = 0; i < properties.Length; i++)
{
Instance.SetAge(i, properties[i].Age);
Instance.SetModificationDate(i, properties[i].Date);
this.properties[i] = properties[i].Value;
}
// trigger holded events/property updates.
//foreach (var r in afterAttachmentTriggers)
// r.Key.Trigger(r.Value);
//afterAttachmentTriggers.Clear();
attached = true;
}
return true;
}
protected internal virtual void _EmitEventByIndex(byte index, object args)
{
var et = Instance.Definition.GetEventDefByIndex(index);
events[index]?.Invoke(this, args);
Instance.EmitResourceEvent(et, args);
}
public AsyncReply _Invoke(byte index, object args)
{
if (destroyed)
throw new Exception("Trying to access a destroyed object.");
if (suspended)
throw new Exception("Trying to access a suspended object.");
if (index >= Instance.Definition.Functions.Length)
throw new Exception("Function index is incorrect.");
var ft = Instance.Definition.GetFunctionDefByIndex(index);
if (ft == null)
throw new Exception("Function template not found.");
if (ft.IsStatic)
return connection.StaticCall(Instance.Definition.ClassId, index, args);
else
return connection.SendInvoke(instanceId, index, args);
}
public AsyncReply Subscribe(EventDef et)
{
if (et == null)
return new AsyncReply().TriggerError(new AsyncException(ErrorType.Management, (ushort)ExceptionCode.MethodNotFound, ""));
if (!et.Subscribable)
return new AsyncReply().TriggerError(new AsyncException(ErrorType.Management, (ushort)ExceptionCode.NotSubscribable, ""));
return connection.SendSubscribeRequest(instanceId, et.Index);
}
public AsyncReply Subscribe(string eventName)
{
var et = Instance.Definition.GetEventDefByName(eventName);
return Subscribe(et);
}
public AsyncReply Unsubscribe(EventDef et)
{
if (et == null)
return new AsyncReply().TriggerError(new AsyncException(ErrorType.Management, (ushort)ExceptionCode.MethodNotFound, ""));
if (!et.Subscribable)
return new AsyncReply().TriggerError(new AsyncException(ErrorType.Management, (ushort)ExceptionCode.NotSubscribable, ""));
return connection.SendUnsubscribeRequest(instanceId, et.Index);
}
public AsyncReply Unsubscribe(string eventName)
{
var et = Instance.Definition.GetEventDefByName(eventName);
return Unsubscribe(et);
}
public override bool TryInvokeMember(InvokeMemberBinder binder, object[] args, out object result)
{
if (destroyed)
throw new Exception("Trying to access a destroyed object.");
if (suspended)
throw new Exception("Trying to access a suspended object.");
var ft = Instance.Definition.GetFunctionDefByName(binder.Name);
var reply = new AsyncReply<object>();
if (attached && ft != null)
{
if (args.Length == 1)
{
// Detect anonymous types
var type = args[0].GetType();
if (Codec.IsAnonymous(type))
{
var indexedArgs = new Map<byte, object>();
var pis = type.GetProperties();
for (byte i = 0; i < ft.Arguments.Length; i++)
{
var pi = pis.FirstOrDefault(x => x.Name == ft.Arguments[i].Name);
if (pi != null)
indexedArgs.Add(i, pi.GetValue(args[0]));
}
result = _Invoke(ft.Index, indexedArgs);
}
else if (args[0] is object[] || args[0] is Map<byte, object>)
{
result = _Invoke(ft.Index, new object[] { args });
}
else
{
result = _Invoke(ft.Index, args);
}
}
else
{
result = _Invoke(ft.Index, args);
}
return true;
}
else
{
result = null;
return false;
}
}
///// <summary>
///// Get a property value.
///// </summary>
///// <param name="index">Zero-based property index.</param>
///// <returns>Value</returns>
//protected internal object _Get(byte index)
//{
//}
public bool TryGetPropertyValue(byte index, out object value)
{
if (index >= properties.Length)
{
value = null;
return false;
}
else
{
value = properties[index];
return true;
}
}
public override bool TryGetMember(GetMemberBinder binder, out object result)
{
if (destroyed)
throw new Exception("Trying to access a destroyed object.");
result = null;
if (!attached)
return false;
var pt = Instance.Definition.GetPropertyDefByName(binder.Name);
if (pt != null)
{
result = properties[pt.Index];
return true;
}
else
{
var et = Instance.Definition.GetEventDefByName(binder.Name);
if (et == null)
return false;
result = events[et.Index];
return true;
}
}
internal void _UpdatePropertyByIndex(byte index, object value)
{
var pt = Instance.Definition.GetPropertyDefByIndex(index);
properties[index] = value;
Instance.EmitModification(pt, value);
}
/// <summary>
/// Set property value.
/// </summary>
/// <param name="index">Zero-based property index.</param>
/// <param name="value">Value</param>
/// <returns>Indicator when the property is set.</returns>
//protected object _SetSync(byte index, object value)
//{
//}
///// <summary>
///// Set property value.
///// </summary>
///// <param name="index">Zero-based property index.</param>
///// <param name="value">Value</param>
///// <returns>Indicator when the property is set.</returns>
//protected internal AsyncReply<object> _Set(byte index, object value)
//{
//}
public override bool TrySetMember(SetMemberBinder binder, object value)
{
if (destroyed)
throw new Exception("Trying to access a destroyed object.");
if (suspended)
throw new Exception("Trying to access a suspended object.");
if (!attached)
return false;
var pt = Instance.Definition.GetPropertyDefByName(binder.Name);
if (pt != null)
{
SetResourceProperty(pt.Index, value);
return true;
}
else
{
var et = Instance.Definition.GetEventDefByName(binder.Name);
if (et == null)
return false;
events[et.Index] = (DistributedResourceEvent)value;
return true;
}
}
/// <summary>
/// Resource interface.
/// </summary>
public Instance Instance
{
get;
set;
}
public TypeDef ResourceDefinition
{
get
{
return typeDef;
}
internal set
{
typeDef = value;
}
}
/// <summary>
/// Create a new instance of distributed resource.
/// </summary>
public DistributedResource()
{
//stack = new DistributedResourceStack(this);
//this.Instance.ResourceModified += this.OnModified;
}
/// <summary>
/// Resource interface.
/// </summary>
/// <param name="trigger"></param>
/// <returns></returns>
public AsyncReply<bool> Trigger(ResourceTrigger trigger)
{
if (trigger == ResourceTrigger.Initialize)
{
this.Instance.PropertyModified += (x) =>
this.PropertyChanged?.Invoke(this, new ResourcePropertyChangedEventArgs(x.Name));
}
// do nothing.
return new AsyncReply<bool>(true);
}
protected virtual void EmitPropertyChanged(string name)
{
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(name));
}
public PropertyValue[] SerializeResource()
{
var props = new PropertyValue[properties.Length];
for (byte i = 0; i < properties.Length; i++)
props[i] = new PropertyValue(properties[i],
Instance.GetAge(i),
Instance.GetModificationDate(i));
return props;
}
public Map<byte, PropertyValue> SerializeResourceAfter(ulong age = 0)
{
var rt = new Map<byte, PropertyValue>();
for (byte i = 0; i < properties.Length; i++)
if (Instance.GetAge(i) > age)
rt.Add(i, new PropertyValue(properties[i],
Instance.GetAge(i),
Instance.GetModificationDate(i)));
return rt;
}
public object GetResourceProperty(byte index)
{
if (index >= properties.Length)
return null;
return properties[index];
}
public AsyncReply SetResourcePropertyAsync(byte index, object value)
{
if (destroyed)
throw new Exception("Trying to access a destroyed object.");
if (suspended)
throw new Exception("Trying to access a suspended object.");
if (!attached)
throw new Exception("Resource is not attached.");
if (index >= properties.Length)
throw new Exception("Property index not found."); ;
var reply = new AsyncReply<object>();
connection.SendSetProperty(instanceId, index, value)
.Then((res) =>
{
// not really needed, server will always send property modified,
// this only happens if the programmer forgot to emit in property setter
properties[index] = value;
reply.Trigger(null);
});
return reply;
}
public void SetResourceProperty(byte index, object value)
{
// Don't set the same current value
if (properties[index] == value)
return;
SetResourcePropertyAsync(index, value).Wait();
return;
}
~DistributedResource()
{
Destroy();
}
}

View File

@@ -1,20 +0,0 @@
using Esiur.Core;
using Esiur.Resource;
using System;
using System.Collections.Generic;
using System.Text;
namespace Esiur.Net.IIP
{
internal class DistributedResourceAttachRequestInfo
{
public AsyncReply<DistributedResource> Reply { get; set; }
public uint[] RequestSequence { get; set; }
public DistributedResourceAttachRequestInfo(AsyncReply<DistributedResource> reply, uint[] requestSequence)
{
Reply = reply;
RequestSequence = requestSequence;
}
}
}

View File

@@ -1,33 +0,0 @@
/*
Copyright (c) 2017 Ahmed Kh. Zamil
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Esiur.Net.IIP;
public delegate void DistributedResourceEvent(DistributedResource sender, object argument);

View File

@@ -1,71 +0,0 @@
/*
Copyright (c) 2017 Ahmed Kh. Zamil
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Esiur.Net.IIP;
public class DistributedResourceQueueItem
{
public enum DistributedResourceQueueItemType
{
Propery,
Event
}
DistributedResourceQueueItemType type;
byte index;
object value;
DistributedResource resource;
public DistributedResourceQueueItem(DistributedResource resource, DistributedResourceQueueItemType type, object value, byte index)
{
this.resource = resource;
this.index = index;
this.type = type;
this.value = value;
}
public DistributedResource Resource
{
get { return resource; }
}
public DistributedResourceQueueItemType Type
{
get { return type; }
}
public byte Index
{
get { return index; }
}
public object Value
{
get { return value; }
}
}

View File

@@ -1,182 +0,0 @@
/*
Copyright (c) 2017 Ahmed Kh. Zamil
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Esiur.Net.Sockets;
using Esiur.Misc;
using System.Threading;
using Esiur.Data;
using Esiur.Core;
using System.Net;
using Esiur.Resource;
using Esiur.Security.Membership;
using System.Threading.Tasks;
using Esiur.Data.Schema;
namespace Esiur.Net.IIP;
public class DistributedServer : NetworkServer<DistributedConnection>, IResource
{
[Attribute]
public string IP
{
get;
set;
}
IMembership membership;
[Attribute]
public IMembership Membership
{
get => membership;
set
{
if (membership != null)
membership.Authorization -= Membership_Authorization;
membership = value;
if (membership != null)
membership.Authorization += Membership_Authorization;
}
}
private void Membership_Authorization(AuthorizationIndication indication)
{
lock (Connections.SyncRoot)
foreach (var connection in Connections)
if (connection.Session == indication.Session)
connection.ProcessAuthorization(indication.Results);
}
[Attribute]
public EntryPoint EntryPoint
{
get;
set;
}
[Attribute]
public ushort Port
{
get;
set;
} = 10518;
[Attribute]
public ExceptionLevel ExceptionLevel { get; set; }
= ExceptionLevel.Code
| ExceptionLevel.Source
| ExceptionLevel.Message
| ExceptionLevel.Trace;
public Instance Instance
{
get;
set;
}
public AsyncReply<bool> Trigger(ResourceTrigger trigger)
{
if (trigger == ResourceTrigger.Initialize)
{
TCPSocket listener;
if (IP != null)
listener = new TCPSocket(new IPEndPoint(IPAddress.Parse(IP), Port));
else
listener = new TCPSocket(new IPEndPoint(IPAddress.Any, Port));
Start(listener);
}
else if (trigger == ResourceTrigger.Terminate)
{
Stop();
}
else if (trigger == ResourceTrigger.SystemReload)
{
Trigger(ResourceTrigger.Terminate);
Trigger(ResourceTrigger.Initialize);
}
return new AsyncReply<bool>(true);
}
protected override void ClientConnected(DistributedConnection connection)
{
//Task.Delay(10000).ContinueWith((x) =>
//{
// Console.WriteLine("By bye");
// // Remove me from here
// connection.Close();
// one = true;
//});
}
public override void Add(DistributedConnection connection)
{
connection.Server = this;
connection.ExceptionLevel = ExceptionLevel;
base.Add(connection);
}
public override void Remove(DistributedConnection connection)
{
connection.Server = null;
base.Remove(connection);
}
protected override void ClientDisconnected(DistributedConnection connection)
{
//connection.OnReady -= ConnectionReadyEventReceiver;
//Warehouse.Remove(connection);
}
public KeyList<string, CallInfo?> Calls { get; } = new KeyList<string, CallInfo?>();
public struct CallInfo
{
public FunctionDefinition Template;
public Delegate Delegate;
}
public DistributedServer MapCall(string call, Delegate handler)
{
var ft = FunctionDefinition.MakeFunctionDef(null, handler.Method, 0, call, null);
Calls.Add(call, new CallInfo() { Delegate = handler, Template = ft });
return this;
}
}

View File

@@ -1,36 +0,0 @@
/*
Copyright (c) 2017 Ahmed Kh. Zamil
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
using System;
using System.Collections.Generic;
using System.Text;
using Esiur.Net.Sockets;
using Esiur.Security.Authority;
namespace Esiur.Net.IIP;
public class DistributedSession : NetworkSession
{
public Source Source { get; set; }
public Authentication Authentication { get; set; }
}

View File

@@ -1,39 +0,0 @@
/*
Copyright (c) 2019 - 2024 Ahmed Kh. Zamil
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
using System;
using System.Collections.Generic;
using System.Text;
using Esiur.Core;
using Esiur.Data;
using Esiur.Resource;
using Esiur.Data.Schema;
namespace Esiur.Net.IIP;
public abstract class EntryPoint : Esiur.Resource.Resource
{
public abstract AsyncReply<IResource> Query(string path, DistributedConnection sender);
protected abstract override bool Create();
}

View File

@@ -1,36 +0,0 @@
using System;
using System.Collections.Generic;
using System.Text;
namespace Esiur.Net.IIP;
public interface IPropertyContext
{
object GetValue(DistributedConnection connection);
}
public class PropertyContext<T> : IPropertyContext
{
public T Value { get; private set; }
public DistributedConnection Connection { get; private set; }
public Func<DistributedConnection, T> Method { get; private set; }
public PropertyContext(DistributedConnection connection, T value)
{
this.Value = value;
this.Connection = connection;
}
public PropertyContext(Func<DistributedConnection, T> method)
{
this.Method = method;
}
public static implicit operator PropertyContext<T>(Func<DistributedConnection, T> method)
=> new PropertyContext<T>(method);
public object GetValue(DistributedConnection connection)
{
return Method.Invoke(connection);
}
}

View File

@@ -1,23 +0,0 @@
using Esiur.Resource;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Text;
namespace Esiur.Net.IIP
{
public class ResourcePropertyChangedEventArgs : PropertyChangedEventArgs
{
public ResourcePropertyChangedEventArgs(string propertyName) : base(propertyName)
{
}
public ResourcePropertyChangedEventArgs(PropertyModificationInfo info) : base(info.Name)
{
Info = info;
}
public readonly PropertyModificationInfo Info;
}
}

View File

@@ -4,19 +4,19 @@ using System.Text;
namespace Esiur.Net.Packets
{
public static class IIPAuthExtensions
public static class EpAuthExtensions
{
public static IIPAuthPacketIAuthFormat GetIAuthFormat(this object value)
public static EpAuthPacketIAuthFormat GetIAuthFormat(this object value)
{
if (value is string)
return IIPAuthPacketIAuthFormat.Text;
return EpAuthPacketIAuthFormat.Text;
else if (value is int || value is uint
|| value is byte || value is sbyte
|| value is short || value is ushort
|| value is long || value is ulong)
return IIPAuthPacketIAuthFormat.Number;
return EpAuthPacketIAuthFormat.Number;
else if (value.GetType().IsArray)
return IIPAuthPacketIAuthFormat.Choice;
return EpAuthPacketIAuthFormat.Choice;
throw new Exception("Unknown IAuth format");
}

View File

@@ -35,33 +35,33 @@ using System.Timers;
namespace Esiur.Net.Packets;
public class IIPAuthPacket : Packet
public class EpAuthPacket : Packet
{
public IIPAuthPacketCommand Command
public EpAuthPacketCommand Command
{
get;
set;
}
public IIPAuthPacketInitialize Initialization
public EpAuthPacketInitialize Initialization
{
get;
set;
}
public IIPAuthPacketAcknowledge Acknowledgement
public EpAuthPacketAcknowledge Acknowledgement
{
get;
set;
}
public IIPAuthPacketAction Action
public EpAuthPacketAction Action
{
get;
set;
}
public IIPAuthPacketEvent Event
public EpAuthPacketEvent Event
{
get;
set;
@@ -92,13 +92,13 @@ public class IIPAuthPacket : Packet
}
public IIPAuthPacketPublicKeyAlgorithm PublicKeyAlgorithm
public EpAuthPacketPublicKeyAlgorithm PublicKeyAlgorithm
{
get;
set;
}
public IIPAuthPacketHashAlgorithm HashAlgorithm
public EpAuthPacketHashAlgorithm HashAlgorithm
{
get;
set;
@@ -176,14 +176,14 @@ public class IIPAuthPacket : Packet
if (NotEnough(offset, ends, 1))
return -dataLengthNeeded;
Command = (IIPAuthPacketCommand)(data[offset] >> 6);
Command = (EpAuthPacketCommand)(data[offset] >> 6);
if (Command == IIPAuthPacketCommand.Initialize)
if (Command == EpAuthPacketCommand.Initialize)
{
LocalMethod = (AuthenticationMethod)(data[offset] >> 4 & 0x3);
RemoteMethod = (AuthenticationMethod)(data[offset] >> 2 & 0x3);
Initialization = (IIPAuthPacketInitialize)(data[offset++] & 0xFC); // remove last two reserved LSBs
Initialization = (EpAuthPacketInitialize)(data[offset++] & 0xFC); // remove last two reserved LSBs
if (NotEnough(offset, ends, 1))
return -dataLengthNeeded;
@@ -197,13 +197,13 @@ public class IIPAuthPacket : Packet
offset += (uint)DataType.Value.TotalLength;
}
else if (Command == IIPAuthPacketCommand.Acknowledge)
else if (Command == EpAuthPacketCommand.Acknowledge)
{
LocalMethod = (AuthenticationMethod)(data[offset] >> 4 & 0x3);
RemoteMethod = (AuthenticationMethod)(data[offset] >> 2 & 0x3);
Acknowledgement = (IIPAuthPacketAcknowledge)(data[offset++] & 0xFC); // remove last two reserved LSBs
Acknowledgement = (EpAuthPacketAcknowledge)(data[offset++] & 0xFC); // remove last two reserved LSBs
if (NotEnough(offset, ends, 1))
return -dataLengthNeeded;
@@ -216,19 +216,19 @@ public class IIPAuthPacket : Packet
offset += (uint)DataType.Value.TotalLength;
}
else if (Command == IIPAuthPacketCommand.Action)
else if (Command == EpAuthPacketCommand.Action)
{
Action = (IIPAuthPacketAction)data[offset++]; // (IIPAuthPacketAction)(data[offset++] & 0x3f);
Action = (EpAuthPacketAction)data[offset++]; // (EPAuthPacketAction)(data[offset++] & 0x3f);
if (Action == IIPAuthPacketAction.AuthenticateHash
|| Action == IIPAuthPacketAction.AuthenticatePublicHash
|| Action == IIPAuthPacketAction.AuthenticatePrivateHash
|| Action == IIPAuthPacketAction.AuthenticatePublicPrivateHash)
if (Action == EpAuthPacketAction.AuthenticateHash
|| Action == EpAuthPacketAction.AuthenticatePublicHash
|| Action == EpAuthPacketAction.AuthenticatePrivateHash
|| Action == EpAuthPacketAction.AuthenticatePublicPrivateHash)
{
if (NotEnough(offset, ends, 3))
return -dataLengthNeeded;
HashAlgorithm = (IIPAuthPacketHashAlgorithm)data[offset++];
HashAlgorithm = (EpAuthPacketHashAlgorithm)data[offset++];
var hashLength = data.GetUInt16(offset, Endian.Little);
offset += 2;
@@ -241,13 +241,13 @@ public class IIPAuthPacket : Packet
offset += hashLength;
}
else if (Action == IIPAuthPacketAction.AuthenticatePrivateHashCert
|| Action == IIPAuthPacketAction.AuthenticatePublicPrivateHashCert)
else if (Action == EpAuthPacketAction.AuthenticatePrivateHashCert
|| Action == EpAuthPacketAction.AuthenticatePublicPrivateHashCert)
{
if (NotEnough(offset, ends, 3))
return -dataLengthNeeded;
HashAlgorithm = (IIPAuthPacketHashAlgorithm)data[offset++];
HashAlgorithm = (EpAuthPacketHashAlgorithm)data[offset++];
var hashLength = data.GetUInt16(offset, Endian.Little);
offset += 2;
@@ -272,7 +272,7 @@ public class IIPAuthPacket : Packet
offset += certLength;
}
else if (Action == IIPAuthPacketAction.IAuthPlain)
else if (Action == EpAuthPacketAction.IAuthPlain)
{
if (NotEnough(offset, ends, 5))
return -dataLengthNeeded;
@@ -288,7 +288,7 @@ public class IIPAuthPacket : Packet
offset += (uint)DataType.Value.TotalLength;
}
else if (Action == IIPAuthPacketAction.IAuthHashed)
else if (Action == EpAuthPacketAction.IAuthHashed)
{
if (NotEnough(offset, ends, 7))
return -dataLengthNeeded;
@@ -296,7 +296,7 @@ public class IIPAuthPacket : Packet
Reference = data.GetUInt32(offset, Endian.Little);
offset += 4;
HashAlgorithm = (IIPAuthPacketHashAlgorithm)data[offset++];
HashAlgorithm = (EpAuthPacketHashAlgorithm)data[offset++];
var cl = data.GetUInt16(offset, Endian.Little);
offset += 2;
@@ -309,7 +309,7 @@ public class IIPAuthPacket : Packet
offset += cl;
}
else if (Action == IIPAuthPacketAction.IAuthEncrypted)
else if (Action == EpAuthPacketAction.IAuthEncrypted)
{
if (NotEnough(offset, ends, 7))
return -dataLengthNeeded;
@@ -317,7 +317,7 @@ public class IIPAuthPacket : Packet
Reference = data.GetUInt32(offset, Endian.Little);
offset += 4;
PublicKeyAlgorithm = (IIPAuthPacketPublicKeyAlgorithm)data[offset++];
PublicKeyAlgorithm = (EpAuthPacketPublicKeyAlgorithm)data[offset++];
var cl = data.GetUInt16(offset, Endian.Little);
offset += 2;
@@ -330,11 +330,11 @@ public class IIPAuthPacket : Packet
offset += cl;
}
else if (Action == IIPAuthPacketAction.EstablishNewSession)
else if (Action == EpAuthPacketAction.EstablishNewSession)
{
// Nothing here
}
else if (Action == IIPAuthPacketAction.EstablishResumeSession)
else if (Action == EpAuthPacketAction.EstablishResumeSession)
{
if (NotEnough(offset, ends, 1))
return -dataLengthNeeded;
@@ -349,7 +349,7 @@ public class IIPAuthPacket : Packet
offset += sessionLength;
}
else if (Action == IIPAuthPacketAction.EncryptKeyExchange)
else if (Action == EpAuthPacketAction.EncryptKeyExchange)
{
if (NotEnough(offset, ends, 2))
return -dataLengthNeeded;
@@ -366,13 +366,13 @@ public class IIPAuthPacket : Packet
offset += keyLength;
}
else if (Action == IIPAuthPacketAction.RegisterEndToEndKey
|| Action == IIPAuthPacketAction.RegisterHomomorphic)
else if (Action == EpAuthPacketAction.RegisterEndToEndKey
|| Action == EpAuthPacketAction.RegisterHomomorphic)
{
if (NotEnough(offset, ends, 3))
return -dataLengthNeeded;
PublicKeyAlgorithm = (IIPAuthPacketPublicKeyAlgorithm)data[offset++];
PublicKeyAlgorithm = (EpAuthPacketPublicKeyAlgorithm)data[offset++];
var keyLength = data.GetUInt16(offset, Endian.Little);
@@ -387,14 +387,14 @@ public class IIPAuthPacket : Packet
}
}
else if (Command == IIPAuthPacketCommand.Event)
else if (Command == EpAuthPacketCommand.Event)
{
Event = (IIPAuthPacketEvent)data[offset++];
Event = (EpAuthPacketEvent)data[offset++];
if (Event == IIPAuthPacketEvent.ErrorTerminate
|| Event == IIPAuthPacketEvent.ErrorMustEncrypt
|| Event == IIPAuthPacketEvent.ErrorRetry)
if (Event == EpAuthPacketEvent.ErrorTerminate
|| Event == EpAuthPacketEvent.ErrorMustEncrypt
|| Event == EpAuthPacketEvent.ErrorRetry)
{
if (NotEnough(offset, ends, 3))
return -dataLengthNeeded;
@@ -411,7 +411,7 @@ public class IIPAuthPacket : Packet
offset += msgLength;
}
else if (Event == IIPAuthPacketEvent.IndicationEstablished)
else if (Event == EpAuthPacketEvent.IndicationEstablished)
{
if (NotEnough(offset, ends, 2))
return -dataLengthNeeded;
@@ -438,9 +438,9 @@ public class IIPAuthPacket : Packet
offset += accountLength;
}
else if (Event == IIPAuthPacketEvent.IAuthPlain
|| Event == IIPAuthPacketEvent.IAuthHashed
|| Event == IIPAuthPacketEvent.IAuthEncrypted)
else if (Event == EpAuthPacketEvent.IAuthPlain
|| Event == EpAuthPacketEvent.IAuthHashed
|| Event == EpAuthPacketEvent.IAuthEncrypted)
{
if (NotEnough(offset, ends, 1))
return -dataLengthNeeded;

View File

@@ -4,7 +4,7 @@ using System.Text;
namespace Esiur.Net.Packets
{
public enum IIPAuthPacketAcknowledge : byte
public enum EpAuthPacketAcknowledge : byte
{
NoAuthNoAuth = 0x40, // 0b01000000,
NoAuthCredentials = 0x44, // 0b01000100,

View File

@@ -4,7 +4,7 @@ using System.Text;
namespace Esiur.Net.Packets
{
public enum IIPAuthPacketAction : byte
public enum EpAuthPacketAction : byte
{
AuthenticateHash = 0x80,
AuthenticatePublicHash = 0x81,

View File

@@ -4,7 +4,7 @@ using System.Text;
namespace Esiur.Net.Packets
{
public enum IIPAuthPacketCommand : byte
public enum EpAuthPacketCommand : byte
{
Initialize = 0x0,
Acknowledge = 0x1,

View File

@@ -4,7 +4,7 @@ using System.Text;
namespace Esiur.Net.Packets
{
public enum IIPAuthPacketEvent : byte
public enum EpAuthPacketEvent : byte
{
ErrorTerminate = 0xC0,
ErrorMustEncrypt = 0xC1,

View File

@@ -4,7 +4,7 @@ using System.Text;
namespace Esiur.Net.Packets
{
public enum IIPAuthPacketHashAlgorithm
public enum EpAuthPacketHashAlgorithm
{
SHA256,
SHA3,

View File

@@ -4,7 +4,7 @@ using System.Text;
namespace Esiur.Net.Packets
{
public enum IIPAuthPacketHeader
public enum EpAuthPacketHeader
{
Version = 0,
Domain = 1,

View File

@@ -4,7 +4,7 @@ using System.Text;
namespace Esiur.Net.Packets
{
public enum IIPAuthPacketIAuthDestination
public enum EpAuthPacketIAuthDestination
{
Self = 0,
Device = 1, // logged in device

View File

@@ -4,7 +4,7 @@ using System.Text;
namespace Esiur.Net.Packets
{
public enum IIPAuthPacketIAuthFormat
public enum EpAuthPacketIAuthFormat
{
None = 0,
Number = 1,

View File

@@ -4,7 +4,7 @@ using System.Text;
namespace Esiur.Net.Packets
{
public enum IIPAuthPacketIAuthHeader : byte
public enum EpAuthPacketIAuthHeader : byte
{
Reference = 0,
Destination = 1,

View File

@@ -4,7 +4,7 @@ using System.Text;
namespace Esiur.Net.Packets
{
public enum IIPAuthPacketInitialize
public enum EpAuthPacketInitialize
{
NoAuthNoAuth = 0x0, //0b00000000,
NoAuthCredentials = 0x4, //0b00000100,

View File

@@ -4,7 +4,7 @@ using System.Text;
namespace Esiur.Net.Packets
{
public enum IIPAuthPacketPublicKeyAlgorithm
public enum EpAuthPacketPublicKeyAlgorithm
{
RSA = 0,
CKKS = 1,

View File

@@ -32,15 +32,15 @@ using System.Text;
using System.Threading.Tasks;
namespace Esiur.Net.Packets;
class IIPPacket : Packet
class EpPacket : Packet
{
public uint CallbackId { get; set; }
public IIPPacketMethod Method { get; set; }
public IIPPacketRequest Request { get; set; }
public IIPPacketReply Reply { get; set; }
public EpPacketMethod Method { get; set; }
public EpPacketRequest Request { get; set; }
public EpPacketReply Reply { get; set; }
public IIPPacketNotification Notification { get; set; }
public EpPacketNotification Notification { get; set; }
public byte Extension { get; set; }
@@ -59,10 +59,10 @@ class IIPPacket : Packet
{
return Method switch
{
IIPPacketMethod.Notification => $"{Method} {Notification}",
IIPPacketMethod.Request => $"{Method} {Request}",
IIPPacketMethod.Reply => $"{Method} {Reply}",
IIPPacketMethod.Extension => $"{Method} {Extension}",
EpPacketMethod.Notification => $"{Method} {Notification}",
EpPacketMethod.Request => $"{Method} {Request}",
EpPacketMethod.Reply => $"{Method} {Reply}",
EpPacketMethod.Extension => $"{Method} {Extension}",
_ => $"{Method}"
};
}
@@ -88,15 +88,15 @@ class IIPPacket : Packet
var hasDTU = (data[offset] & 0x20) == 0x20;
Method = (IIPPacketMethod)(data[offset] >> 6);
Method = (EpPacketMethod)(data[offset] >> 6);
if (Method == IIPPacketMethod.Notification)
if (Method == EpPacketMethod.Notification)
{
Notification = (IIPPacketNotification)(data[offset++] & 0x1f);
Notification = (EpPacketNotification)(data[offset++] & 0x1f);
}
else if (Method == IIPPacketMethod.Request)
else if (Method == EpPacketMethod.Request)
{
Request = (IIPPacketRequest)(data[offset++] & 0x1f);
Request = (EpPacketRequest)(data[offset++] & 0x1f);
if (NotEnough(offset, ends, 4))
return -dataLengthNeeded;
@@ -104,9 +104,9 @@ class IIPPacket : Packet
CallbackId = data.GetUInt32(offset, Endian.Little);
offset += 4;
}
else if (Method == IIPPacketMethod.Reply)
else if (Method == EpPacketMethod.Reply)
{
Reply = (IIPPacketReply)(data[offset++] & 0x1f);
Reply = (EpPacketReply)(data[offset++] & 0x1f);
if (NotEnough(offset, ends, 4))
return -dataLengthNeeded;
@@ -114,7 +114,7 @@ class IIPPacket : Packet
CallbackId = data.GetUInt32(offset, Endian.Little);
offset += 4;
}
else if (Method == IIPPacketMethod.Extension)
else if (Method == EpPacketMethod.Extension)
{
Extension = (byte)(data[offset++] & 0x1f);
}

View File

@@ -5,14 +5,14 @@ using System.Text;
namespace Esiur.Net.Packets;
struct IIPPacketAttachInfo
struct EpPacketAttachInfo
{
public string Link;
public ulong Age;
public byte[] Content;
public UUID TypeId;
public IIPPacketAttachInfo(UUID typeId, ulong age, string link, byte[] content)
public EpPacketAttachInfo(UUID typeId, ulong age, string link, byte[] content)
{
TypeId = typeId;
Age = age;

View File

@@ -4,7 +4,7 @@ using System.Text;
namespace Esiur.Net.Packets
{
public enum IIPPacketMethod : byte
public enum EpPacketMethod : byte
{
Notification = 0,
Request,

View File

@@ -4,7 +4,7 @@ using System.Text;
namespace Esiur.Net.Packets
{
public enum IIPPacketNotification : byte
public enum EpPacketNotification : byte
{
// Notification Invoke
PropertyModified = 0x0,

View File

@@ -4,7 +4,7 @@ using System.Text;
namespace Esiur.Net.Packets
{
public enum IIPPacketReply : byte
public enum EpPacketReply : byte
{
// Success
Completed = 0x0,

View File

@@ -4,7 +4,7 @@ using System.Text;
namespace Esiur.Net.Packets
{
public enum IIPPacketReport : byte
public enum EpPacketReport : byte
{
ManagementError,
ExecutionError,

View File

@@ -4,7 +4,7 @@ using System.Text;
namespace Esiur.Net.Packets
{
public enum IIPPacketRequest : byte
public enum EpPacketRequest : byte
{
// Request Invoke
InvokeFunction = 0x0,
@@ -13,11 +13,11 @@ namespace Esiur.Net.Packets
Unsubscribe = 0x3,
// Request Inquire
SchemaFromClassName = 0x8,
SchemaFromClassId = 0x9,
SchemaFromResourceId = 0xA,
TypeDefByName = 0x8,
TypeDefById = 0x9,
TypeDefByResourceId = 0xA,
Query = 0xB,
LinkSchemas = 0xC,
LinkTypeDefs = 0xC,
Token = 0xD,
GetResourceIdByLink = 0xE,

View File

@@ -35,7 +35,7 @@ using Esiur.Core;
namespace Esiur.Net.UDP;
/* public class IIPConnection
/* public class EPConnection
{
public EndPoint SenderPoint;
public