Skip to content

Commit

Permalink
Add user_data parameter to netcode_generate_connect_token
Browse files Browse the repository at this point in the history
uint8_t * user_data, taken directly from netcode_generate_connect_token_private, is now a part of netcode_generate_connect_token so that creation of user data is exposed to the user. The constant NETCODE_USER_DATA_BYTES is also exposed in netcode.h for the purpose of users knowing how large the user_data array should be. To replace the previous code which was randomly generating 256 bytes for the purpose of connecting, the random user_data generation code has been copy pasted into all the code that previously used netcode_generate_connect_token without the user_data parameter. All tests are passing.
  • Loading branch information
stellarLuminant committed Feb 4, 2019
1 parent 5f166b6 commit c4b0198
Show file tree
Hide file tree
Showing 6 changed files with 113 additions and 30 deletions.
5 changes: 4 additions & 1 deletion client.c
Expand Up @@ -81,9 +81,12 @@ int main( int argc, char ** argv )
netcode_random_bytes( (uint8_t*) &client_id, 8 );
printf( "client id is %.16" PRIx64 "\n", client_id );

uint8_t user_data[NETCODE_USER_DATA_BYTES];
netcode_random_bytes(user_data, NETCODE_USER_DATA_BYTES);

uint8_t connect_token[NETCODE_CONNECT_TOKEN_BYTES];

if ( netcode_generate_connect_token( 1, &server_address, &server_address, CONNECT_TOKEN_EXPIRY, CONNECT_TOKEN_TIMEOUT, client_id, PROTOCOL_ID, private_key, connect_token ) != NETCODE_OK )
if ( netcode_generate_connect_token( 1, &server_address, &server_address, CONNECT_TOKEN_EXPIRY, CONNECT_TOKEN_TIMEOUT, client_id, PROTOCOL_ID, private_key, user_data, connect_token ) != NETCODE_OK )
{
printf( "error: failed to generate connect token\n" );
return 1;
Expand Down
5 changes: 4 additions & 1 deletion client_server.c
Expand Up @@ -97,7 +97,10 @@ int main( int argc, char ** argv )
netcode_random_bytes( (uint8_t*) &client_id, 8 );
printf( "client id is %.16" PRIx64 "\n", client_id );

if ( netcode_generate_connect_token( 1, (NETCODE_CONST char**) &server_address, (NETCODE_CONST char**) &server_address, CONNECT_TOKEN_EXPIRY, CONNECT_TOKEN_TIMEOUT, client_id, PROTOCOL_ID, private_key, connect_token ) != NETCODE_OK )
uint8_t user_data[NETCODE_USER_DATA_BYTES];
netcode_random_bytes(user_data, NETCODE_USER_DATA_BYTES);

if ( netcode_generate_connect_token( 1, (NETCODE_CONST char**) &server_address, (NETCODE_CONST char**) &server_address, CONNECT_TOKEN_EXPIRY, CONNECT_TOKEN_TIMEOUT, client_id, PROTOCOL_ID, private_key, user_data, connect_token ) != NETCODE_OK )
{
printf( "error: failed to generate connect token\n" );
return 1;
Expand Down

0 comments on commit c4b0198

Please sign in to comment.