2
0
mirror of https://github.com/esiur/esiur-dotnet.git synced 2025-09-13 20:43:19 +00:00
This commit is contained in:
2025-08-24 05:58:40 +03:00
parent b12939e109
commit a1353a03ad
7 changed files with 92 additions and 55 deletions

View File

@@ -123,29 +123,29 @@ public static class Codec
DataDeserializer.ResourceParser8, DataDeserializer.ResourceParser8,
}, },
new SyncParser[]{ new SyncParser[]{
DataDeserializer.Int16Parser,
DataDeserializer.UInt16Parser, DataDeserializer.UInt16Parser,
DataDeserializer.Int16Parser,
DataDeserializer.Char16Parser, DataDeserializer.Char16Parser,
DataDeserializer.LocalResourceParser16, DataDeserializer.LocalResourceParser16,
DataDeserializer.ResourceParser16, DataDeserializer.ResourceParser16,
}, },
new SyncParser[]{ new SyncParser[]{
DataDeserializer.Int32Parser,
DataDeserializer.UInt32Parser, DataDeserializer.UInt32Parser,
DataDeserializer.Int32Parser,
DataDeserializer.Float32Parser, DataDeserializer.Float32Parser,
DataDeserializer.LocalResourceParser32, DataDeserializer.LocalResourceParser32,
DataDeserializer.ResourceParser32, DataDeserializer.ResourceParser32,
}, },
new SyncParser[]{ new SyncParser[]{
DataDeserializer.Int64Parser,
DataDeserializer.UInt64Parser, DataDeserializer.UInt64Parser,
DataDeserializer.Int64Parser,
DataDeserializer.Float64Parser, DataDeserializer.Float64Parser,
DataDeserializer.DateTimeParser, DataDeserializer.DateTimeParser,
}, },
new SyncParser[] new SyncParser[]
{ {
DataDeserializer.Int128Parser, // int 128
DataDeserializer.UInt128Parser, // uint 128 DataDeserializer.UInt128Parser, // uint 128
DataDeserializer.Int128Parser, // int 128
DataDeserializer.Float128Parser, DataDeserializer.Float128Parser,
} }
}; };

View File

