Skip to content

Commit

Permalink
add external fields to combination and unicorn
Browse files Browse the repository at this point in the history
  • Loading branch information
leandrofpk committed Apr 2, 2022
1 parent 9ce42dc commit 46129d4
Show file tree
Hide file tree
Showing 17 changed files with 118 additions and 57 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
ALTER TABLE vdf_combination
ADD COLUMN ext_src_id varchar(255) NOT NULL,
ADD COLUMN ext_status smallint(6) NOT NULL,
ADD COLUMN ext_value varchar(255) NOT NULL;
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
ALTER TABLE vdf_unicorn
ADD COLUMN ext_src_id varchar(255) NOT NULL,
ADD COLUMN ext_status smallint(6) NOT NULL,
ADD COLUMN ext_value varchar(255) NOT NULL;
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.example.beacon.interfac.api.dto;

import com.example.beacon.interfac.domain.pulse.External;
import com.example.beacon.interfac.domain.pulse.ExternalDto;
import com.example.beacon.interfac.domain.pulse.ListValue;
import com.example.beacon.interfac.infra.PulseEntity;
import com.fasterxml.jackson.annotation.JsonFormat;
Expand Down Expand Up @@ -36,7 +36,7 @@ public class PulseDto {

private String localRandomValue;

private External external;
private ExternalDto external;

private List<ListValue> listValues;

Expand Down Expand Up @@ -65,7 +65,7 @@ public PulseDto(PulseEntity pulseEntity){
this.outputValue = pulseEntity.getOutputValue();
this.statusCode = pulseEntity.getStatusCode();

this.external = External.newExternalFromEntity(pulseEntity.getExternalEntity());
this.external = ExternalDto.newExternalFromEntity(pulseEntity.getExternalEntity());
this.listValues = convertListValuesToPulse(pulseEntity);
}

Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package com.example.beacon.interfac.domain.pulse;

import com.example.beacon.interfac.infra.ExternalEntity;
import lombok.Data;
import lombok.NoArgsConstructor;

@Data
@NoArgsConstructor
public class ExternalDto {

private String sourceId;

private short statusCode;

private String value;

private ExternalDto(String sourceId, short statusCode, String value) {
this.sourceId = sourceId;
this.statusCode = statusCode;
this.value = value;
}

public static ExternalDto newExternalFromEntity(ExternalEntity entity){
return new ExternalDto(entity.getSourceId(), entity.getStatusCode(), entity.getValue());
}

@Override
public String toString() {
return "External{" +
"sourceId='" + sourceId + '\'' +
", statusCode=" + statusCode +
", value='" + value + '\'' +
'}';
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,18 @@ public class ExternalEntity {
public ExternalEntity() {
}

public static ExternalEntity newExternalEntity(){
return new ExternalEntity("00000000000000000000000000000000000000000000000000000000000000000000000000000000" +
"000000000000000000000000000000000000000000000000",
new Short("0"),
"000000000000000000000000000000000000000000000000000000000000000000000000000000" +
"00000000000000000000000000000000000000000000000000");
}

public ExternalEntity(String sourceId, short statusCode, String value) {
this.sourceId = sourceId;
this.statusCode = statusCode;
this.value = value;
}

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,12 @@ public ByteSerializationFields(CombinationEntity entity) throws IOException {
byteSerializeHash(entity.getCertificateId());
encode8(entity.getPulseIndex());
byteSerializeString(getTimeStampFormated(entity.getTimeStamp()));

// external
byteSerializeHash(entity.getExternal().getSourceId());
encode4(entity.getExternal().getStatusCode());
byteSerializeHash(entity.getExternal().getValue());

byteSerializeString(entity.getCombination());
for (CombinationSeedEntity e : entity.getSeedList()) {
byteSerializeString(getTimeStampFormated(e.getTimeStamp()));
Expand All @@ -73,6 +79,12 @@ public ByteSerializationFields(VdfUnicornEntity entity) throws IOException {
byteSerializeHash(entity.getCertificateId());
encode8(entity.getPulseIndex());
byteSerializeString(getTimeStampFormated(entity.getTimeStamp()));

// external
byteSerializeHash(entity.getExternal().getSourceId());
encode4(entity.getExternal().getStatusCode());
byteSerializeHash(entity.getExternal().getValue());

byteSerializeString(entity.getCombination());
for (VdfUnicornSeedEntity e : entity.getSeedList()) {
byteSerializeString(getTimeStampFormated(e.getTimeStamp()));
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.example.beacon.vdf.application;

import com.example.beacon.interfac.domain.pulse.ExternalDto;
import com.example.beacon.vdf.application.combination.dto.VdfSlothDto;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.annotation.JsonPropertyOrder;
Expand Down Expand Up @@ -35,6 +36,8 @@ public class VdfPulseDto {

private int period;

private ExternalDto external;

private String combination;

private List<VdfSeedDto> seedList = new ArrayList<>();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.example.beacon.vdf.application.combination;

import com.example.beacon.interfac.domain.pulse.ExternalDto;
import com.example.beacon.vdf.application.VdfPulseDto;
import com.example.beacon.vdf.application.VdfSeedDto;
import com.example.beacon.vdf.application.combination.dto.VdfSlothDto;
Expand Down Expand Up @@ -150,6 +151,8 @@ private VdfPulseDto convertToDto(CombinationEntity entity){
dto.setCombination(entity.getCombination());
dto.setOutputValue(entity.getOutputValue());

dto.setExternal(ExternalDto.newExternalFromEntity(entity.getExternal()));

entity.getSeedList().forEach(s ->
dto.addSeed(new VdfSeedDto(s.getSeed(),
DateUtil.getTimeStampFormated(s.getTimeStamp()),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import br.gov.inmetro.beacon.library.ciphersuite.suite0.CipherSuiteBuilder;
import br.gov.inmetro.beacon.library.ciphersuite.suite0.CriptoUtilService;
import br.gov.inmetro.beacon.library.ciphersuite.suite0.ICipherSuite;
import com.example.beacon.interfac.infra.ExternalEntity;
import com.example.beacon.shared.ByteSerializationFields;
import com.example.beacon.vdf.VdfSloth;
import com.example.beacon.vdf.application.combination.dto.SeedUnicordCombinationVo;
Expand Down Expand Up @@ -90,6 +91,9 @@ protected void persist(String timeStamp, List<SeedUnicordCombinationVo> seedUnic
combinationEntity.setTimeStamp(ZonedDateTime.parse(timeStamp, DateTimeFormatter.ISO_DATE_TIME));
combinationEntity.setCertificateId(this.certificateId);
combinationEntity.setCipherSuite(0);

combinationEntity.setExternal(ExternalEntity.newExternalEntity());

combinationEntity.setCombination(env.getProperty("vdf.combination").toUpperCase());
combinationEntity.setPeriod(Integer.parseInt(env.getProperty("beacon.combination.period")));

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.example.beacon.vdf.application.vdfunicorn;

import com.example.beacon.interfac.domain.pulse.ExternalDto;
import com.example.beacon.vdf.application.VdfPulseDto;
import com.example.beacon.vdf.application.VdfSeedDto;
import com.example.beacon.vdf.application.combination.dto.VdfSlothDto;
Expand Down Expand Up @@ -190,6 +191,8 @@ private VdfPulseDto convertToDto(VdfUnicornEntity entity){
dto.setCombination(entity.getCombination());
dto.setOutputValue(entity.getOutputValue());

dto.setExternal(ExternalDto.newExternalFromEntity(entity.getExternal()));

entity.getSeedList().forEach(s ->
dto.addSeed(new VdfSeedDto(s.getSeed(),
DateUtil.getTimeStampFormated(s.getTimeStamp()),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import br.gov.inmetro.beacon.library.ciphersuite.suite0.CipherSuiteBuilder;
import br.gov.inmetro.beacon.library.ciphersuite.suite0.CriptoUtilService;
import br.gov.inmetro.beacon.library.ciphersuite.suite0.ICipherSuite;
import com.example.beacon.interfac.infra.ExternalEntity;
import com.example.beacon.shared.ByteSerializationFields;
import com.example.beacon.vdf.VdfSloth;
import com.example.beacon.vdf.application.VdfSeedDto;
Expand Down Expand Up @@ -104,11 +105,6 @@ private SeedUnicordCombinationVo calcSeedConcat(SeedPostDto dtoNew, List<SeedUni
}

public void endTimeSlot() throws Exception {
if (this.seedListUnicordCombination.isEmpty()){
this.statusEnum = StatusEnum.STOPPED;
return;
}

this.statusEnum = StatusEnum.RUNNING;
List<SeedSourceDto> honestSeeds = seedBuilder.getHonestPartyUnicorn();

Expand Down Expand Up @@ -196,6 +192,8 @@ protected void persist(BigInteger y, BigInteger x, int iterations) throws Except
unicornEntity.setCombination(env.getProperty("vdf.combination").toUpperCase());
unicornEntity.setPeriod(Integer.parseInt(env.getProperty("beacon.unicorn.period")));

unicornEntity.setExternal(ExternalEntity.newExternalEntity());

this.seedListUnicordCombination.forEach(SeedUnicordCombinationVo ->
unicornEntity.addSeed(new VdfUnicornSeedEntity(SeedUnicordCombinationVo, unicornEntity)));

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.example.beacon.vdf.infra.entity;

import com.example.beacon.interfac.infra.ExternalEntity;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
Expand Down Expand Up @@ -36,6 +37,9 @@ public class CombinationEntity {

private int period;

@Embedded
private ExternalEntity external;

private String combination;

@OneToMany(fetch = FetchType.LAZY, mappedBy = "combinationEntity", cascade = CascadeType.ALL)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.example.beacon.vdf.infra.entity;

import com.example.beacon.interfac.infra.ExternalEntity;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
Expand Down Expand Up @@ -36,6 +37,9 @@ public class VdfUnicornEntity {

private int period;

@Embedded
private ExternalEntity external;

private String combination;

@OneToMany(fetch = FetchType.LAZY, mappedBy = "vdfUnicornEntity", cascade = CascadeType.ALL)
Expand Down
14 changes: 9 additions & 5 deletions beacon-interface/src/main/resources/application.properties
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,11 @@ spring.datasource.password=${RDS_PASSWORD:123456}
spring.jpa.hibernate.ddl-auto=validate

#hibernate
spring.jpa.show-sql=false
spring.jpa.show-sql=true

spring.jpa.properties.hibernate.use_sql_comments=true
spring.jpa.properties.hibernate.format_sql=true

spring.jpa.properties.hibernate.dialect = org.hibernate.dialect.MySQL5Dialect
spring.jpa.properties.hibernate.jdbc.time_zone=UTC

Expand Down Expand Up @@ -60,8 +64,8 @@ beacon.x509.privatekey=${BEACON_X509_PRIVATEKEY}
#170000 = 1m 2s running
#170000*8 = 1360000
beacon.combination.iterations=1360000
#period in minutes
beacon.combination.period=10
#period in milliseconds
beacon.combination.period=600000

#
beacon.combination.sources.seconds-to-retry=5
Expand All @@ -83,8 +87,8 @@ beacon.unicorn.start.submission=0 0,30 * * * *
#170000 = 1 minute running
#170000*24 = 1530000
beacon.unicorn.iterations=1530000
#period in minutes
beacon.unicorn.period=30
#period in milliseconds
beacon.unicorn.period=1800000


#########################################################################
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,15 @@ function atualizarRecord(data) {
lista += '<tr><td>Time:</td>';
lista += '<td>' + pulse.timeStamp + '</td></tr>';

lista += '<tr><td>External Source Id:</td>';
lista += '<td style="word-break: break-word">' + pulse.external.sourceId + '</td></tr>';

lista += '<tr><td>External Status Code:</td>';
lista += '<td>' + pulse.external.statusCode + '</td></tr>';

lista += '<tr><td>External Value:</td>';
lista += '<td style="word-break: break-word">' + pulse.external.value + '</td></tr>';

lista += '<tr><td>Combination:</td>';
lista += '<td>' + pulse.combination + '</td></tr>';

Expand Down
9 changes: 9 additions & 0 deletions beacon-interface/src/main/resources/static/js/vdf-unicorn.js
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,15 @@ function atualizarRecord(data) {
lista += '<tr><td>Time:</td>';
lista += '<td>' + pulse.timeStamp + '</td></tr>';

lista += '<tr><td>External Source Id:</td>';
lista += '<td style="word-break: break-word">' + pulse.external.sourceId + '</td></tr>';

lista += '<tr><td>External Status Code:</td>';
lista += '<td>' + pulse.external.statusCode + '</td></tr>';

lista += '<tr><td>External Value:</td>';
lista += '<td style="word-break: break-word">' + pulse.external.value + '</td></tr>';

lista += '<tr><td>Combination:</td>';
lista += '<td>' + pulse.combination + '</td></tr>';

Expand Down

0 comments on commit 46129d4

Please sign in to comment.