Skip to content

Commit

Permalink
Revert "Merge pull request snowdrop#136 from graben/nodeIdentifier"
Browse files Browse the repository at this point in the history
  • Loading branch information
graben authored and cunningt committed Jun 24, 2024
1 parent 0c00340 commit 791c95d
Showing 1 changed file with 2 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,6 @@

package me.snowdrop.boot.narayana.core.properties;

import java.nio.charset.StandardCharsets;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.util.List;

import com.arjuna.ats.arjuna.common.CoordinatorEnvironmentBean;
Expand All @@ -37,8 +34,6 @@
*/
public class NarayanaPropertiesInitializer implements InitializingBean {

private static final String HASH_ALGORITHM_FOR_SHORTENING = "SHA-224";

private final NarayanaProperties properties;

public NarayanaPropertiesInitializer(NarayanaProperties narayanaProperties) {
Expand All @@ -64,24 +59,13 @@ public void afterPropertiesSet() {
}

private void setNodeIdentifier(String nodeIdentifier) {
String verifiedNodeIdentifier = nodeIdentifier;
try {
if (nodeIdentifier != null && nodeIdentifier.getBytes(StandardCharsets.UTF_8).length > 28) {
verifiedNodeIdentifier = shortenNodeIdentifier(nodeIdentifier);
}

getPopulator(CoreEnvironmentBean.class).setNodeIdentifier(verifiedNodeIdentifier);
} catch (CoreEnvironmentBeanException | NoSuchAlgorithmException e) {
getPopulator(CoreEnvironmentBean.class).setNodeIdentifier(nodeIdentifier);
} catch (CoreEnvironmentBeanException e) {
throw new IllegalArgumentException(e);
}
}

private String shortenNodeIdentifier(String nodeIdentifier) throws NoSuchAlgorithmException {
final byte[] nodeIdentifierAsBytes = nodeIdentifier.getBytes();
MessageDigest messageDigest224 = MessageDigest.getInstance(HASH_ALGORITHM_FOR_SHORTENING);
return new String(messageDigest224.digest(nodeIdentifierAsBytes), StandardCharsets.UTF_8);
}

private void setXARecoveryNodes(List<String> xaRecoveryNodes) {
if (xaRecoveryNodes.isEmpty()) {
xaRecoveryNodes = List.of(getPopulator(CoreEnvironmentBean.class).getNodeIdentifier());
Expand Down

0 comments on commit 791c95d

Please sign in to comment.