@@ -114,10 +114,16 @@ public static class DataSerializer
public static (TransmissionTypeIdentifier, byte[]) EnumComposer(object value, DistributedConnection connection) public static (TransmissionTypeIdentifier, byte[]) EnumComposer(object value, DistributedConnection connection)
{ {
Console.WriteLine(value.GetType().Name);
if (value == null) if (value == null)
return (TransmissionTypeIdentifier.Null, new byte[0]); return (TransmissionTypeIdentifier.Null, new byte[0]);
var template = connection.Instance.Warehouse.GetTemplateByType(value.GetType()); var warehouse = connection?.Instance?.Warehouse ?? connection?.Server?.Instance?.Warehouse;
if (warehouse == null)
throw new Exception("Warehouse not set.");
var template = warehouse.GetTemplateByType(value.GetType());
var intVal = Convert.ChangeType(value, (value as Enum).GetTypeCode()); var intVal = Convert.ChangeType(value, (value as Enum).GetTypeCode());

View File

@@ -57,6 +57,23 @@ namespace Esiur.Data
//e6 = data[offset++]; //e6 = data[offset++];
} }
public unsafe override int GetHashCode()
{
unchecked
{
fixed (byte* p = Data)
{
ulong u0 = *(ulong*)p;
ulong u1 = *(ulong*)(p + 8);
// simple mixing of two 64-bit halves
return ((int)u0 ^ (int)(u0 >> 32)) ^
((int)u1 ^ (int)(u1 >> 32));
}
}
}
public UUID(byte[] data) { public UUID(byte[] data) {
if (data.Length != 16) if (data.Length != 16)
@@ -88,6 +105,14 @@ namespace Esiur.Data
//return $"{a1.ToString("x2")}{a2.ToString("x2")}{a3.ToString("x2")}{a4.ToString("x2")}-{b1.ToString("x2")}{b2.ToString("x2")}-{c1.ToString("x2")}{c2.ToString("x2")}-{d1.ToString("x2")}{d2.ToString("x2")}-{e1.ToString("x2")}{e2.ToString("x2")}{e3.ToString("x2")}{e4.ToString("x2")}{e5.ToString("x2")}{e6.ToString("x2")}"; //return $"{a1.ToString("x2")}{a2.ToString("x2")}{a3.ToString("x2")}{a4.ToString("x2")}-{b1.ToString("x2")}{b2.ToString("x2")}-{c1.ToString("x2")}{c2.ToString("x2")}-{d1.ToString("x2")}{d2.ToString("x2")}-{e1.ToString("x2")}{e2.ToString("x2")}{e3.ToString("x2")}{e4.ToString("x2")}{e5.ToString("x2")}{e6.ToString("x2")}";
} }
public override bool Equals(object obj)
{
if (obj is UUID b)
return Data.SequenceEqual(b.Data);
return false;
}
public static bool operator == (UUID a, UUID b) public static bool operator == (UUID a, UUID b)
{ {
return a.Data.SequenceEqual(b.Data); return a.Data.SequenceEqual(b.Data);

View File

@@ -764,7 +764,7 @@ public partial class DistributedConnection : NetworkConnection, IStore
if (this.Instance == null) if (this.Instance == null)
{ {
Instance.Warehouse.Put(Server + "/" + session.AuthorizedAccount.Replace("/", "_"), this) Server.Instance.Warehouse.Put(Server + "/" + session.AuthorizedAccount.Replace("/", "_"), this)
.Then(x => .Then(x =>
{ {
openReply?.Trigger(true); openReply?.Trigger(true);
@@ -896,7 +896,7 @@ public partial class DistributedConnection : NetworkConnection, IStore
var dataType = authPacket.DataType.Value; var dataType = authPacket.DataType.Value;
var (_, parsed) = Codec.ParseSync(data, dataType.Offset, Instance.Warehouse, dataType); var (_, parsed) = Codec.ParseSync(data, dataType.Offset, Server.Instance.Warehouse, dataType);
var rt = (Map<byte, object>)parsed; var rt = (Map<byte, object>)parsed;
@@ -1232,7 +1232,7 @@ public partial class DistributedConnection : NetworkConnection, IStore
if (this.Instance == null) if (this.Instance == null)
{ {
Instance.Warehouse.Put( Server.Instance.Warehouse.Put(
Server.Instance.Link + "/" + this.GetHashCode().ToString().Replace("/", "_"), this) Server.Instance.Link + "/" + this.GetHashCode().ToString().Replace("/", "_"), this)
.Then(x => .Then(x =>
{ {

View File

@@ -11,6 +11,6 @@ namespace Esiur.Net.Packets
Email = 2, Email = 2,
SMS = 3, SMS = 3,
App = 4, // Authenticator app App = 4, // Authenticator app
ThirdParty = 5, // usualy a second person ThirdParty = 5, // usually a second person
} }
} }

View File

@@ -22,22 +22,23 @@ SOFTWARE.
*/ */
using Esiur.Data;
using Esiur.Core; using Esiur.Core;
using Esiur.Data;
using Esiur.Misc;
using Esiur.Net.IIP;
using Esiur.Net.Packets;
using Esiur.Proxy; using Esiur.Proxy;
using Esiur.Resource.Template; using Esiur.Resource.Template;
using Esiur.Security.Permissions; using Esiur.Security.Permissions;
using System; using System;
using System.Collections;
using System.Collections.Concurrent;
using System.Collections.Generic; using System.Collections.Generic;
using System.Data;
using System.Linq; using System.Linq;
using System.Text; using System.Text;
using System.Threading.Tasks;
using Esiur.Net.IIP;
using System.Text.RegularExpressions; using System.Text.RegularExpressions;
using Esiur.Misc; using System.Threading.Tasks;
using System.Collections.Concurrent;
using System.Collections;
using System.Data;
namespace Esiur.Resource; namespace Esiur.Resource;
@@ -85,6 +86,11 @@ public class Warehouse
Protocols.Add("iip", Protocols.Add("iip",
async (name, attributes) async (name, attributes)
=> await New<DistributedConnection>(name, null, attributes)); => await New<DistributedConnection>(name, null, attributes));
new TypeTemplate(typeof(IIPAuthPacketIAuthHeader), this);
new TypeTemplate(typeof(IIPAuthPacketIAuthDestination), this);
new TypeTemplate(typeof(IIPAuthPacketIAuthFormat), this);
} }
@@ -355,41 +361,41 @@ public class Warehouse
if (store == null) if (store == null)
throw new Exception("Resource store is not set."); throw new Exception("Resource store is not set.");
//if (store == null) //if (store == null)
//{ //{
// // assign parent's store as a store // // assign parent's store as a store
// if (parent != null) // if (parent != null)
// { // {
// // assign parent as a store // // assign parent as a store
// if (parent is IStore) // if (parent is IStore)
// { // {
// store = (IStore)parent; // store = (IStore)parent;
// List<WeakReference<IResource>> list; // List<WeakReference<IResource>> list;
// if (stores.TryGetValue(store, out list)) // if (stores.TryGetValue(store, out list))
// lock (((ICollection)list).SyncRoot) // lock (((ICollection)list).SyncRoot)
// list.Add(resourceReference); // list.Add(resourceReference);
// //stores[store].Add(resourceReference); // //stores[store].Add(resourceReference);
// } // }
// else // else
// { // {
// store = parent.Instance.Store; // store = parent.Instance.Store;
// List<WeakReference<IResource>> list; // List<WeakReference<IResource>> list;
// if (stores.TryGetValue(store, out list)) // if (stores.TryGetValue(store, out list))
// lock (((ICollection)list).SyncRoot) // lock (((ICollection)list).SyncRoot)
// list.Add(resourceReference); // list.Add(resourceReference);
// } // }
// } // }
// // assign self as a store (root store) // // assign self as a store (root store)
// else if (resource is IStore) // else if (resource is IStore)
// { // {
// store = (IStore)resource; // store = (IStore)resource;
// } // }
// else // else
// throw new Exception("Can't find a store for the resource."); // throw new Exception("Can't find a store for the resource.");
//} //}
resource.Instance = new Instance(this, resourceCounter++, instanceName, resource, store, customTemplate, age); resource.Instance = new Instance(this, resourceCounter++, instanceName, resource, store, customTemplate, age);
if (attributes != null) if (attributes != null)
if (attributes is Map<string, object> attrs) if (attributes is Map<string, object> attrs)

View File

@@ -27,7 +27,7 @@ namespace Esiur.Security.Membership
public AuthorizationRequest(Map<IIPAuthPacketIAuthHeader, object> headers) public AuthorizationRequest(Map<IIPAuthPacketIAuthHeader, object> headers)
{ {
Reference = (uint)headers[IIPAuthPacketIAuthHeader.Reference]; Reference = (uint)headers[IIPAuthPacketIAuthHeader.Reference];
Destination = (IIPAuthPacketIAuthDestination)headers[IIPAuthPacketIAuthHeader.Destination]; Destination =(IIPAuthPacketIAuthDestination)headers[IIPAuthPacketIAuthHeader.Destination];
Clue = (string)headers[IIPAuthPacketIAuthHeader.Clue]; Clue = (string)headers[IIPAuthPacketIAuthHeader.Clue];
if (headers.ContainsKey(IIPAuthPacketIAuthHeader.RequiredFormat)) if (headers.ContainsKey(IIPAuthPacketIAuthHeader.RequiredFormat))