Permalink
Browse files

Add user_data parameter to netcode_generate_connect_token

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 c4b0198b8ddb387f09e73d79ff3cfe17e8d6d9f3
Showing with 113 additions and 30 deletions.
  1. +4 −1 client.c
  2. +4 −1 client_server.c
  3. +95 −26 netcode.c
  4. +2 −0 netcode.h
  5. +4 −1 profile.c
  6. +4 −1 soak.c
@@ -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;
@@ -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;
Oops, something went wrong.

0 comments on commit c4b0198

Please sign in to comment.