Permalink
Browse files

update windows

  • Loading branch information...
gafferongames committed Jul 15, 2017
1 parent e430b16 commit 7c5d926d6c8b6702511960ff1f8cda5eb3710930
Showing with 146 additions and 93 deletions.
  1. +7 −1 test.cpp
  2. BIN windows/sodium.lib
  3. +41 −4 yojimbo.cpp
  4. +98 −88 yojimbo.h
View
@@ -129,6 +129,8 @@ void test_queue()
check( queue.GetSize() == QueueSize );
}
#if YOJIMBO_HAS_MBEDTLS
void test_base64()
{
const int BufferSize = 256;
@@ -165,6 +167,8 @@ void test_base64()
check( memcmp( key, decoded_key, KeyBytes ) == 0 );
}
#endif // #if YOJIMBO_HAS_MBEDTLS
void test_bitpacker()
{
const int BufferSize = 256;
@@ -2207,7 +2211,9 @@ int main()
RUN_TEST( test_endian );
RUN_TEST( test_queue );
RUN_TEST( test_base64 );
#if YOJIMBO_HAS_MBEDTLS
RUN_TEST( test_base64 );
#endif // #if YOJIMBO_HAS_MBEDTLS
RUN_TEST( test_bitpacker );
RUN_TEST( test_stream );
RUN_TEST( test_address );
View
Binary file not shown.
View
@@ -66,7 +66,10 @@ void ShutdownYojimbo()
#include <stdio.h>
#include <string.h>
#include <stdio.h>
#if YOJIMBO_HAS_MBEDTLS
#include <mbedtls/base64.h>
#endif // #if YOJIMBO_HAS_MBEDTLS
extern "C" void netcode_random_bytes( uint8_t*, int );
@@ -140,6 +143,8 @@ namespace yojimbo
printf( " (%d bytes)\n", data_bytes );
}
#if YOJIMBO_HAS_MBEDTLS
int base64_encode_string( const char * input, char * output, int output_size )
{
yojimbo_assert( input );
@@ -199,6 +204,8 @@ namespace yojimbo
return ( result == 0 ) ? (int) output_length : -1;
}
#endif // #if YOJIMBO_HAS_MBEDTLS
}
// ---------------------------------------------------------------------------------
@@ -865,6 +872,7 @@ double yojimbo_time()
// ---------------------------------------------------------------------------------
#if YOJIMBO_HAS_MBEDTLS
#include <mbedtls/config.h>
#include <mbedtls/platform.h>
#include <mbedtls/net.h>
@@ -874,6 +882,7 @@ double yojimbo_time()
#include <mbedtls/ctr_drbg.h>
#include <mbedtls/error.h>
#include <mbedtls/certs.h>
#endif // #if YOJIMBO_HAS_MBEDTLS
#include <inttypes.h>
#include <string.h>
#include "netcode.h"
@@ -885,38 +894,48 @@ namespace yojimbo
{
struct MatcherInternal
{
#if YOJIMBO_HAS_MBEDTLS
mbedtls_net_context server_fd;
mbedtls_entropy_context entropy;
mbedtls_ctr_drbg_context ctr_drbg;
mbedtls_ssl_context ssl;
mbedtls_ssl_config conf;
mbedtls_x509_crt cacert;
#endif // #if YOJIMBO_HAS_MBEDTLS
};
Matcher::Matcher( Allocator & allocator )
{
#if YOJIMBO_HAS_MBEDTLS
yojimbo_assert( ConnectTokenBytes == NETCODE_CONNECT_TOKEN_BYTES );
m_allocator = &allocator;
m_initialized = false;
m_matchStatus = MATCH_IDLE;
m_internal = YOJIMBO_NEW( allocator, MatcherInternal );
memset( m_connectToken, 0, sizeof( m_connectToken ) );
#else // #if YOJIMBO_HAS_MBEDTLS
(void) allocator;
#endif // #if YOJIMBO_HAS_MBEDTLS
}
Matcher::~Matcher()
{
#if YOJIMBO_HAS_MBEDTLS
mbedtls_net_free( &m_internal->server_fd );
mbedtls_x509_crt_free( &m_internal->cacert );
mbedtls_ssl_free( &m_internal->ssl );
mbedtls_ssl_config_free( &m_internal->conf );
mbedtls_ctr_drbg_free( &m_internal->ctr_drbg );
mbedtls_entropy_free( &m_internal->entropy );
YOJIMBO_DELETE( *m_allocator, MatcherInternal, m_internal );
#endif // #if YOJIMBO_HAS_MBEDTLS
}
bool Matcher::Initialize()
{
const char * pers = "yojimbo_client";
#if YOJIMBO_HAS_MBEDTLS
const char * pers = "yojimbo_client";
mbedtls_net_init( &m_internal->server_fd );
mbedtls_ssl_init( &m_internal->ssl );
@@ -939,16 +958,20 @@ namespace yojimbo
return false;
}
m_initialized = true;
memset( m_connectToken, 0, sizeof( m_connectToken ) );
#endif // // #if YOJIMBO_HAS_MBEDTLS
m_initialized = true;
return true;
}
void Matcher::RequestMatch( uint64_t protocolId, uint64_t clientId, bool verifyCertificate )
{
yojimbo_assert( m_initialized );
#if YOJIMBO_HAS_MBEDTLS
yojimbo_assert( m_initialized );
const char * data;
char request[1024];
@@ -1072,6 +1095,15 @@ namespace yojimbo
cleanup:
mbedtls_ssl_close_notify( &m_internal->ssl );
#else // #if YOJIMBO_HAS_MBEDTLS
(void) protocolId;
(void) clientId;
(void) verifyCertificate;
m_matchStatus = MATCH_FAILED;
#endif // #if YOJIMBO_HAS_MBEDTLS
}
MatchStatus Matcher::GetMatchStatus()
@@ -1081,12 +1113,17 @@ namespace yojimbo
void Matcher::GetConnectToken( uint8_t * connectToken )
{
#if YOJIMBO_HAS_MBEDTLS
yojimbo_assert( connectToken );
yojimbo_assert( m_matchStatus == MATCH_READY );
if ( m_matchStatus == MATCH_READY )
{
memcpy( connectToken, m_connectToken, ConnectTokenBytes );
}
#else // #if YOJIMBO_HAS_MBEDTLS
(void) connectToken;
yojimbo_assert( false );
#endif // #if YOJIMBO_HAS_MBEDTLS
}
}
Oops, something went wrong.

0 comments on commit 7c5d926

Please sign in to comment.