MCPcopy Create free account
hub / github.com/DeusData/codebase-memory-mcp / win_endpoint_refresh_rendezvous

Function win_endpoint_refresh_rendezvous

src/daemon/ipc.c:4655–4715  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

4653}
4654
4655static win_rendezvous_status_t win_endpoint_refresh_rendezvous(
4656 const cbm_daemon_ipc_endpoint_t *endpoint) {
4657 if (!endpoint || !endpoint->user_sid || endpoint->user_sid_length == 0) {
4658 return WIN_RENDEZVOUS_ERROR;
4659 }
4660 cbm_private_lock_directory_t *directory = NULL;
4661 cbm_private_file_lock_t *record_lock = NULL;
4662 cbm_private_file_lock_status_t directory_status =
4663 cbm_daemon_ipc_private_lock_directory_new(endpoint, &directory);
4664 if (directory_status != CBM_PRIVATE_FILE_LOCK_OK) {
4665 win_endpoint_generation_invalidate(endpoint);
4666 return WIN_RENDEZVOUS_ERROR;
4667 }
4668 cbm_private_file_lock_status_t lock_status = cbm_private_file_lock_try_acquire(
4669 directory, CBM_DAEMON_IPC_WINDOWS_RENDEZVOUS_FILE, CBM_PRIVATE_FILE_LOCK_SH, &record_lock);
4670 if (lock_status != CBM_PRIVATE_FILE_LOCK_OK) {
4671 win_private_lock_release_complete(&record_lock);
4672 cbm_private_lock_directory_close(directory);
4673 win_endpoint_generation_invalidate(endpoint);
4674 return lock_status == CBM_PRIVATE_FILE_LOCK_BUSY ? WIN_RENDEZVOUS_BUSY
4675 : WIN_RENDEZVOUS_ERROR;
4676 }
4677
4678 uint8_t record[CBM_DAEMON_IPC_WINDOWS_RENDEZVOUS_RECORD_SIZE];
4679 size_t record_length = 0;
4680 cbm_private_file_lock_status_t read_status =
4681 cbm_private_file_lock_payload_read(record_lock, record, sizeof(record), &record_length);
4682 uint8_t nonce[CBM_DAEMON_IPC_WINDOWS_NONCE_SIZE];
4683 char address[CBM_DAEMON_IPC_WINDOWS_NAME_CAP];
4684 bool decoded =
4685 read_status == CBM_PRIVATE_FILE_LOCK_OK &&
4686 cbm_daemon_ipc_windows_rendezvous_record_decode(record, record_length, nonce, address);
4687 char expected[CBM_DAEMON_IPC_WINDOWS_NAME_CAP];
4688 bool bound =
4689 decoded &&
4690 cbm_daemon_ipc_windows_generation_address(endpoint->user_sid, endpoint->user_sid_length,
4691 endpoint->instance_key, nonce, expected) &&
4692 strcmp(expected, address) == 0;
4693 win_rendezvous_status_t result;
4694 if (read_status != CBM_PRIVATE_FILE_LOCK_OK) {
4695 win_endpoint_generation_invalidate(endpoint);
4696 result = WIN_RENDEZVOUS_ERROR;
4697 } else if (record_length == 0) {
4698 win_endpoint_generation_invalidate(endpoint);
4699 result = WIN_RENDEZVOUS_ABSENT;
4700 } else if (!bound) {
4701 win_endpoint_generation_invalidate(endpoint);
4702 result = WIN_RENDEZVOUS_CORRUPT;
4703 } else if (!win_endpoint_generation_install(endpoint, address)) {
4704 win_endpoint_generation_invalidate(endpoint);
4705 result = WIN_RENDEZVOUS_ERROR;
4706 } else {
4707 result = WIN_RENDEZVOUS_VALID;
4708 }
4709 /* Keep the record lock through the in-memory snapshot update. Otherwise
4710 * a reader of generation N could install/invalidate after a startup owner
4711 * has published generation N+1, regressing this endpoint to stale state. */
4712 win_private_lock_release_complete(&record_lock);

Tested by

no test coverage detected