-
Notifications
You must be signed in to change notification settings - Fork 16
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add connect/disconnect, reduce copy, simplify headers #23
Add connect/disconnect, reduce copy, simplify headers #23
Conversation
wolfhsm/wh_comm.h
Outdated
@@ -32,7 +32,8 @@ | |||
enum { | |||
WH_COMM_HEADER_LEN = 8, /* whCommHeader */ | |||
WH_COMM_DATA_LEN = 1280, | |||
WH_COMM_MTU = (WH_COMM_HEADER_LEN + WH_COMM_DATA_LEN) | |||
WH_COMM_MTU = (WH_COMM_HEADER_LEN + WH_COMM_DATA_LEN), | |||
WH_COMM_MTU_8 = (WH_COMM_MTU + 7) / 8, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we should call it WH_COMM_MTU_BITS
, wolfSSL defines things as bits when referring to sizes in bits: #define SP_INT_BITS 4096
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hah! This is actually the rounded-up number of 8-byte uint64_t's needed to hold an MTU packet. How about I change this to WH_COMM_MTU_64?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oooh yeah that is a little confusing, I had to double take this a few times to be sure, as +7/8 looks like rounding up bits to the next byte on first glance, but we are dealing with bytes and 64-bit words here.
Maybe one of the following, or a permutation thereof?
WH_COMM_MTU_ALIGN64_COUNT
WH_COMM_MTU_WORD64_COUNT
WH_COMM_MTU_ALIGN64_WORD_COUNT
I think explicitly calling out sizes and purpose is a good thing.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ah gotcha yeah thats much less confusing, I'd also add a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
went with WH_COMM_MTU_U64_COUNT with a comment. Fixed in next push.
wolfhsm/wh_comm.h
Outdated
@@ -32,7 +32,8 @@ | |||
enum { | |||
WH_COMM_HEADER_LEN = 8, /* whCommHeader */ | |||
WH_COMM_DATA_LEN = 1280, | |||
WH_COMM_MTU = (WH_COMM_HEADER_LEN + WH_COMM_DATA_LEN) | |||
WH_COMM_MTU = (WH_COMM_HEADER_LEN + WH_COMM_DATA_LEN), | |||
WH_COMM_MTU_8 = (WH_COMM_MTU + 7) / 8, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oooh yeah that is a little confusing, I had to double take this a few times to be sure, as +7/8 looks like rounding up bits to the next byte on first glance, but we are dealing with bytes and 64-bit words here.
Maybe one of the following, or a permutation thereof?
WH_COMM_MTU_ALIGN64_COUNT
WH_COMM_MTU_WORD64_COUNT
WH_COMM_MTU_ALIGN64_WORD_COUNT
I think explicitly calling out sizes and purpose is a good thing.
wolfhsm/wh_comm.h
Outdated
typedef int (*whCommSetConnectedCb)(void* context, int connected); | ||
|
||
/* Status of whether a client is connected or not */ | ||
enum { | ||
WH_COMM_DISCONNECTED = 0, | ||
WH_COMM_CONNECTED = 1, | ||
}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thoughts on typing enums, especially when an argument is assumed to be one of a few values? I think it adds clarity as to what should be passed in, as opposed to relying on comments or a hopefully obvious enum name. I'm pro anything that lets code be more self-documenting. Something like:
/* Status of whether a client is connected or not */
typedef enum {
WH_COMM_DISCONNECTED = 0,
WH_COMM_CONNECTED = 1,
} whCommConnectState;
typedef int (*whCommSetConnectedCb)(void* context, whCommConnectState connected);
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Concur. I was trying to keep the callbacks generic and untyped, but there's no reason not to force the type to an enum. Fixed in next push.
test/wh_test_crypto.c
Outdated
for ( wh_Server_SetConnected(server, am_connected); | ||
am_connected == WH_COMM_CONNECTED; | ||
wh_Server_GetConnected(server, &am_connected) ){ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is fun
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Prolly too fancy. I'll switch it to a while structure. Fixed in next push
test/wh_test_clientserver.c
Outdated
@@ -1235,6 +1236,7 @@ int whTest_ClientCfg(whClientConfig* clientCfg) | |||
WH_TEST_ASSERT_RETURN(server_rc == WH_ERROR_OK); | |||
WH_TEST_ASSERT_RETURN(avail_objects == NF_OBJECT_COUNT); | |||
|
|||
wh_Client_CommClose(client); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
wh_Client_CommClose(client); | |
WH_TEST_RETURN_ON_FAIL(wh_Client_CommClose(client)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed in next push.
Added refactor to backlog. Improved names
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good
A number of changes:
Nearly all of these changes are necessary to make the Bernini and Aurix ports compile clean and align packet buffers correctly as well as use optimized memcpy.