#1 Re: mORMot 2 » ECDSA private and public keys » 2024-09-21 18:01:23

And this is an example I created a while ago when I was researching mORMot2.

https://gist.github.com/Coldzer0/448f5b … 23a0de456f

#2 Re: mORMot 2 » ECDSA private and public keys » 2024-09-21 17:59:03

Prometeus wrote:

Ab,

I always try to understand what I am doing. Believe me, I avoid asking in this forum because of the intimidating way you respond to some people here, without knowing precisely what each user may have done before asking, but for this case, it simply didn't work. I also tried to google some responses using mormot stuff, but I also found nothing.  I didn't invent the private key. There is one page with some steps to find a final result, starting with a 256-bit private key given by them (the one used in my post, as well as the result public key from the original private key, also posted there). It is a 256-bit private key as it is supposed to be, the SAME SIZE of the one used in your 'test.core.ecc', line 89. In fact, I just realized that the key you used in that example also doesn't pass the test above ('DC5B79BD481E536DD8075D06C18D42B25B557B4671017BA2A26102B69FD9B70A'). So, I am using the same functions used in your tests and it is not working. I just need to calculate a 256-bit public key for a well-generated 256-bit private key, as is the case in my original question, and I am trying to use the mormot one because looks like they are fast.

I would recommend making sure that the one you are using is ecc256r1 and not ec25519, Because mORMot2 only support the ecc256r1.

#3 Re: mORMot 2 » Discord Server for mORMot » 2024-09-01 16:26:30

That's great; I will create a server, create the channels and other needed stuff, and send you the link to publish.

#4 mORMot 2 » Discord Server for mORMot » 2024-08-31 20:07:12

Coldzer0
Replies: 2

Hello All,

mORMot2 is an excellent framework that deserves to be known more in the development comminutes.
In the last few years, Many people have been using Discord to create communities related to the development of their projects.

@ab Have you ever considered creating a Discord Server for mORMot development?

It's viral and attracts a lot of attention. It's easy to interact with people fast.
Plus, the voice chat element is perfect; people can share their work or do live streaming, helping each other.

And I would love to hear what people around here think about this.

Regareds.

#5 Re: mORMot 2 » mORMot 2 log file creation settings » 2024-08-26 12:22:06

You don't have to edit the mormot2 source code.
All you need to do is add "mormot.core.buffers, mormot.core.zip" in your uses.

And at the start of your app or the log init part
"LogCompressAlgo := AlgoGZFast;"

#6 Re: mORMot 2 » Does mORMot2 have middleware similar to TMS Sparkle » 2024-07-12 09:55:47

In my projects, I'm using OnBeforeBody. It's a good point to check for API tokens or header values.

For example, I've had this in one of my projects.

function TMainServer.BeforeBody(var aUrl, aMethod, aInHeaders, aInContentType, aRemoteIP, aBearerToken: RawUtf8; aContentLength: Int64; aFlags: THttpServerRequestFlags): cardinal;
var
  AuthData : String;
Begin
  // Always return HTTP_UNAUTHORIZED if there's any problem ^_^
  Result := HTTP_UNAUTHORIZED;

  // If user asks for time/ping we allow it
  if (LowerCase(aUrl) = '/api/v1/time') or (LowerCase(aUrl) = '/api/v1/ping') Then
  begin
    Exit(HTTP_SUCCESS);
  end;

  if aBearerToken <> '' then
  begin
    AuthData := Base64ToBin(aBearerToken);
    // Check Telegram webapp initData
    if IsValidTelegramUser(AuthData) then
    begin
      if IsAllowedUser(GetUserIDFromToken(AuthData)) then
        Result := HTTP_SUCCESS;
    end;
  end;
End;

#8 Re: mORMot 2 » IDocList/IDocDict JSON for Delphi and FPC » 2024-03-23 11:54:26

Hello,

I recently started using IDocDict and IDocList, and everything works well.
But there's a small thing I can't figure out.

Is there a way to read a value from a JSON path, for example, this data

{"@type":"updateNewMessage","message":{"@type":"message","id":123456789,"sender_id":{"@type":"messageSenderUser","user_id":123456789},"chat_id":123456789,"is_outgoing":false,"is_pinned":false,"can_be_edited":false,"can_be_forwarded":true,"can_be_replied_in_another_chat":true,"can_be_saved":true,"can_be_deleted_only_for_self":true,"can_be_deleted_for_all_users":true,"can_get_added_reactions":false,"can_get_statistics":false,"can_get_message_thread":false,"can_get_read_date":false,"can_get_viewers":false,"can_get_media_timestamp_links":false,"can_report_reactions":false,"has_timestamped_media":true,"is_channel_post":false,"is_topic_message":false,"contains_unread_mention":false,"date":1711194238,"edit_date":0,"unread_reactions":[],"message_thread_id":0,"self_destruct_in":0.000000,"auto_delete_in":0.000000,"via_bot_user_id":0,"author_signature":"","media_album_id":"0","restriction_reason":"","content":{"@type":"messageText","text":{"@type":"formattedText","text":"/start","entities":[{"@type":"textEntity","offset":0,"length":6,"type":{"@type":"textEntityTypeBotCommand"}}]}}}}

Can I do a reading using the full path

function ReadMsg(JSONStr : String) : String;
var
    JSON: IDocDict;
begin
    result := '';
    if IsValidJson(JSONStr) then
    begin
      JSON := DocDict(JSONStr); 
      result := JSON.S['message.content.text.text']; // Can I do that using mormot?
    end;    
end;

And for the Exists method

if JSON.Exists('message.content.text') then

Thanks.

#10 Re: mORMot 2 » Windows API Multiple defined symbols » 2023-12-08 19:24:16

I found a bug in the static unit and sent a fix in the same pull request.

#11 Re: mORMot 2 » Windows API Multiple defined symbols » 2023-12-06 10:16:39

I end up using NOLIBCSTATIC

I created a pull request because it needed some extra fixes so the code could compile

https://github.com/synopse/mORMot2/pull/231

#12 mORMot 2 » Windows API Multiple defined symbols » 2023-12-04 09:52:56

Coldzer0
Replies: 4

Hello

I was working on my project ImGui-Pascal, and It requires linking with some Windows libraries, one of them is msvcrt
And I was recreating one of my projects to use it as a UI and mORMot2 as the backend.

The problem is these APIs are already defined in src\lib\mormot.lib.static.pas

Error: Multiple defined symbol "__strtod"
Error: Multiple defined symbol "__imp__localtime64"

__strtod is only used by src\lib\mormot.lib.quickjs.pas, which can be handled with an IFDEF if QuickJS is used.

But the real problem is imp_localtime64 := @localtime64; which I assume is used for some other library (not sure).

So, what do you think about this case?

#13 Re: mORMot 2 » High CPU usage when frames are received » 2023-09-30 20:36:26

flydev wrote:

Good to hear that.

It was an instance of a bidir TWebSocketAsyncServerRest. I will recompile the project next week and upload all the test clients while keeping the server running in the debugger.


Then yes your sever was definitely affected by the bug, and recompiling it with the latest update will solve it.

#14 Re: mORMot 2 » High CPU usage when frames are received » 2023-09-30 19:49:33

flydev wrote:

@ColdZer0, is everything still ok?

This is what happens after 14 hours, plus the console is not updating anymore.

I am asking because i ran into the same issue in the end of july while testing the new async server, and I want to give another try. I had no junk network traffic as the network is filtered only on known static ips but almost all clients are connecting through 4G routers with sometime high latency and/or random disconnections. The console was "stuck" after ~6h with around 170 clients sending 1 or more requests per secs.

Thanks you both for the debugging and fixes smile


For me, everything still works very fine ( the server has been running for 5 days 16 hours - from the last update I did to the server code not from the last WebSocket fix )
So everything works very well.

What kind of Async server you are using? WebSocket ? or just HTTPAsync Server?

Because the problem with the WebSocket one has nothing to do with the HTTPAsync Server.

#15 Re: mORMot 2 » High CPU usage when frames are received » 2023-09-14 03:37:39

Everything seems to be stable after yesterday's fixes.

Thanks for your work and the great framework.

#16 Re: mORMot 2 » High CPU usage when frames are received » 2023-09-13 11:54:25

I have a question regarding exceptions at functions like

function TWebProcessInFrame.GetHeader: boolean;

Do we need exceptions here?

Like

EWebSockets.CreateUtf8('%.GetFrame: truncated mask', [process]);

Can't we return false on errors because exceptions like these hang the Debugger while testing?

#17 Re: mORMot 2 » High CPU usage when frames are received » 2023-09-13 06:49:03

The GPF with the hsoBan40xIP fix has worked fine till now.
I've been testing it for 30 mins since you pushed the commit. I'll keep testing.

And for the lock, I just pulled the changes and will test it and see if everything works fine.

Thanks for your hard work and updates.

#18 Re: mORMot 2 » High CPU usage when frames are received » 2023-09-13 02:05:49

So after running for a while, the high CPU thing happens, and here's some call Stackframe for a couple of threads, and all of the high CPU ones stuck either at

Procedure TRWLock.WriteLock;
or
procedure TRWLock.ReadOnlyLockSpin;

and all of them come from
TAsyncConnections.ConnectionFind
TAsyncConnections.ConnectionFindAndLock

Here's screenshots

Stack_1
and
Stack_2


I'll try to check with fewer threads to see if I can catch what is happening.

#19 Re: mORMot 2 » High CPU usage when frames are received » 2023-09-12 20:53:01

After doing some testing with the debugger.

Here's the first error "Access Violation" at the "IsBanned" function.
It only happens when I enable "hsoBan40xIP"

IsBanned

#20 Re: mORMot 2 » High CPU usage when frames are received » 2023-09-12 16:21:36

The last test I'm doing right now has the hsoBan40xIP and hsoLogVerbose options in the server

And I'm doing a LOG_VERBOSE for the TSynLog.Family.Level

Right now the server has been running for 13+ hours and the server status seems stable

Server_Status


If the server reacts the same as before I'll send you the full server logs in a private message.

#21 Re: mORMot 2 » High CPU usage when frames are received » 2023-09-06 17:27:30

So I noticed yesterday that I was not enabling the Windows firewall
Then After enabling it and I already have a list of IPs to block they were doing DDOS attacks on the server

the server still running and I blocked more IPs

Here's an example The number of WebSocket connections that I counted was way less than the console shows
Then I checked the list of connected IPs and found 1 IP connected to the server 200+ times, I blocked the IP and a couple of other malicious IPs

The number decreased after killing the multiple connections
DDOS

And I noticed in the screenshots I sent before that there was a spike in network data up to 2GB in traffic which is odd.

I'll keep the server running with the firewall and list of blocked IPs and see if it affects the result of the test.
Then I'll do another test with verbose enabled.


Now I have a question regards the TCP connections in the "TWebSocketAsyncServer"
Can I intercept the connection at the beginning even before the WebSocket upgrade?

I want to make some internal checks to test for any multi-connected IPs or other malicious IPs.



Could you try to compile the server with FPC and see what happens on Linux?

I can't with this server because it is built for Windows with a GUI controller for status and some other options.

But I was already working on a new rewrite for the project to be compatible for Linux and with REST server without the GUI stuff and only APIs.

#22 Re: mORMot 2 » High CPU usage when frames are received » 2023-09-05 01:09:17

Right Now I added the ConsoleWrite you mentioned

The server has been running for "12 hours +" and waiting to see what will happen

