2
0
mirror of https://github.com/esiur/esiur-dotnet.git synced 2025-06-27 05:23:13 +00:00
This commit is contained in:
2022-03-09 21:55:30 +03:00
parent 530df018ec
commit 9a174f406f
106 changed files with 5166 additions and 4398 deletions

View File

@ -42,6 +42,7 @@ public abstract class PacketFilter : IResource
}
public event DestroyedEvent OnDestroy;
public abstract AsyncReply<bool> Trigger(ResourceTrigger trigger);
@ -51,4 +52,6 @@ public abstract class PacketFilter : IResource
{
OnDestroy?.Invoke(this);
}
}

View File

@ -61,6 +61,7 @@ public class PacketServer : IResource
}
public event DestroyedEvent OnDestroy;
public event PropertyModifiedEvent PropertyModified;
public void Destroy()
{

View File

@ -103,26 +103,36 @@ public class HTTPConnection : NetworkConnection
public bool Upgrade()
{
if (IsWebsocketRequest())
var ok = Upgrade(Request, Response);
if (ok)
{
WSMode = true;
Send();
}
return ok;
}
public static bool Upgrade(HTTPRequestPacket request, HTTPResponsePacket response)
{
if (IsWebsocketRequest(request))
{
string magicString = "258EAFA5-E914-47DA-95CA-C5AB0DC85B11";
string ret = Request.Headers["Sec-WebSocket-Key"] + magicString;
string ret = request.Headers["Sec-WebSocket-Key"] + magicString;
// Compute the SHA1 hash
SHA1 sha = SHA1.Create();
byte[] sha1Hash = sha.ComputeHash(Encoding.UTF8.GetBytes(ret));
Response.Headers["Upgrade"] = Request.Headers["Upgrade"];
Response.Headers["Connection"] = Request.Headers["Connection"];// "Upgrade";
Response.Headers["Sec-WebSocket-Accept"] = Convert.ToBase64String(sha1Hash);
response.Headers["Upgrade"] = request.Headers["Upgrade"];
response.Headers["Connection"] = request.Headers["Connection"];// "Upgrade";
response.Headers["Sec-WebSocket-Accept"] = Convert.ToBase64String(sha1Hash);
if (Request.Headers.ContainsKey("Sec-WebSocket-Protocol"))
Response.Headers["Sec-WebSocket-Protocol"] = Request.Headers["Sec-WebSocket-Protocol"];
if (request.Headers.ContainsKey("Sec-WebSocket-Protocol"))
response.Headers["Sec-WebSocket-Protocol"] = request.Headers["Sec-WebSocket-Protocol"];
Response.Number = HTTPResponsePacket.ResponseCode.Switching;
Response.Text = "Switching Protocols";
WSMode = true;
Send();
response.Number = HTTPResponsePacket.ResponseCode.Switching;
response.Text = "Switching Protocols";
return true;
}
@ -212,13 +222,18 @@ public class HTTPConnection : NetworkConnection
public bool IsWebsocketRequest()
{
if (Request.Headers.ContainsKey("connection")
&& Request.Headers["connection"].ToLower().Contains("upgrade")
&& Request.Headers.ContainsKey("upgrade")
&& Request.Headers["upgrade"].ToLower() == "websocket"
&& Request.Headers.ContainsKey("Sec-WebSocket-Version")
&& Request.Headers["Sec-WebSocket-Version"] == "13"
&& Request.Headers.ContainsKey("Sec-WebSocket-Key"))
return IsWebsocketRequest(this.Request);
}
public static bool IsWebsocketRequest(HTTPRequestPacket request)
{
if (request.Headers.ContainsKey("connection")
&& request.Headers["connection"].ToLower().Contains("upgrade")
&& request.Headers.ContainsKey("upgrade")
&& request.Headers["upgrade"].ToLower() == "websocket"
&& request.Headers.ContainsKey("Sec-WebSocket-Version")
&& request.Headers["Sec-WebSocket-Version"] == "13"
&& request.Headers.ContainsKey("Sec-WebSocket-Key"))
//&& Request.Headers.ContainsKey("Sec-WebSocket-Protocol"))
{
return true;
@ -284,7 +299,7 @@ public class HTTPConnection : NetworkConnection
if (IsWebsocketRequest() & !WSMode)
if (IsWebsocketRequest(Request) & !WSMode)
{
Upgrade();
//return;

View File

@ -46,7 +46,6 @@ public abstract class HTTPFilter : IResource
}
public event DestroyedEvent OnDestroy;
public abstract AsyncReply<bool> Trigger(ResourceTrigger trigger);
/*

View File

@ -155,7 +155,12 @@ public class HTTPServer : NetworkServer<HTTPConnection>, IResource
return false;
}
//public delegate void HTTPGetHandler(HTTPConnection connection, object[] params values);
public void MapGet(string pattern, Delegate handler)
{
// if (p)
}
/*

View File

@ -39,6 +39,7 @@ using Esiur.Resource.Template;
using System.Linq;
using System.Diagnostics;
using static Esiur.Net.Packets.IIPPacket;
using Esiur.Net.HTTP;
namespace Esiur.Net.IIP;
public partial class DistributedConnection : NetworkConnection, IStore
@ -56,6 +57,8 @@ public partial class DistributedConnection : NetworkConnection, IStore
/// </summary>
public event ErrorEvent OnError;
IIPPacket packet = new IIPPacket();
IIPAuthPacket authPacket = new IIPAuthPacket();
@ -71,8 +74,12 @@ public partial class DistributedConnection : NetworkConnection, IStore
string _hostname;
ushort _port;
bool initialPacket = true;
DateTime loginDate;
/// <summary>
/// Local username to authenticate ourselves.
/// </summary>
@ -350,7 +357,7 @@ public partial class DistributedConnection : NetworkConnection, IStore
if (ready)
{
var rt = packet.Parse(msg, offset, ends);
//Console.WriteLine("Rec: " + chunkId + " " + packet.ToString());
Console.WriteLine("Rec: " + chunkId + " " + packet.ToString());
/*
if (packet.Command == IIPPacketCommand.Event)
@ -394,10 +401,10 @@ public partial class DistributedConnection : NetworkConnection, IStore
IIPEventResourceDestroyed(packet.ResourceId);
break;
case IIPPacket.IIPPacketEvent.PropertyUpdated:
IIPEventPropertyUpdated(packet.ResourceId, packet.MethodIndex, packet.Content);
IIPEventPropertyUpdated(packet.ResourceId, packet.MethodIndex, (TransmissionType)packet.DataType, msg);// packet.Content);
break;
case IIPPacket.IIPPacketEvent.EventOccurred:
IIPEventEventOccurred(packet.ResourceId, packet.MethodIndex, packet.Content);
IIPEventEventOccurred(packet.ResourceId, packet.MethodIndex, (TransmissionType)packet.DataType, msg);//packet.Content);
break;
case IIPPacketEvent.ChildAdded:
@ -407,10 +414,11 @@ public partial class DistributedConnection : NetworkConnection, IStore
IIPEventChildRemoved(packet.ResourceId, packet.ChildId);
break;
case IIPPacketEvent.Renamed:
IIPEventRenamed(packet.ResourceId, packet.Content);
IIPEventRenamed(packet.ResourceId, packet.ResourceLink);
break;
case IIPPacketEvent.AttributesUpdated:
IIPEventAttributesUpdated(packet.ResourceId, packet.Content);
// @TODO: fix this
//IIPEventAttributesUpdated(packet.ResourceId, packet.Content);
break;
}
}
@ -429,7 +437,8 @@ public partial class DistributedConnection : NetworkConnection, IStore
IIPRequestDetachResource(packet.CallbackId, packet.ResourceId);
break;
case IIPPacket.IIPPacketAction.CreateResource:
IIPRequestCreateResource(packet.CallbackId, packet.StoreId, packet.ResourceId, packet.Content);
//@TODO : fix this
//IIPRequestCreateResource(packet.CallbackId, packet.StoreId, packet.ResourceId, packet.Content);
break;
case IIPPacket.IIPPacketAction.DeleteResource:
IIPRequestDeleteResource(packet.CallbackId, packet.ResourceId);
@ -441,7 +450,7 @@ public partial class DistributedConnection : NetworkConnection, IStore
IIPRequestRemoveChild(packet.CallbackId, packet.ResourceId, packet.ChildId);
break;
case IIPPacketAction.RenameResource:
IIPRequestRenameResource(packet.CallbackId, packet.ResourceId, packet.Content);
IIPRequestRenameResource(packet.CallbackId, packet.ResourceId, packet.ResourceName);
break;
// Inquire
@ -474,13 +483,13 @@ public partial class DistributedConnection : NetworkConnection, IStore
break;
// Invoke
case IIPPacket.IIPPacketAction.InvokeFunctionArrayArguments:
IIPRequestInvokeFunctionArrayArguments(packet.CallbackId, packet.ResourceId, packet.MethodIndex, packet.Content);
case IIPPacket.IIPPacketAction.InvokeFunction:
IIPRequestInvokeFunction(packet.CallbackId, packet.ResourceId, packet.MethodIndex, (TransmissionType)packet.DataType, msg);
break;
case IIPPacket.IIPPacketAction.InvokeFunctionNamedArguments:
IIPRequestInvokeFunctionNamedArguments(packet.CallbackId, packet.ResourceId, packet.MethodIndex, packet.Content);
break;
//case IIPPacket.IIPPacketAction.InvokeFunctionNamedArguments:
// IIPRequestInvokeFunctionNamedArguments(packet.CallbackId, packet.ResourceId, packet.MethodIndex, (TransmissionType)packet.DataType, msg);
// break;
//case IIPPacket.IIPPacketAction.GetProperty:
// IIPRequestGetProperty(packet.CallbackId, packet.ResourceId, packet.MethodIndex);
@ -498,27 +507,33 @@ public partial class DistributedConnection : NetworkConnection, IStore
break;
case IIPPacket.IIPPacketAction.SetProperty:
IIPRequestSetProperty(packet.CallbackId, packet.ResourceId, packet.MethodIndex, packet.Content);
IIPRequestSetProperty(packet.CallbackId, packet.ResourceId, packet.MethodIndex, (TransmissionType)packet.DataType, msg);
break;
// Attribute
case IIPPacketAction.GetAllAttributes:
IIPRequestGetAttributes(packet.CallbackId, packet.ResourceId, packet.Content, true);
// @TODO : fix this
//IIPRequestGetAttributes(packet.CallbackId, packet.ResourceId, packet.Content, true);
break;
case IIPPacketAction.UpdateAllAttributes:
IIPRequestUpdateAttributes(packet.CallbackId, packet.ResourceId, packet.Content, true);
// @TODO : fix this
//IIPRequestUpdateAttributes(packet.CallbackId, packet.ResourceId, packet.Content, true);
break;
case IIPPacketAction.ClearAllAttributes:
IIPRequestClearAttributes(packet.CallbackId, packet.ResourceId, packet.Content, true);
// @TODO : fix this
//IIPRequestClearAttributes(packet.CallbackId, packet.ResourceId, packet.Content, true);
break;
case IIPPacketAction.GetAttributes:
IIPRequestGetAttributes(packet.CallbackId, packet.ResourceId, packet.Content, false);
// @TODO : fix this
//IIPRequestGetAttributes(packet.CallbackId, packet.ResourceId, packet.Content, false);
break;
case IIPPacketAction.UpdateAttributes:
IIPRequestUpdateAttributes(packet.CallbackId, packet.ResourceId, packet.Content, false);
// @TODO : fix this
//IIPRequestUpdateAttributes(packet.CallbackId, packet.ResourceId, packet.Content, false);
break;
case IIPPacketAction.ClearAttributes:
IIPRequestClearAttributes(packet.CallbackId, packet.ResourceId, packet.Content, false);
// @TODO : fix this
//IIPRequestClearAttributes(packet.CallbackId, packet.ResourceId, packet.Content, false);
break;
}
}
@ -528,11 +543,11 @@ public partial class DistributedConnection : NetworkConnection, IStore
{
// Manage
case IIPPacket.IIPPacketAction.AttachResource:
IIPReply(packet.CallbackId, packet.ClassId, packet.ResourceAge, packet.ResourceLink, packet.Content);
IIPReply(packet.CallbackId, packet.ClassId, packet.ResourceAge, packet.ResourceLink, packet.DataType, msg);
break;
case IIPPacket.IIPPacketAction.ReattachResource:
IIPReply(packet.CallbackId, packet.ResourceAge, packet.Content);
IIPReply(packet.CallbackId, packet.ResourceAge, packet.DataType, msg);
break;
case IIPPacket.IIPPacketAction.DetachResource:
@ -555,7 +570,9 @@ public partial class DistributedConnection : NetworkConnection, IStore
case IIPPacket.IIPPacketAction.TemplateFromClassName:
case IIPPacket.IIPPacketAction.TemplateFromClassId:
case IIPPacket.IIPPacketAction.TemplateFromResourceId:
IIPReply(packet.CallbackId, TypeTemplate.Parse(packet.Content));
var content = msg.Clip(packet.DataType.Value.Offset, (uint)packet.DataType.Value.ContentLength);
IIPReply(packet.CallbackId, TypeTemplate.Parse(content));
break;
case IIPPacketAction.QueryLink:
@ -563,13 +580,12 @@ public partial class DistributedConnection : NetworkConnection, IStore
case IIPPacketAction.ResourceParents:
case IIPPacketAction.ResourceHistory:
case IIPPacketAction.LinkTemplates:
IIPReply(packet.CallbackId, packet.Content);
IIPReply(packet.CallbackId, (TransmissionType)packet.DataType, msg);// packet.Content);
break;
// Invoke
case IIPPacket.IIPPacketAction.InvokeFunctionArrayArguments:
case IIPPacket.IIPPacketAction.InvokeFunctionNamedArguments:
IIPReplyInvoke(packet.CallbackId, packet.Content);
case IIPPacket.IIPPacketAction.InvokeFunction:
IIPReplyInvoke(packet.CallbackId, (TransmissionType)packet.DataType, msg);// packet.Content);
break;
//case IIPPacket.IIPPacketAction.GetProperty:
@ -589,7 +605,7 @@ public partial class DistributedConnection : NetworkConnection, IStore
// Attribute
case IIPPacketAction.GetAllAttributes:
case IIPPacketAction.GetAttributes:
IIPReply(packet.CallbackId, packet.Content);
IIPReply(packet.CallbackId, (TransmissionType)packet.DataType, msg);// packet.Content);
break;
case IIPPacketAction.UpdateAllAttributes:
@ -616,7 +632,7 @@ public partial class DistributedConnection : NetworkConnection, IStore
IIPReportProgress(packet.CallbackId, ProgressType.Execution, packet.ProgressValue, packet.ProgressMax);
break;
case IIPPacketReport.ChunkStream:
IIPReportChunk(packet.CallbackId, packet.Content);
IIPReportChunk(packet.CallbackId, (TransmissionType)packet.DataType, msg);// packet.Content);
break;
}
@ -626,6 +642,62 @@ public partial class DistributedConnection : NetworkConnection, IStore
else
{
// check if the reqeust through websockets
if (initialPacket)
{
initialPacket = false;
if (msg.Length > 3 && Encoding.Default.GetString(msg, 0, 3) == "GET")
{
// Parse with http packet
var req = new HTTPRequestPacket();
var pSize = req.Parse(msg, 0, (uint)msg.Length);
if (pSize > 0)
{
// check for WS upgrade
if (HTTPConnection.IsWebsocketRequest(req))
{
Socket?.Unhold();
var res = new HTTPResponsePacket();
HTTPConnection.Upgrade(req, res);
res.Compose(HTTPResponsePacket.ComposeOptions.AllCalculateLength);
Send(res.Data);
// replace my socket with websockets
var tcpSocket = this.Unassign();
var wsSocket = new WSocket(tcpSocket);
this.Assign(wsSocket);
}
else
{
var res = new HTTPResponsePacket();
res.Number = HTTPResponsePacket.ResponseCode.BadRequest;
res.Compose(HTTPResponsePacket.ComposeOptions.AllCalculateLength);
Send(res.Data);
//@TODO: kill the connection
}
}
else
{
// packet incomplete
return (uint)pSize;
}
// switching completed
return (uint)msg.Length;
}
}
Console.WriteLine(msg.GetString(offset, ends - offset));
var rt = authPacket.Parse(msg, offset, ends);
//Console.WriteLine(session.LocalAuthentication.Type.ToString() + " " + offset + " " + ends + " " + rt + " " + authPacket.ToString());
@ -649,7 +721,16 @@ public partial class DistributedConnection : NetworkConnection, IStore
{
try
{
Server.Membership.UserExists(authPacket.RemoteUsername, authPacket.Domain).Then(x =>
if (Server.Membership == null)
{
var errMsg = DC.ToBytes("Membership not set.");
SendParams().AddUInt8(0xc0)
.AddUInt8((byte)ExceptionCode.GeneralFailure)
.AddUInt16((ushort)errMsg.Length)
.AddUInt8Array(errMsg).Done();
}
else Server.Membership.UserExists(authPacket.RemoteUsername, authPacket.Domain).Then(x =>
{
if (x)
{
@ -660,15 +741,15 @@ public partial class DistributedConnection : NetworkConnection, IStore
.AddUInt8(0xa0)
.AddUInt8Array(localNonce)
.Done();
//SendParams((byte)0xa0, localNonce);
}
//SendParams((byte)0xa0, localNonce);
}
else
{
//Console.WriteLine("User not found");
SendParams().AddUInt8(0xc0)
.AddUInt8((byte)ExceptionCode.UserOrTokenNotFound)
.AddUInt16(14)
.AddString("User not found").Done();
//Console.WriteLine("User not found");
SendParams().AddUInt8(0xc0)
.AddUInt8((byte)ExceptionCode.UserOrTokenNotFound)
.AddUInt16(14)
.AddString("User not found").Done();
}
});
}
@ -686,31 +767,43 @@ public partial class DistributedConnection : NetworkConnection, IStore
{
try
{
// Check if user and token exists
Server.Membership.TokenExists(authPacket.RemoteTokenIndex, authPacket.Domain).Then(x =>
if (Server.Membership == null)
{
if (x != null)
{
session.RemoteAuthentication.Username = x;
session.RemoteAuthentication.TokenIndex = authPacket.RemoteTokenIndex;
remoteNonce = authPacket.RemoteNonce;
session.RemoteAuthentication.Domain = authPacket.Domain;
SendParams()
.AddUInt8(0xa0)
.AddUInt8Array(localNonce)
.Done();
}
else
{
//Console.WriteLine("User not found");
SendParams()
SendParams()
.AddUInt8(0xc0)
.AddUInt8((byte)ExceptionCode.UserOrTokenNotFound)
.AddUInt16(15)
.AddString("Token not found")
.Done();
}
});
}
// Check if user and token exists
else
{
Server.Membership.TokenExists(authPacket.RemoteTokenIndex, authPacket.Domain).Then(x =>
{
if (x != null)
{
session.RemoteAuthentication.Username = x;
session.RemoteAuthentication.TokenIndex = authPacket.RemoteTokenIndex;
remoteNonce = authPacket.RemoteNonce;
session.RemoteAuthentication.Domain = authPacket.Domain;
SendParams()
.AddUInt8(0xa0)
.AddUInt8Array(localNonce)
.Done();
}
else
{
//Console.WriteLine("User not found");
SendParams()
.AddUInt8(0xc0)
.AddUInt8((byte)ExceptionCode.UserOrTokenNotFound)
.AddUInt16(15)
.AddString("Token not found")
.Done();
}
});
}
}
catch (Exception ex)
{
@ -729,7 +822,7 @@ public partial class DistributedConnection : NetworkConnection, IStore
try
{
// Check if guests are allowed
if (Server.Membership.GuestsAllowed)
if (Server.Membership?.GuestsAllowed ?? true)
{
session.RemoteAuthentication.Username = "g-" + Global.GenerateCode();
session.RemoteAuthentication.Domain = authPacket.Domain;
@ -789,31 +882,31 @@ public partial class DistributedConnection : NetworkConnection, IStore
if (pw != null)
{
var hashFunc = SHA256.Create();
//var hash = hashFunc.ComputeHash(BinaryList.ToBytes(pw, remoteNonce, localNonce));
var hash = hashFunc.ComputeHash((new BinaryList())
.AddUInt8Array(pw)
.AddUInt8Array(remoteNonce)
.AddUInt8Array(localNonce)
.ToArray());
//var hash = hashFunc.ComputeHash(BinaryList.ToBytes(pw, remoteNonce, localNonce));
var hash = hashFunc.ComputeHash((new BinaryList())
.AddUInt8Array(pw)
.AddUInt8Array(remoteNonce)
.AddUInt8Array(localNonce)
.ToArray());
if (hash.SequenceEqual(remoteHash))
{
// send our hash
//var localHash = hashFunc.ComputeHash(BinaryList.ToBytes(localNonce, remoteNonce, pw));
//SendParams((byte)0, localHash);
// send our hash
//var localHash = hashFunc.ComputeHash(BinaryList.ToBytes(localNonce, remoteNonce, pw));
//SendParams((byte)0, localHash);
var localHash = hashFunc.ComputeHash((new BinaryList()).AddUInt8Array(localNonce).AddUInt8Array(remoteNonce).AddUInt8Array(pw).ToArray());
var localHash = hashFunc.ComputeHash((new BinaryList()).AddUInt8Array(localNonce).AddUInt8Array(remoteNonce).AddUInt8Array(pw).ToArray());
SendParams().AddUInt8(0).AddUInt8Array(localHash).Done();
readyToEstablish = true;
}
else
{
//Global.Log("auth", LogType.Warning, "U:" + RemoteUsername + " IP:" + Socket.RemoteEndPoint.Address.ToString() + " S:DENIED");
SendParams().AddUInt8(0xc0)
.AddUInt8((byte)ExceptionCode.AccessDenied)
.AddUInt16(13)
.AddString("Access Denied")
.Done();
//Global.Log("auth", LogType.Warning, "U:" + RemoteUsername + " IP:" + Socket.RemoteEndPoint.Address.ToString() + " S:DENIED");
SendParams().AddUInt8(0xc0)
.AddUInt8((byte)ExceptionCode.AccessDenied)
.AddUInt16(13)
.AddString("Access Denied")
.Done();
}
}
});
@ -849,7 +942,7 @@ public partial class DistributedConnection : NetworkConnection, IStore
openReply?.Trigger(true);
OnReady?.Invoke(this);
Server?.Membership.Login(session);
Server?.Membership?.Login(session);
loginDate = DateTime.Now;
}).Error(x =>
@ -862,7 +955,7 @@ public partial class DistributedConnection : NetworkConnection, IStore
ready = true;
openReply?.Trigger(true);
OnReady?.Invoke(this);
Server?.Membership.Login(session);
Server?.Membership?.Login(session);
}
//Global.Log("auth", LogType.Warning, "U:" + RemoteUsername + " IP:" + Socket.RemoteEndPoint.Address.ToString() + " S:AUTH");
@ -988,7 +1081,7 @@ public partial class DistributedConnection : NetworkConnection, IStore
protected override void DataReceived(NetworkBuffer data)
{
// Console.WriteLine("DR " + hostType + " " + data.Available + " " + RemoteEndPoint.ToString());
//Console.WriteLine("DR " + data.Available + " " + RemoteEndPoint.ToString());
var msg = data.Read();
uint offset = 0;
uint ends = (uint)msg.Length;
@ -997,7 +1090,7 @@ public partial class DistributedConnection : NetworkConnection, IStore
var chunkId = (new Random()).Next(1000, 1000000);
var list = new List<Structure>();// double, IIPPacketCommand>();
//var list = new List<Map<string, object>>();// double, IIPPacketCommand>();
this.Socket.Hold();
@ -1127,7 +1220,7 @@ public partial class DistributedConnection : NetworkConnection, IStore
{
try
{
var bag = new AsyncBag();
var bag = new AsyncBag<IResource>();
for (var i = 0; i < resources.Keys.Count; i++)
{
@ -1168,13 +1261,13 @@ public partial class DistributedConnection : NetworkConnection, IStore
return new AsyncReply<bool>(true);
}
public bool Record(IResource resource, string propertyName, object value, ulong age, DateTime dateTime)
public bool Record(IResource resource, string propertyName, object value, ulong? age, DateTime? dateTime)
{
// nothing to do
return true;
}
public bool Modify(IResource resource, string propertyName, object value, ulong age, DateTime dateTime)
public bool Modify(IResource resource, string propertyName, object value, ulong? age, DateTime? dateTime)
{
// nothing to do
return true;
@ -1202,9 +1295,10 @@ public partial class DistributedConnection : NetworkConnection, IStore
throw new NotImplementedException();
}
public AsyncBag<T> Children<T>(IResource resource, string name) where T : IResource
{
throw new Exception("SS");
throw new Exception("Not implemented");
//if (Codec.IsLocalResource(resource, this))
// return new AsyncBag<T>((resource as DistributedResource).children.Where(x => x.GetType() == typeof(T)).Select(x => (T)x));
@ -1214,7 +1308,7 @@ public partial class DistributedConnection : NetworkConnection, IStore
public AsyncBag<T> Parents<T>(IResource resource, string name) where T : IResource
{
throw new Exception("SS");
throw new Exception("Not implemented");
//if (Codec.IsLocalResource(resource, this))
// return (resource as DistributedResource).parents.Where(x => x.GetType() == typeof(T)).Select(x => (T)x);
@ -1253,7 +1347,7 @@ public partial class DistributedConnection : NetworkConnection, IStore
Warehouse.Remove(this);
if (ready)
Server?.Membership.Logout(session);
Server?.Membership?.Logout(session);
ready = false;
}

File diff suppressed because it is too large Load Diff

View File

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

View File

@ -52,7 +52,8 @@ public class DistributedResource : DynamicObject, IResource
/// Raised when the distributed resource is destroyed.
/// </summary>
public event DestroyedEvent OnDestroy;
public event Instance.ResourceModifiedEvent OnModified;
public event PropertyModifiedEvent PropertyModified;
uint instanceId;
DistributedConnection connection;
@ -83,6 +84,8 @@ public class DistributedResource : DynamicObject, IResource
//}
/// <summary>
/// Connection responsible for the distributed resource.
/// </summary>
@ -214,12 +217,10 @@ public class DistributedResource : DynamicObject, IResource
{
var et = Instance.Template.GetEventTemplateByIndex(index);
events[index]?.Invoke(this, args);
Instance.EmitResourceEvent(et.Name, args);
Instance.EmitResourceEvent(et, args);
}
public AsyncReply<object> _InvokeByNamedArguments(byte index, Structure namedArgs)
public AsyncReply<object> _Invoke(byte index, Map<byte, object> args)
{
if (destroyed)
throw new Exception("Trying to access destroyed object");
@ -231,23 +232,7 @@ public class DistributedResource : DynamicObject, IResource
throw new Exception("Function index is incorrect");
return connection.SendInvokeByNamedArguments(instanceId, index, namedArgs);
}
public AsyncReply<object> _InvokeByArrayArguments(byte index, object[] args)
{
if (destroyed)
throw new Exception("Trying to access destroyed object");
if (suspended)
throw new Exception("Trying to access suspended object");
if (index >= Instance.Template.Functions.Length)
throw new Exception("Function index is incorrect");
return connection.SendInvokeByArrayArguments(instanceId, index, args);
return connection.SendInvoke(instanceId, index, args);
}
@ -294,31 +279,43 @@ public class DistributedResource : DynamicObject, IResource
var ft = Instance.Template.GetFunctionTemplateByName(binder.Name);
var reply = new AsyncReply<object>();
if (attached && ft != null)
{
var indexedArgs = new Map<byte, object>();
if (args.Length == 1)
{
// Detect anonymous types
var type = args[0].GetType();
if (Codec.IsAnonymous(type))
{
var namedArgs = new Structure();
var pi = type.GetTypeInfo().GetProperties();
foreach (var p in pi)
namedArgs[p.Name] = p.GetValue(args[0]);
result = _InvokeByNamedArguments(ft.Index, namedArgs);
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
{
result = _InvokeByArrayArguments(ft.Index, args);
indexedArgs.Add((byte)0, args[0]);
result = _Invoke(ft.Index, indexedArgs);
}
}
else
{
result = _InvokeByArrayArguments(ft.Index, args);
for (byte i = 0; i < args.Length; i++)
indexedArgs.Add(i, args[i]);
result = _Invoke(ft.Index, indexedArgs);
}
return true;
}
@ -341,6 +338,20 @@ public class DistributedResource : DynamicObject, IResource
return properties[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)
@ -409,6 +420,7 @@ public class DistributedResource : DynamicObject, IResource
return reply;
}
public override bool TrySetMember(SetMemberBinder binder, object value)
{
if (destroyed)
@ -496,7 +508,7 @@ public class DistributedResource : DynamicObject, IResource
{
if (trigger == ResourceTrigger.Initialize)
this.Instance.ResourceModified += this.OnModified;
this.Instance.PropertyModified += this.PropertyModified;
// do nothing.
return new AsyncReply<bool>(true);

View File

@ -38,6 +38,9 @@ using Esiur.Security.Membership;
namespace Esiur.Net.IIP;
public class DistributedServer : NetworkServer<DistributedConnection>, IResource
{
[Attribute]
public string IP
{
@ -81,6 +84,8 @@ public class DistributedServer : NetworkServer<DistributedConnection>, IResource
set;
}
public event PropertyModifiedEvent PropertyModified;
public AsyncReply<bool> Trigger(ResourceTrigger trigger)
{
if (trigger == ResourceTrigger.Initialize)

View File

@ -170,6 +170,7 @@ public class NetworkBuffer
{
rt = data;
data = new byte[0];
return rt;
}
else
{
@ -200,7 +201,6 @@ public class NetworkBuffer
}
}
return rt;
}
}
}

View File

@ -121,6 +121,8 @@ public abstract class NetworkServer<TConnection> : IDestructible where TConnecti
return;
}
Console.WriteLine("New Socket ... " + DateTime.Now);
var c = new TConnection();
//c.OnClose += ClientDisconnectedEventReceiver;
c.Assign(s);

View File

@ -222,7 +222,7 @@ class IIPAuthPacket : Packet
if (NotEnough(offset, ends, 2))
return -dataLengthNeeded;
var length = data.GetUInt16(offset);
var length = data.GetUInt16(offset, Endian.Little);
offset += 2;
@ -311,7 +311,7 @@ class IIPAuthPacket : Packet
offset += 32;
RemoteTokenIndex = data.GetUInt64(offset);
RemoteTokenIndex = data.GetUInt64(offset, Endian.Little);
offset += 8;
}
}
@ -321,7 +321,7 @@ class IIPAuthPacket : Packet
if (NotEnough(offset, ends, 2))
return -dataLengthNeeded;
var keyLength = data.GetUInt16(offset);
var keyLength = data.GetUInt16(offset, Endian.Little);
offset += 2;
@ -369,7 +369,7 @@ class IIPAuthPacket : Packet
if (NotEnough(offset, ends, 2))
return -dataLengthNeeded;
var keyLength = data.GetUInt16(offset);
var keyLength = data.GetUInt16(offset, Endian.Little);
offset += 2;
@ -394,7 +394,7 @@ class IIPAuthPacket : Packet
ErrorCode = data[offset++];
var cl = data.GetUInt16(offset);
var cl = data.GetUInt16(offset, Endian.Little);
offset += 2;
if (NotEnough(offset, ends, cl))

View File

@ -109,8 +109,8 @@ class IIPPacket : Packet
LinkTemplates,
// Request Invoke
InvokeFunctionArrayArguments = 0x10,
InvokeFunctionNamedArguments,
InvokeFunction = 0x10,
Reserved,
Listen,
Unlisten,
SetProperty,
@ -173,6 +173,7 @@ class IIPPacket : Packet
set;
}
public TransmissionType? DataType { get; set; }
public uint ResourceId { get; set; }
public uint NewResourceId { get; set; }
@ -181,11 +182,13 @@ class IIPPacket : Packet
public uint StoreId { get; set; }
public ulong ResourceAge { get; set; }
public byte[] Content { get; set; }
//public byte[] Content { get; set; }
public ushort ErrorCode { get; set; }
public string ErrorMessage { get; set; }
public string ClassName { get; set; }
public string ResourceLink { get; set; }
public string ResourceName { get; set; }
public Guid ClassId { get; set; }
public byte MethodIndex { get; set; }
public string MethodName { get; set; }
@ -236,7 +239,7 @@ class IIPPacket : Packet
if (NotEnough(offset, ends, 4))
return -dataLengthNeeded;
ResourceId = data.GetUInt32(offset);
ResourceId = data.GetUInt32(offset, Endian.Little);
offset += 4;
}
else if (Command == IIPPacketCommand.Report)
@ -246,7 +249,7 @@ class IIPPacket : Packet
if (NotEnough(offset, ends, 4))
return -dataLengthNeeded;
CallbackId = data.GetUInt32(offset);
CallbackId = data.GetUInt32(offset, Endian.Little);
offset += 4;
}
else
@ -257,7 +260,7 @@ class IIPPacket : Packet
if (NotEnough(offset, ends, 4))
return -dataLengthNeeded;
CallbackId = data.GetUInt32(offset);
CallbackId = data.GetUInt32(offset, Endian.Little);
offset += 4;
}
@ -268,7 +271,7 @@ class IIPPacket : Packet
if (NotEnough(offset, ends, 4))
return -dataLengthNeeded;
NewResourceId = data.GetUInt32(offset);
NewResourceId = data.GetUInt32(offset, Endian.Little);
offset += 4;
}
@ -282,7 +285,7 @@ class IIPPacket : Packet
if (NotEnough(offset, ends, 4))
return -dataLengthNeeded;
ChildId = data.GetUInt32(offset);
ChildId = data.GetUInt32(offset, Endian.Little);
offset += 4;
}
else if (Event == IIPPacketEvent.Renamed)
@ -290,13 +293,15 @@ class IIPPacket : Packet
if (NotEnough(offset, ends, 2))
return -dataLengthNeeded;
var cl = data.GetUInt16(offset);
var cl = data.GetUInt16(offset, Endian.Little);
offset += 2;
if (NotEnough(offset, ends, cl))
return -dataLengthNeeded;
Content = data.Clip(offset, cl);
ResourceName = data.GetString(offset, cl);
//Content = data.Clip(offset, cl);
offset += cl;
}
@ -308,31 +313,19 @@ class IIPPacket : Packet
MethodIndex = data[offset++];
var dt = (DataType)data[offset++];
var size = dt.Size();// Codec.SizeOf(dt);
(var size, DataType) = TransmissionType.Parse(data, offset, ends);
if (size < 0)
{
if (NotEnough(offset, ends, 4))
return -dataLengthNeeded;
var cl = data.GetUInt32(offset);
offset += 4;
//var dt = (DataType)data[offset++];
//var size = dt.Size();// Codec.SizeOf(dt);
if (NotEnough(offset, ends, cl))
return -dataLengthNeeded;
if (DataType == null)
return -(int)size;
Content = data.Clip(offset - 5, cl + 5);
offset += cl;
}
else
{
if (NotEnough(offset, ends, (uint)size))
return -dataLengthNeeded;
//Content = data.Clip(DataType.Value.Offset, (uint)DataType.Value.ContentLength);
offset += (uint)size;
Content = data.Clip(offset - 1, (uint)size + 1);
offset += (uint)size;
}
}
//else if (Event == IIPPacketEvent.EventOccurred)
//{
@ -357,13 +350,14 @@ class IIPPacket : Packet
if (NotEnough(offset, ends, 4))
return -dataLengthNeeded;
var cl = data.GetUInt32(offset);
var cl = data.GetUInt32(offset, Endian.Little);
offset += 4;
if (NotEnough(offset, ends, cl))
return -dataLengthNeeded;
Content = data.Clip(offset, cl);
//@TODO: Fix this
//Content = data.Clip(offset, cl);
offset += cl;
}
@ -375,7 +369,7 @@ class IIPPacket : Packet
if (NotEnough(offset, ends, 4))
return -dataLengthNeeded;
ResourceId = data.GetUInt32(offset);
ResourceId = data.GetUInt32(offset, Endian.Little);
offset += 4;
}
else if (Action == IIPPacketAction.ReattachResource)
@ -383,10 +377,10 @@ class IIPPacket : Packet
if (NotEnough(offset, ends, 12))
return -dataLengthNeeded;
ResourceId = data.GetUInt32(offset);
ResourceId = data.GetUInt32(offset, Endian.Little);
offset += 4;
ResourceAge = data.GetUInt64(offset);
ResourceAge = data.GetUInt64(offset, Endian.Little);
offset += 8;
}
@ -395,7 +389,7 @@ class IIPPacket : Packet
if (NotEnough(offset, ends, 4))
return -dataLengthNeeded;
ResourceId = data.GetUInt32(offset);
ResourceId = data.GetUInt32(offset, Endian.Little);
offset += 4;
}
@ -404,25 +398,26 @@ class IIPPacket : Packet
if (NotEnough(offset, ends, 12))
return -dataLengthNeeded;
StoreId = data.GetUInt32(offset);
StoreId = data.GetUInt32(offset, Endian.Little);
offset += 4;
ResourceId = data.GetUInt32(offset);
ResourceId = data.GetUInt32(offset, Endian.Little);
offset += 4;
var cl = data.GetUInt32(offset);
var cl = data.GetUInt32(offset, Endian.Little);
offset += 4;
if (NotEnough(offset, ends, cl))
return -dataLengthNeeded;
this.Content = data.Clip(offset, cl);
// @TODO: fix this
//this.Content = data.Clip(offset, cl);
}
else if (Action == IIPPacketAction.DeleteResource)
{
if (NotEnough(offset, ends, 4))
return -dataLengthNeeded;
ResourceId = data.GetUInt32(offset);
ResourceId = data.GetUInt32(offset, Endian.Little);
offset += 4;
}
@ -432,9 +427,9 @@ class IIPPacket : Packet
if (NotEnough(offset, ends, 8))
return -dataLengthNeeded;
ResourceId = data.GetUInt32(offset);
ResourceId = data.GetUInt32(offset, Endian.Little);
offset += 4;
ChildId = data.GetUInt32(offset);
ChildId = data.GetUInt32(offset, Endian.Little);
offset += 4;
}
else if (Action == IIPPacketAction.RenameResource)
@ -442,15 +437,16 @@ class IIPPacket : Packet
if (NotEnough(offset, ends, 6))
return -dataLengthNeeded;
ResourceId = data.GetUInt32(offset);
ResourceId = data.GetUInt32(offset, Endian.Little);
offset += 4;
var cl = data.GetUInt16(offset);
var cl = data.GetUInt16(offset, Endian.Little);
offset += 2;
if (NotEnough(offset, ends, cl))
return -dataLengthNeeded;
Content = data.Clip(offset, cl);
ResourceName = data.GetString(offset, cl);
//Content = data.Clip(offset, cl);
offset += cl;
}
else if (Action == IIPPacketAction.TemplateFromClassName)
@ -481,7 +477,7 @@ class IIPPacket : Packet
if (NotEnough(offset, ends, 4))
return -dataLengthNeeded;
ResourceId = data.GetUInt32(offset);
ResourceId = data.GetUInt32(offset, Endian.Little);
offset += 4;
}
else if (Action == IIPPacketAction.QueryLink
@ -490,7 +486,7 @@ class IIPPacket : Packet
if (NotEnough(offset, ends, 2))
return -dataLengthNeeded;
var cl = data.GetUInt16(offset);
var cl = data.GetUInt16(offset, Endian.Little);
offset += 2;
if (NotEnough(offset, ends, cl))
@ -505,7 +501,7 @@ class IIPPacket : Packet
if (NotEnough(offset, ends, 4))
return -dataLengthNeeded;
ResourceId = data.GetUInt32(offset);
ResourceId = data.GetUInt32(offset, Endian.Little);
offset += 4;
}
else if (Action == IIPPacketAction.ResourceHistory)
@ -513,35 +509,42 @@ class IIPPacket : Packet
if (NotEnough(offset, ends, 20))
return -dataLengthNeeded;
ResourceId = data.GetUInt32(offset);
ResourceId = data.GetUInt32(offset, Endian.Little);
offset += 4;
FromDate = data.GetDateTime(offset);
FromDate = data.GetDateTime(offset, Endian.Little);
offset += 8;
ToDate = data.GetDateTime(offset);
ToDate = data.GetDateTime(offset, Endian.Little);
offset += 8;
}
else if (Action == IIPPacketAction.InvokeFunctionArrayArguments
|| Action == IIPPacketAction.InvokeFunctionNamedArguments)
else if (Action == IIPPacketAction.InvokeFunction)
{
if (NotEnough(offset, ends, 9))
if (NotEnough(offset, ends, 6))
return -dataLengthNeeded;
ResourceId = data.GetUInt32(offset);
ResourceId = data.GetUInt32(offset, Endian.Little);
offset += 4;
MethodIndex = data[offset++];
var cl = data.GetUInt32(offset);
offset += 4;
if (NotEnough(offset, ends, cl))
return -dataLengthNeeded;
(var size, DataType) = TransmissionType.Parse(data, offset, ends);
Content = data.Clip(offset, cl);
offset += cl;
if (DataType == null)
return -(int)size;
offset += (uint)size;
//var cl = data.GetUInt32(offset);
//offset += 4;
//if (NotEnough(offset, ends, cl))
// return -dataLengthNeeded;
//Content = data.Clip(offset, cl);
//offset += cl;
}
else if (Action == IIPPacketAction.Listen
@ -550,7 +553,7 @@ class IIPPacket : Packet
if (NotEnough(offset, ends, 5))
return -dataLengthNeeded;
ResourceId = data.GetUInt32(offset);
ResourceId = data.GetUInt32(offset, Endian.Little);
offset += 4;
MethodIndex = data[offset++];
@ -575,37 +578,21 @@ class IIPPacket : Packet
if (NotEnough(offset, ends, 6))
return -dataLengthNeeded;
ResourceId = data.GetUInt32(offset);
ResourceId = data.GetUInt32(offset, Endian.Little);
offset += 4;
MethodIndex = data[offset++];
(var size, DataType) = TransmissionType.Parse(data, offset, ends);
var dt = (DataType)data[offset++];
var size = dt.Size();// Codec.SizeOf(dt);
if (DataType == null)
return -(int)size;
if (size < 0)
{
if (NotEnough(offset, ends, 4))
return -dataLengthNeeded;
var cl = data.GetUInt32(offset);
offset += 4;
//Content = data.Clip(DataType.Value.Offset, (uint)DataType.Value.ContentLength);
if (NotEnough(offset, ends, cl))
return -dataLengthNeeded;
offset += (uint)size;
Content = data.Clip(offset - 5, cl + 5);
offset += cl;
}
else
{
if (NotEnough(offset, ends, (uint)size))
return -dataLengthNeeded;
Content = data.Clip(offset - 1, (uint)size + 1);
offset += (uint)size;
}
}
// Attributes
else if (Action == IIPPacketAction.UpdateAllAttributes
@ -616,15 +603,16 @@ class IIPPacket : Packet
if (NotEnough(offset, ends, 8))
return -dataLengthNeeded;
ResourceId = data.GetUInt32(offset);
ResourceId = data.GetUInt32(offset, Endian.Little);
offset += 4;
var cl = data.GetUInt32(offset);
var cl = data.GetUInt32(offset, Endian.Little);
offset += 4;
if (NotEnough(offset, ends, cl))
return -dataLengthNeeded;
Content = data.Clip(offset, cl);
// @TODO: fix this
//Content = data.Clip(offset, cl);
offset += cl;
}
}
@ -640,10 +628,10 @@ class IIPPacket : Packet
ClassId = data.GetGuid(offset);
offset += 16;
ResourceAge = data.GetUInt64(offset);
ResourceAge = data.GetUInt64(offset, Endian.Little);
offset += 8;
uint cl = data.GetUInt16(offset);
uint cl = data.GetUInt16(offset, Endian.Little);
offset += 2;
if (NotEnough(offset, ends, cl))
@ -652,17 +640,19 @@ class IIPPacket : Packet
ResourceLink = data.GetString(offset, cl);
offset += cl;
if (NotEnough(offset, ends, 4))
return -dataLengthNeeded;
//if (NotEnough(offset, ends, 4))
// return -dataLengthNeeded;
cl = data.GetUInt32(offset);
offset += 4;
if (NotEnough(offset, ends, cl))
return -dataLengthNeeded;
(var size, DataType) = TransmissionType.Parse(data, offset, ends);
if (DataType == null)
return -(int)size;
offset += (uint)size;
//Content = data.Clip(DataType.Value.Offset, (uint)DataType.Value.ContentLength);
Content = data.Clip(offset, cl);
offset += cl;
}
else if (Action == IIPPacketAction.DetachResource)
{
@ -676,7 +666,7 @@ class IIPPacket : Packet
//ClassId = data.GetGuid(offset);
//offset += 16;
ResourceId = data.GetUInt32(offset);
ResourceId = data.GetUInt32(offset, Endian.Little);
offset += 4;
}
@ -697,51 +687,40 @@ class IIPPacket : Packet
|| Action == IIPPacketAction.GetAllAttributes
|| Action == IIPPacketAction.GetAttributes)
{
if (NotEnough(offset, ends, 4))
if (NotEnough(offset, ends, 1))
return -dataLengthNeeded;
var cl = data.GetUInt32(offset);
offset += 4;
(var size, DataType) = TransmissionType.Parse(data, offset, ends );
if (NotEnough(offset, ends, cl))
return -dataLengthNeeded;
if (DataType == null)
return -(int)size;
Content = data.Clip(offset, cl);
offset += cl;
offset += (uint)size;
//var cl = data.GetUInt32(offset);
//offset += 4;
//if (NotEnough(offset, ends, cl))
// return -dataLengthNeeded;
//Content = data.Clip(offset, cl);
//offset += cl;
}
else if (Action == IIPPacketAction.InvokeFunctionArrayArguments
|| Action == IIPPacketAction.InvokeFunctionNamedArguments)
else if (Action == IIPPacketAction.InvokeFunction)
//|| Action == IIPPacketAction.GetProperty
//|| Action == IIPPacketAction.GetPropertyIfModified)
{
if (NotEnough(offset, ends, 1))
return -dataLengthNeeded;
var dt = (DataType)data[offset++];
var size = dt.Size();// Codec.SizeOf(dt);
(var size, DataType) = TransmissionType.Parse(data, offset, ends);
if (size < 0)
{
if (NotEnough(offset, ends, 4))
return -dataLengthNeeded;
if (DataType == null)
return -(int)size;
var cl = data.GetUInt32(offset);
offset += 4;
offset += (uint)size;
if (NotEnough(offset, ends, cl))
return -dataLengthNeeded;
Content = data.Clip(offset - 5, cl + 5);
offset += cl;
}
else
{
if (NotEnough(offset, ends, (uint)size))
return -dataLengthNeeded;
Content = data.Clip(offset - 1, (uint)size + 1);
offset += (uint)size;
}
//Content = data.Clip(DataType.Value.Offset, (uint)DataType.Value.ContentLength);
}
else if (Action == IIPPacketAction.SetProperty
|| Action == IIPPacketAction.Listen
@ -757,7 +736,7 @@ class IIPPacket : Packet
if (NotEnough(offset, ends, 2))
return -dataLengthNeeded;
ErrorCode = data.GetUInt16(offset);
ErrorCode = data.GetUInt16(offset, Endian.Little);
offset += 2;
}
else if (Report == IIPPacketReport.ExecutionError)
@ -765,13 +744,13 @@ class IIPPacket : Packet
if (NotEnough(offset, ends, 2))
return -dataLengthNeeded;
ErrorCode = data.GetUInt16(offset);
ErrorCode = data.GetUInt16(offset, Endian.Little);
offset += 2;
if (NotEnough(offset, ends, 2))
return -dataLengthNeeded;
var cl = data.GetUInt16(offset);
var cl = data.GetUInt16(offset, Endian.Little);
offset += 2;
if (NotEnough(offset, ends, cl))
@ -785,9 +764,9 @@ class IIPPacket : Packet
if (NotEnough(offset, ends, 8))
return -dataLengthNeeded;
ProgressValue = data.GetInt32(offset);
ProgressValue = data.GetInt32(offset, Endian.Little);
offset += 4;
ProgressMax = data.GetInt32(offset);
ProgressMax = data.GetInt32(offset, Endian.Little);
offset += 4;
}
else if (Report == IIPPacketReport.ChunkStream)
@ -795,31 +774,16 @@ class IIPPacket : Packet
if (NotEnough(offset, ends, 1))
return -dataLengthNeeded;
var dt = (DataType)data[offset++];
var size = dt.Size();// Codec.SizeOf(dt);
if (size < 0)
{
if (NotEnough(offset, ends, 4))
return -dataLengthNeeded;
(var size, DataType) = TransmissionType.Parse(Data, offset, ends );
var cl = data.GetUInt32(offset);
offset += 4;
if (DataType == null)
return -(int)size;
if (NotEnough(offset, ends, cl))
return -dataLengthNeeded;
offset += (uint)size;
Content = data.Clip(offset - 5, cl + 5);
offset += cl;
}
else
{
if (NotEnough(offset, ends, (uint)size))
return -dataLengthNeeded;
//Content = data.Clip(DataType.Value.Offset, (uint)DataType.Value.ContentLength);
Content = data.Clip(offset - 1, (uint)size + 1);
offset += (uint)size;
}
}
}

View File

@ -88,13 +88,13 @@ public class WebsocketPacket : Packet
// 4 bytes
{
pkt.Add((byte)((Mask ? 0x80 : 0x0) | 127));
pkt.AddRange(DC.ToBytes((UInt64)Message.LongCount()));
pkt.AddRange(DC.ToBytes((UInt64)Message.LongCount(), Endian.Big));
}
else if (Message.Length > 125)
// 2 bytes
{
pkt.Add((byte)((Mask ? 0x80 : 0x0) | 126));
pkt.AddRange(DC.ToBytes((UInt16)Message.Length));
pkt.AddRange(DC.ToBytes((UInt16)Message.Length, Endian.Big));
}
else
{
@ -145,7 +145,7 @@ public class WebsocketPacket : Packet
//Console.WriteLine("stage 2 " + needed);
return length - needed;
}
PayloadLength = data.GetUInt16(offset);
PayloadLength = data.GetUInt16(offset, Endian.Big);
offset += 2;
}
else if (PayloadLength == 127)
@ -157,7 +157,7 @@ public class WebsocketPacket : Packet
return length - needed;
}
PayloadLength = data.GetInt64(offset);
PayloadLength = data.GetInt64(offset, Endian.Big);
offset += 8;
}

View File

@ -36,6 +36,7 @@ namespace Esiur.Net.TCP;
public abstract class TCPFilter : IResource
{
public Instance Instance
{
get;
@ -43,6 +44,7 @@ public abstract class TCPFilter : IResource
}
public event DestroyedEvent OnDestroy;
public abstract AsyncReply<bool> Trigger(ResourceTrigger trigger);

View File

@ -66,7 +66,6 @@ public class TCPServer : NetworkServer<TCPConnection>, IResource
TCPFilter[] filters = null;
public AsyncReply<bool> Trigger(ResourceTrigger trigger)
{
if (trigger == ResourceTrigger.Initialize)

View File

@ -35,6 +35,9 @@ using Esiur.Resource;
namespace Esiur.Net.UDP;
public abstract class UDPFilter : IResource
{
public Instance Instance
{
get;

View File

@ -47,6 +47,7 @@ public class UDPServer : IResource
UDPFilter[] filters = new UDPFilter[0];
public event DestroyedEvent OnDestroy;
public Instance Instance
{