Discovery mode entry point for unified binary.
Options are already parsed by the main dispatcher before this function is called, so they are available via GET_OPTION().
Discovery mode entry point for unified binary.
Handles session discovery, host negotiation, and media flow.
338 {
339 log_debug("discovery_main() starting");
340
341
342
343
344
345
346 const char *session_string = GET_OPTION(session_string);
347 bool is_initiator = (session_string == NULL || session_string[0] == '\0');
348
349 int port_int = GET_OPTION(port);
350
351 log_debug("Discovery: is_initiator=%d, port=%d", is_initiator, port_int);
352
353
356 .acds_port = (uint16_t)GET_OPTION(discovery_port),
357 .session_string = is_initiator ? NULL : session_string,
358 .local_port = (uint16_t)port_int,
359 .on_state_change = on_discovery_state_change,
360 .on_session_ready = on_session_ready,
361 .on_error = on_discovery_error,
362 .callback_user_data = NULL,
363 .should_exit_callback = discovery_capture_should_exit_adapter,
364 .exit_callback_data = NULL,
365 };
366
367
369 if (!g_discovery) {
370 log_fatal("Failed to create discovery session");
371 return ERROR_MEMORY;
372 }
373
374
375 log_debug("Discovery: starting discovery session");
377 if (result != ASCIICHAT_OK) {
378 log_fatal("Failed to start discovery session: %d", result);
380 g_discovery = NULL;
381 return result;
382 }
383
384
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405 session_client_like_config_t config = {
406 .run_fn = discovery_run,
407 .run_user_data = NULL,
408 .tcp_client = NULL,
409 .websocket_client = NULL,
410 .discovery = (void *)g_discovery,
411 .custom_should_exit = NULL,
412 .exit_user_data = NULL,
413 .keyboard_handler = discovery_keyboard_handler,
414 .max_reconnect_attempts = 0,
415 .should_reconnect_callback = NULL,
416 .reconnect_user_data = NULL,
417 .reconnect_delay_ms = 0,
418 .print_newline_on_tty_exit = false,
419 };
420
421 log_debug("Discovery: calling session_client_like_run()");
423 log_debug("Discovery: session_client_like_run() returned %d", session_result);
424
425
426 log_debug("Discovery: cleaning up");
427
428 if (g_discovery) {
431 g_discovery = NULL;
432 }
433
434 return (session_result == ASCIICHAT_OK) ? 0 : (int)session_result;
435}
asciichat_error_t session_client_like_run(const session_client_like_config_t *config)
void set_interrupt_callback(void(*cb)(void))
void discovery_session_stop(discovery_session_t *session)
Stop the discovery session.
discovery_session_t * discovery_session_create(const discovery_config_t *config)
Create a new discovery session.
asciichat_error_t discovery_session_start(discovery_session_t *session)
Start the discovery session.
void discovery_session_destroy(discovery_session_t *session)
Destroy discovery session and free resources.
Configuration for discovery session.
const char * acds_address
ACDS address (default: "127.0.0.1")