BTW I'm using "TWebSocketAsyncServer" and all the connections sending data all the time like ping and other small text chat data

For now, this is the network status.
network status


And for the performance for now it uses only 88MB of RAM and less than 1% of CPU which is amazing.
performance

I'll try to enable full logging after this test and share it with you.


This is what happens after 14 hours, plus the console is not updating anymore.
bug

#23 Re: mORMot 2 » High CPU usage when frames are received » 2023-09-02 00:32:09

Hello @ab

I still got a high CPU on the Async web socket server with 1500+ concurrent connections for 26+ hours
I was checking the server status and I found out that the server CPU was 90+%
When I checked the threads it was all from mORMot Async server threads
Each thread was using around 5..6% and on the stack, every single one of them was doing SwitchToThread

I'll try to use something like ProDelphi64 or if you have any recommendations on how to trace this down I'll be happy to hear from you.
or try to run it under the IDE debugger for as long as I can.

I'm using mORMot2 v2.1.5824, Delphi 11.3 and the server is running on a Windows

#24 Re: mORMot 2 » THttpAsyncConnections pending overflow with 2.0.stable » 2023-06-17 17:55:51

I got the same error on logs after keeping the server running for a couple of hours.

I'll try to enable trace logging and see if I can get it to have the same issue again.

#25 mORMot 2 » Uploading Files to TWebSocketAsyncServer » 2023-02-28 14:36:20

Coldzer0
Replies: 1

Hello guys,

I was looking at the source code of Mormot2 to see if there's any way I can upload a file to TWebSocketAsyncServer, which is based on THttpAsyncServer.

But with no luck.

So is there any way I can upload files to the Mormot2 HTTP server, and if mormot 2 HTTP servers support multipart file upload?

I'm looking to upload files of 1GB to 5GB in size.

Regards.

#26 Re: mORMot 1 » Help - mORMot2 Raw TCP Async Client & Server » 2021-10-29 18:33:41

Hello ab,

Please check my last comment https://github.com/synopse/mORMot2/issu … -954962300

I add a git patch propose some changes to let the TAsyncClient work as expected.

#27 Re: mORMot 1 » Help - mORMot2 Raw TCP Async Client & Server » 2021-10-27 16:13:02

Hello ab,

I Notice today that there's an update on the TAsyncServer But not the TAsyncClient

https://github.com/synopse/mORMot2/comm … 2538a2f0c4


Is there any update coming for the TAsyncClient OnRead Problem ?


Thanks.

#28 Re: mORMot 1 » Help - mORMot2 Raw TCP Async Client & Server » 2021-10-26 12:05:35

Thanks for reply.

Yes I'll use Linux But I was testing windows for other project I've in mind.

And About the TAsyncClient there's no release for the "atpReadPoll" that's why I called ThreadPollingWakeup.

I think TAsyncClient needs to be updated.


One thing I notice is when I use TAsyncConnections with 1 thread count the reading is working fine once the ThreadPoolCount is bigger than 1 there's no OnRead call.

#29 Re: mORMot 1 » Help - mORMot2 Raw TCP Async Client & Server » 2021-10-26 10:37:50

Hello ab

So basically I took a good look at the TAsyncServer and the TAsyncClient and the main difference is the Server has a mechanism to notify the ReadPoll to handle new subscriptions, But the Client didn't have.

So What I did is adding the following code in the "ConnectionCreate" CallBack.


// assign the new connection to the internal reading poll.
If Clients.Start(aconnection) Then
Begin
    // release atpReadPoll lock to handle new subscription ASAP
    ThreadPollingWakeup(fClients.PollRead.PollForPendingEvents(0));

    // Send 2MB As Test - we should receive it
    WriteString(aConnection, DupeString('A', 1024*1024*2));
    Result := True;
End

Here's the new Client Code
https://gist.github.com/Coldzer0/226e0d … 4485594e28

