diff --git a/leyden/pom.xml b/leyden/pom.xml index 42175d402..9fd3261ba 100644 --- a/leyden/pom.xml +++ b/leyden/pom.xml @@ -15,6 +15,10 @@ com.salesforce.apollo memberships + + com.h2database + h2-mvstore + diff --git a/leyden/src/main/java/com/salesforce/apollo/leyden/LeydenJar.java b/leyden/src/main/java/com/salesforce/apollo/leyden/LeydenJar.java index 702d1b2ea..0f26dc82e 100644 --- a/leyden/src/main/java/com/salesforce/apollo/leyden/LeydenJar.java +++ b/leyden/src/main/java/com/salesforce/apollo/leyden/LeydenJar.java @@ -1,5 +1,6 @@ package com.salesforce.apollo.leyden; +import com.google.protobuf.InvalidProtocolBufferException; import com.salesforce.apollo.archipelago.Router; import com.salesforce.apollo.archipelago.RouterImpl; import com.salesforce.apollo.cryptography.Digest; @@ -13,19 +14,26 @@ import com.salesforce.apollo.thoth.proto.Intervals; import com.salesforce.apollo.thoth.proto.Update; import com.salesforce.apollo.thoth.proto.Updating; +import org.h2.mvstore.MVMap; +import org.h2.mvstore.MVStore; + +import java.util.concurrent.atomic.AtomicBoolean; /** * @author hal.hildebrand **/ public class LeydenJar { - private final Context context; - private final RouterImpl.CommonCommunications reconComms; - private final RouterImpl.CommonCommunications binderComms; - private final double fpr; - private final SigningMember member; + public static final String LEYDEN_JAR = "Leyden-Jar"; + private final Context context; + private final RouterImpl.CommonCommunications reconComms; + private final RouterImpl.CommonCommunications binderComms; + private final double fpr; + private final SigningMember member; + private final MVMap bottled; + private final AtomicBoolean started = new AtomicBoolean(); - public LeydenJar(SigningMember member, Context context, Router communications, double fpr, + public LeydenJar(SigningMember member, Context context, Router communications, double fpr, MVStore store, ReconciliationMetrics metrics, BinderMetrics binderMetrics) { this.context = context; this.member = member; @@ -42,6 +50,19 @@ public LeydenJar(SigningMember member, Context context, Router communica binderMetrics), c -> Bind.getCreate(c, binderMetrics), Bind.getLocalLoopback(borders, member)); this.fpr = fpr; + bottled = store.openMap(LEYDEN_JAR, new MVMap.Builder().keyType(new ProtobufDatatype(b -> { + try { + return Key_.parseFrom(b); + } catch (InvalidProtocolBufferException e) { + throw new RuntimeException(e); + } + })).valueType(new ProtobufDatatype(b -> { + try { + return Binding.parseFrom(b); + } catch (InvalidProtocolBufferException e) { + throw new RuntimeException(e); + } + }))); } private class Reconciled implements ReconciliationService { diff --git a/model/src/main/java/com/salesforce/apollo/model/ProtobufDatatype.java b/leyden/src/main/java/com/salesforce/apollo/leyden/ProtobufDatatype.java similarity index 92% rename from model/src/main/java/com/salesforce/apollo/model/ProtobufDatatype.java rename to leyden/src/main/java/com/salesforce/apollo/leyden/ProtobufDatatype.java index 372bfcc60..77103330a 100644 --- a/model/src/main/java/com/salesforce/apollo/model/ProtobufDatatype.java +++ b/leyden/src/main/java/com/salesforce/apollo/leyden/ProtobufDatatype.java @@ -4,25 +4,23 @@ * SPDX-License-Identifier: BSD-3-Clause * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/BSD-3-Clause */ -package com.salesforce.apollo.model; - -import java.nio.ByteBuffer; -import java.util.function.Function; +package com.salesforce.apollo.leyden; +import com.google.protobuf.Message; import org.h2.mvstore.DataUtils; import org.h2.mvstore.WriteBuffer; import org.h2.mvstore.type.BasicDataType; -import com.google.protobuf.Message; +import java.nio.ByteBuffer; +import java.util.function.Function; /** * @author hal.hildebrand - * */ public final class ProtobufDatatype extends BasicDataType { private Function factory; - private ProtobufDatatype(Function factory) { + public ProtobufDatatype(Function factory) { this.factory = factory; } diff --git a/pom.xml b/pom.xml index 1eac3bf76..05fd5a022 100644 --- a/pom.xml +++ b/pom.xml @@ -175,6 +175,11 @@ cryptography ${project.version} + + com.salesforce.apollo + leyden + ${project.version} + com.salesforce.apollo isolates