The code you posted effectively generates a unique ID for each node in the document. This allows any node to be referenced, if you know its path.
I have had inter-PDF links working but it has been many years since so my memory is hazy. Regarding the using the ID instead of a hash, you could try something like this:
// leave existing code as-is
var hash = application.calculateHash( currentNode.getNodePath( 1 ));
var linkName = "links:link" + hash.toString( 16 );
// new code could add a second set of links
linkName = "links:idlink" + formatting.getAttribute("id", false);
If you use that approach you will have a second set of links which are referencable via links:idlinkABC123 where ABC123 is the ID attribute value. You might have to do some work on translating the ID attribute value so it forms an allowable APP tag name. e.g. A-z 0-9 _ -