All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.quorum.tessera.p2p.partyinfo.PartyStore Maven / Gradle / Ivy

Go to download

Tessera is a stateless Java system that is used to enable the encryption, decryption, and distribution of private transactions for Quorum.

There is a newer version: 24.4.2
Show newest version
package com.quorum.tessera.p2p.partyinfo;

import com.quorum.tessera.context.RuntimeContext;
import com.quorum.tessera.discovery.NodeUri;
import java.net.URI;
import java.util.ServiceLoader;
import java.util.Set;
import java.util.stream.Collectors;

/*
 * Support legacy collation of all parties to be added to
 * party info responses so nodes learn of nodes.
 */
public interface PartyStore {

  default void loadFromConfigIfEmpty() {
    RuntimeContext runtimeContext = RuntimeContext.getInstance();

    final Set parties = getParties();

    final URI ownUri = NodeUri.create(runtimeContext.getP2pServerUri()).asURI();

    final Set peerList =
        runtimeContext.getPeers().stream()
            .map(NodeUri::create)
            .map(NodeUri::asURI)
            .filter(p -> !p.equals(ownUri))
            .collect(Collectors.toUnmodifiableSet());

    if (parties.isEmpty() || !peerList.stream().anyMatch(parties::contains)) {
      peerList.forEach(this::store);
    }
  }

  Set getParties();

  PartyStore store(URI party);

  PartyStore remove(URI party);

  static PartyStore getInstance() {
    return ServiceLoader.load(PartyStore.class).findFirst().get();
  }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy