@@ -254,6 +254,24 @@ run_server (EndpointConfig_t * config, slice_ref_uint8_t alpn_slice, bool json_o
254254 return 0 ;
255255}
256256
257+ typedef struct ConnectionStatus {
258+ EndpointResult_t res ;
259+ ConnectionType_t conn_type ;
260+ } ConnectionStatus ;
261+
262+ void
263+ callback (
264+ void const * ctx ,
265+ EndpointResult_t res ,
266+ ConnectionType_t conn_type
267+ )
268+ {
269+ ConnectionStatus * cs ;
270+ cs = (ConnectionStatus * )ctx ;
271+ cs -> res = res ;
272+ cs -> conn_type = conn_type ;
273+ }
274+
257275int
258276run_client (
259277 EndpointConfig_t * config ,
@@ -315,6 +333,10 @@ run_client (
315333 return -1 ;
316334 }
317335
336+ ConnectionStatus * conn_status ;
337+ conn_status = malloc (sizeof (ConnectionStatus ));
338+ endpoint_conn_type_cb (ep , (const void * )conn_status , & node_addr .node_id , callback );
339+
318340 SendStream_t * send_stream = send_stream_default ();
319341 ret = connection_open_uni (& conn , & send_stream );
320342 if (ret != 0 ) {
@@ -389,6 +411,29 @@ run_client (
389411 printf ("received: '%s'\n" , recv_str );
390412
391413 fflush (stdout );
414+ // check that we were able to use the conn_type callback
415+ if (conn_status -> res != ENDPOINT_RESULT_OK ) {
416+ fprintf (stderr , "callback failed to send a connection type\n" );
417+ return -1 ;
418+ } else {
419+ switch (conn_status -> conn_type ) {
420+ case CONNECTION_TYPE_DIRECT :
421+ printf ("had a direct connection\n" );
422+ break ;
423+ case CONNECTION_TYPE_RELAY :
424+ printf ("had a relay connection\n" );
425+ break ;
426+ case CONNECTION_TYPE_MIXED :
427+ printf ("had a mixed connection\n" );
428+ break ;
429+ case CONNECTION_TYPE_NONE :
430+ fprintf (stderr , "callback reported no connection\n" );
431+ return -1 ;
432+ default :
433+ fprintf (stderr , "unknown connection type reported: %i\n" , conn_status -> conn_type );
434+ return -1 ;
435+ }
436+ }
392437
393438 // finish
394439 ret = send_stream_finish (send_stream );
@@ -413,6 +458,7 @@ run_client (
413458 // cleanup
414459 free (recv_str );
415460 free (recv_buffer );
461+ free (conn_status );
416462 recv_stream_free (recv_stream );
417463 return 0 ;
418464}
0 commit comments