It Works well for Reading and Writing (Still didn't test it fully).

I didn't add my code in a PR because I didn't know how it suppose to be handled in the test ( I'm new to mORMot internals ).

Please Check it and let me know if it's Ok to use it like this or if there's a better way.

Thanks.

#30 Re: mORMot 1 » Help - mORMot2 Raw TCP Async Client & Server » 2021-10-25 19:40:32

Thanks ab for reply.

First of all thanks so much for the amazing work in mORMot2.


Do you have any number to share?

Sure

The Sever RDP
The Machine I uses for Server is "CPU= 5 x Intel(R)Xeon(R)CPUE5-24200@1.90GHz(x64) - RAM= 8GB"

This is a x64 Debug Build with Delphi Memory Manager.

Built with Delphi 11 Alexandria : Debug Mode
Memory Usage: About "50MB" for "11,166" concurrent Connections With 16 Async Threads (TAsyncServer).
CPU Usage   : Between 17% & 18% never higher.

Even when it reach the 13,000+ It was still very small memory usage about "52-54 MB"


Here's a screenshot from when I was testing.
Screenshot from server while testing


The Client Side: (I didn't use mORMot2 I used a tool called EchoServerTest to do the testing)
The Stress testing Machine is "CPU=16 x Intel(R)Core(TM)i9-9900KCPU@3.60GHz(x64) RAM= 32GB"

I was aiming for 40000 concurrent connections But windows has limits, I think there's some registry options I can edit to extend the numbers of connections.

Anyway I'll do the test again but with Linux x64 (Will test Release Build Later with mORMot2 Memory Manager).


Could you make a pull request and include your code to the regression tests

Yes no problem I will try my best.


so you can't be notified that the server actually received the data. But it is also the case for plain TCP IIRC.

In normal blocking mode you got the sent length so you can make sure how much of your buffer sent to the server.

But I'll implement custom acknowledgment send by the server to be confirmed by the client as you advised.


I've a question about the internal buffer of the sockets, How can I read a specific size of data keeping in mind that the read and write in Async.
What I mean is how can I make sure that what I receive is the full packet if the size if like 1MB or Bigger keeping in mind that the maximum buffer described in code is "8KB".

#31 mORMot 1 » Help - mORMot2 Raw TCP Async Client & Server » 2021-10-25 12:14:47

Coldzer0
Replies: 8

Hello guys

I was trying to create an Async raw TCP client & server.


I Created A Server and it works very well It can handle thousands of concurrent connections.

I tested it with a tool for stress testing and I got (about 13,000+ (limited by the client machine) connections On Virtual RDP Server : CPU=5xIntel(R)Xeon(R)CPUE5-24200@1.90GHz(x64) 5 Cores - RAM=8GB ).


Echo Server Code:
https://gist.github.com/Coldzer0/d00c04 … 72765506c5


But when I tried to Create Client with the Code of use of mORMot2 TAsyncClient Everything works except for the OnRead, when I try to send any data to the client the OnRead never called.

Client Code:
https://gist.github.com/Coldzer0/8c98a0 … 89791f55e4


And I've another question about Async send, How can I make sure that the server received the sent data or not ?

And please let me know If I'm doing anything wrong, And If there's any good demo of showing how to deal with RAW TCP Client & Server with mORMot2.

#32 SyNode » QuickJS FPC & Delphi Bindings » 2019-08-25 00:49:57

Coldzer0
Replies: 3

Hello all,

This is a FPC & Delphi bindings for QuickJS @ https://bellard.org/quickjs

I hope this will help someone ^_^

https://github.com/Coldzer0/QuickJS-Pascal

#33 Re: SyNode » SpiderMonkey Lite Build » 2018-09-01 11:05:40

mpv wrote:

This is known problem. Most of the size take libicu with all known languages inside. So, without-intl-api and without-system-icu will strip this library and decrease size, but you lost Internationalization API. For example we use it widely. The possible way to keep Intl and decrease size is to remove unneeded resources from libicu

Also disable-ion is IMHO not decrease library size but you lost JIT - very, very big performance degradation

i'll try to enable ion again

in my project i don't need "icu" so i think it's ok to remove

and is there any place i can find more info about

--disable-ion -> i know now it's for JIT

but what about
--disable-jm
--disable-tm
--disable-methodjit
--disable-monoic
--disable-polyic
etc ...

i can't find any resource that give details about these options

#34 Re: SyNode » SpiderMonkey Lite Build » 2018-08-31 10:13:15

this's the smallest size i get so far 6.8MB

with this config

../configure --enable-release --disable-ion --enable-ctypes --disable-jemalloc --enable-nspr-build --disable-debug --disable-debug-symbols --enable-optimize=-O3 --without-intl-api --enable-strip --disable-ion --without-system-icu

#35 SyNode » SpiderMonkey Lite Build » 2018-08-31 09:05:39

Coldzer0
Replies: 5

Hello all

i'm really glad that i found this project

i'm working on a Project Called "Cmulator"

Cmulator is ( x86 - x64 ) Windows PE Sandbox Emulator & Disassembler
Based on Unicorn & Capstone & Besen Engine .

the main core functions built with FreePascal and API hooks with JS Engine "Besen"
but Besen Engine is old and slow , that why i’m interested in your product , as there’s no small and native Pascal JS Engine out there .


a small preview of what JS will be used for in my project

this’s a small Example to Hook "GetModuleFileNameA & GetModuleFileNameW" with JS

var GetModuleFileName = new ApiHook();
/*
DWORD WINAPI GetModuleFileName(
  _In_opt_ HMODULE hModule,
  _Out_    LPTSTR  lpFilename,
  _In_     DWORD   nSize
);
*/
GetModuleFileName.OnCallBack = function (Emu, API, ret) {

    Emu.pop(); // ret
    
    var hModule    = Emu.isx64 ? Emu.ReadReg(REG_RCX) : Emu.pop();
    var lpFilename = Emu.isx64 ? Emu.ReadReg(REG_RDX) : Emu.pop();
    var nSize      = Emu.isx64 ? Emu.ReadReg(REG_R8D) : Emu.pop();

    var mName = Emu.GetModuleName(hModule);
    var Path = 'C:\\folder\\' + mName;


    var len = API.isWapi ? Emu.WriteStringW(lpFilename,Path) : Emu.WriteStringA(lpFilename,Path);
    
    print("GetModuleFileName{0}(0x{1}, 0x{2}, 0x{3}) = '{4}'".format(
        API.IsWapi ? 'W' : 'A',
        hModule.toString(16),
        lpFilename.toString(16),
        nSize.toString(16),
        Path
    ));

    // MS Docs : the return value is the length of the string
    Emu.SetReg(Emu.isx64 ? REG_RAX : REG_EAX, len); 
    Emu.SetReg(Emu.isx64 ? REG_RIP : REG_EIP, ret);
    return true; // true if you handle it false if you want Emu to handle it and set PC .
};

GetModuleFileName.install('kernel32.dll', 'GetModuleFileNameA');
GetModuleFileName.install('kernel32.dll', 'GetModuleFileNameW');

Emu is JS Object have all needed Native functions like "ReadReg" to read Register from the CPU Emulator , "WriteStringA" & "GetModuleName" and a lot more
the main thing here is that i can call JS function from my Native code and vice versa .

the tool Depends on JS as Scripting lang for Hooks and dealing with the CPU Emulator for easy of use and speed .


3 days ago i downloaded and use your project on Mac OS Mojave and it works fine with the linux Patch for exports
but SM is very big 22MB for "libmozjs-52.dylib"

so i'm searching for a way to Build it without the need of Debugger and anything that i can get rid of , even if i'll remove JIT
but i need it small as i can get .

Thanks

Board footer

Powered by FluxBB