You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I understand that libssh2_session_handshake does banner-exchange + key-exchange + service-request-exchange.
I want to time the duration that the client spends within each of these exchanges.
From my understanding, there's no straightforward way to do it and I'll probably have to modify the library itself.
To do so I'll have to declare two callback registration methods in the libssh2.h file so that my client can use this to register its callbacks:
create a event_handlers.c file, add it in Makefile.inc and define the above methods in it:
// file: event_handlers.c#include"libssh2_priv.h"// this includes "libssh2.h" so those method declarations should also be available here.typedefstruct
{
handshake_event_handler_tcallable;
void*context;
} callback_t;
typedefstruct
{
callback_tbanner_received;
callback_tkey_exchanged;
} handshake_event_handlers;
statichandshake_event_handlershandlers= {{NULL}, {NULL}};
voidregister_banner_received_handler(handshake_event_handler_tcallback, void*context)
{
if (NULL!=callback)
{
handlers.banner_received.callable=callback;
handlers.banner_received.context=context;
}
}
voidregister_key_exchanged_handler(handshake_event_handler_tcallback, void*context)
{
if (NULL!=callback)
{
handlers.key_exchanged.callable=callback;
handlers.key_exchanged.context=context;
}
}
void_event_session_banner_received(LIBSSH2_SESSION*session, intevent_status)
{
if (NULL!=handlers.banner_received.callable)
{
handlers.banner_received.callable(session, event_status, handlers.banner_received.context);
}
}
void_event_key_exchanged(LIBSSH2_SESSION*session, intevent_status)
{
if (NULL!=handlers.key_exchanged.callable)
{
handlers.key_exchanged.callable(session, event_status, handlers.key_exchanged.context);
}
}
and then register some methods via these apis in my non-library code. which will get invoked when these events occur.
My client(the non-library code) is single threaded and uses non-blocking mode.
In that case, I should just add the event handler invocation in session.c at:
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
Uh oh!
There was an error while loading. Please reload this page.
-
I understand that
libssh2_session_handshake
does banner-exchange + key-exchange + service-request-exchange.I want to time the duration that the client spends within each of these exchanges.
From my understanding, there's no straightforward way to do it and I'll probably have to modify the library itself.
To do so I'll have to declare two callback registration methods in the
libssh2.h
file so that my client can use this to register its callbacks:then, in
libssh2_priv.h
I add the event handler declarations:create a
event_handlers.c
file, add it inMakefile.inc
and define the above methods in it:and then register some methods via these apis in my non-library code. which will get invoked when these events occur.
My client(the non-library code) is single threaded and uses non-blocking mode.
In that case, I should just add the event handler invocation in
session.c
at:Is my approach correct? or is there a neater way to do it?
I mean, if this is something useful, I can create a PR for this as well. Maybe add more events.
Beta Was this translation helpful? Give feedback.
All reactions