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

Function runtime_peer_image_verify

src/daemon/runtime.c:1052–1098  ·  view source on GitHub ↗

#1955: the HELLO must prove the peer runs this daemon's build. The cheap * proof is "same image file as the daemon"; a peer running a DIFFERENT file * with identical bytes (a second install path, a package-manager copy) needs * the full fingerprint, i.e. hashing the whole (~300 MB) image. That hash is * slower than the client's HELLO budget, so the client abandoned it and every * re-probe sta

Source from the content-addressed store, hash-verified

1050 * later admissions of the same unchanged file match it by metadata, exactly
1051 * like the active image. The accepted set of images is unchanged. */
1052static runtime_peer_image_verdict_t runtime_peer_image_verify(cbm_daemon_runtime_service_t *service,
1053 uint64_t process_id,
1054 const char *requested_build) {
1055 runtime_process_image_reference_t peer;
1056 runtime_process_image_reference_init(&peer);
1057 bool peer_held = runtime_process_image_reference_acquire(process_id, &peer, NULL);
1058 bool known = false;
1059 if (peer_held) {
1060 known = runtime_process_image_reference_same(&service->active_image, &peer);
1061#ifdef CBM_ENABLE_TEST_SEAMS
1062 if (atomic_load(&runtime_force_peer_image_distinct_copy_seam)) {
1063 known = false;
1064 }
1065#endif
1066 if (!known) {
1067 cbm_mutex_lock(&service->mutex);
1068 known = runtime_verified_peer_image_known_locked(service, &peer);
1069 cbm_mutex_unlock(&service->mutex);
1070 }
1071 }
1072 bool released = runtime_process_image_reference_release(&peer);
1073 if (known && released) {
1074 return RUNTIME_PEER_IMAGE_VERIFIED;
1075 }
1076
1077 char fingerprint[CBM_DAEMON_BUILD_FINGERPRINT_SIZE];
1078 runtime_process_image_reference_t hashed;
1079 runtime_process_image_reference_init(&hashed);
1080 runtime_note_peer_image_hash();
1081 bool fingerprinted = runtime_process_image_reference_acquire(process_id, &hashed, fingerprint);
1082 bool verified = fingerprinted && strcmp(fingerprint, requested_build) == 0 &&
1083 strcmp(fingerprint, service->identity.build_fingerprint) == 0;
1084 if (verified) {
1085 cbm_mutex_lock(&service->mutex);
1086 if (service->verified_peer_image_count < RUNTIME_VERIFIED_PEER_IMAGE_CAPACITY &&
1087 !runtime_verified_peer_image_known_locked(service, &hashed)) {
1088 service->verified_peer_images[service->verified_peer_image_count++] = hashed;
1089 runtime_process_image_reference_init(&hashed);
1090 }
1091 cbm_mutex_unlock(&service->mutex);
1092 }
1093 (void)runtime_process_image_reference_release(&hashed);
1094 if (verified) {
1095 return RUNTIME_PEER_IMAGE_VERIFIED;
1096 }
1097 return fingerprinted ? RUNTIME_PEER_IMAGE_MISMATCH : RUNTIME_PEER_IMAGE_UNVERIFIABLE;
1098}
1099
1100static void runtime_verified_peer_images_release(cbm_daemon_runtime_service_t *service) {
1101 for (size_t i = 0; i < service->verified_peer_image_count; i++) {

Callers 1

Tested by

no test coverage detected