Merge pull request #11334 from annando/guid-style

Use a nicer GUID style format
This commit is contained in:
Hypolite Petovan 2022-03-18 07:30:34 -04:00 committed by GitHub
commit 61e023d448
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 7 additions and 9 deletions

View File

@ -1773,7 +1773,10 @@ class Item
} }
/** /**
* Creates an unique guid out of a given uri * Creates an unique guid out of a given uri.
* This function is used for messages outside the fediverse (Connector posts, feeds, Mails, ...)
* Posts that are created on this system are using System::createUUID.
* Received ActivityPub posts are using Processor::getGUIDByURL.
* *
* @param string $uri uri of an item entry * @param string $uri uri of an item entry
* @param string $host hostname for the GUID prefix * @param string $host hostname for the GUID prefix
@ -1785,19 +1788,14 @@ class Item
// We have to avoid that different routines could accidentally create the same value // We have to avoid that different routines could accidentally create the same value
$parsed = parse_url($uri); $parsed = parse_url($uri);
// We use a hash of the hostname as prefix for the guid
$guid_prefix = hash("crc32", $host);
// Remove the scheme to make sure that "https" and "http" doesn't make a difference // Remove the scheme to make sure that "https" and "http" doesn't make a difference
unset($parsed["scheme"]); unset($parsed["scheme"]);
// Glue it together to be able to make a hash from it // Glue it together to be able to make a hash from it
$host_id = implode("/", $parsed); $host_id = implode("/", $parsed);
// We could use any hash algorithm since it isn't a security issue // Use a mixture of several hashes to provide some GUID like experience
$host_hash = hash("ripemd128", $host_id); return hash("crc32", $host) . '-'. hash('joaat', $host_id) . '-'. hash('fnv164', $host_id);
return $guid_prefix.$host_hash;
} }
/** /**

View File

@ -553,7 +553,7 @@ class Processor
} }
/** /**
* Generate a GUID out of an URL * Generate a GUID out of an URL of an ActivityPub post.
* *
* @param string $url message URL * @param string $url message URL
* @return string with GUID * @return string with GUID