merge
This commit is contained in:
3
.idea/.gitignore
generated
vendored
3
.idea/.gitignore
generated
vendored
@@ -1,4 +1,5 @@
|
||||
# Default ignored files
|
||||
/shelf/
|
||||
/workspace.xml
|
||||
/target/
|
||||
/target/
|
||||
/.idea/
|
||||
@@ -80,6 +80,8 @@ public class TransportMessageDataContract
|
||||
transportMessageDataContract.id = _id;
|
||||
transportMessageDataContract.version = 1;
|
||||
transportMessageDataContract.signedValidatorMessages = new HashSet<>();
|
||||
transportMessageDataContract.peerContracts = new HashSet<>();
|
||||
transportMessageDataContract.previousVersions = new HashSet<>();
|
||||
transportMessageDataContract.signedValidatorMessages.add(SignedValidatorMessage.create(_message,_privateKey,_publicKey));
|
||||
transportMessageDataContract.sent = Instant.now();
|
||||
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package com.hypernode.ledger;
|
||||
import jakarta.annotation.PostConstruct;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
@@ -11,7 +12,8 @@ import java.util.*;
|
||||
@RestController
|
||||
public class WebServiceEndpoints
|
||||
{
|
||||
WebServiceMethods _this;
|
||||
@Autowired
|
||||
public WebServiceMethods _this;
|
||||
|
||||
/**
|
||||
* Method to generate a public/private key pair, so that you can generate more accounts
|
||||
@@ -84,7 +86,7 @@ public class WebServiceEndpoints
|
||||
* @param _dataContract
|
||||
*/
|
||||
|
||||
@PostMapping("/receive")
|
||||
@PostMapping("/receiveData")
|
||||
public void receiveData(TransportMessageDataContract _dataContract) {
|
||||
_this.receiveData(_dataContract);
|
||||
}
|
||||
@@ -118,10 +120,10 @@ public class WebServiceEndpoints
|
||||
* Test method to initialize a new ledger from scratch
|
||||
*/
|
||||
@GetMapping("/initCreateNewLedger")
|
||||
public void initCreateNewLedger() {
|
||||
if(_this.privateKey.length > 0)
|
||||
public String initCreateNewLedger() {
|
||||
if(_this.privateKey != null)
|
||||
{
|
||||
return;
|
||||
return "Already Started";
|
||||
}
|
||||
String pubkey2Test =
|
||||
"""
|
||||
@@ -207,7 +209,7 @@ public class WebServiceEndpoints
|
||||
ValidatorNode validatorNode = new ValidatorNode();
|
||||
validatorNode.setPublicKey(Encryption.base64ToByteArray( pubKey));
|
||||
validatorNode.setId( 1);
|
||||
validatorNode.setConnectionString( "localhost:8080");
|
||||
validatorNode.setConnectionString( "http://localhost:8080");
|
||||
validatorNode.setAddress( Map.of(1, 1));
|
||||
validatorNode.setSignature(Encryption.signMessage(validatorNode.getConnectionString(),Encryption.base64ToByteArray(privKey)));
|
||||
validatorNodeList.add(validatorNode);
|
||||
@@ -216,20 +218,21 @@ public class WebServiceEndpoints
|
||||
_this.thisValidatorNode = validatorNode;
|
||||
|
||||
_this.initAndCreateNewLedger(Encryption.base64ToByteArray(privKey), Encryption.base64ToByteArray(pubKey), sdc);
|
||||
return "OK";
|
||||
}
|
||||
|
||||
/**
|
||||
* Test method to initialize a server and connecting it to an existing ledger
|
||||
*/
|
||||
@GetMapping("/testInitAndConnectToExistingLedger")
|
||||
public void testInitAndConnectToExistingLedger() {
|
||||
if(_this.privateKey.length > 0)
|
||||
public String testInitAndConnectToExistingLedger() {
|
||||
if(_this.privateKey != null)
|
||||
{
|
||||
return;
|
||||
return "Already Started";
|
||||
}
|
||||
String _connectionStringServer, _thisConnectionString, _privateKeyBase64, _publicKeyBase64;
|
||||
_connectionStringServer = "localhost:8080/";
|
||||
_thisConnectionString = "localhost:8081/";
|
||||
_connectionStringServer = "http://localhost:8080/";
|
||||
_thisConnectionString = "http://localhost:8081/";
|
||||
_privateKeyBase64 =
|
||||
"MIIEvQIBADANBgkqhkiG9w0BAQEFAASCBKcwggSjAgEAAoIBAQDM39MsfVR50mWT" +
|
||||
"Z+ZlzerKOE96H1X4lkaaGAbjg8SYcp3wzGn9I5193Vb8CgJWtAFW+/Q6cSqfUTQf" +
|
||||
@@ -266,6 +269,7 @@ public class WebServiceEndpoints
|
||||
"PxdWz8BB86JI/hIWqOJkTalz4PhvXfb+o4vakUgrL1hQwsWYQ49nwjgVWANtibPL" +
|
||||
"QwIDAQAB";
|
||||
_this.initAndConnectToExistingLedger(_connectionStringServer, _thisConnectionString, _privateKeyBase64, _publicKeyBase64);
|
||||
return "OK";
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -1,7 +1,9 @@
|
||||
package com.hypernode.ledger;
|
||||
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule;
|
||||
import jakarta.annotation.PostConstruct;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import java.io.File;
|
||||
@@ -13,7 +15,7 @@ import java.net.http.HttpResponse;
|
||||
import java.time.Duration;
|
||||
import java.time.Instant;
|
||||
import java.util.*;
|
||||
|
||||
@Service
|
||||
public class WebServiceMethods {
|
||||
|
||||
LedgerParameters ledgerParameters;
|
||||
@@ -91,6 +93,7 @@ public class WebServiceMethods {
|
||||
this.ledgerParameters = new LedgerParameters();
|
||||
this.ledgerParameters.setGroupParameters(this.statusDataContract.getValidatorNodeList().size());
|
||||
this.transportMessageDataContract = TransportMessageDataContract.create(_lastDataContract.getId() + 1, message, privateKey, publicKey);
|
||||
this.transportMessageDataContract.setPeerContracts(new HashSet<>());
|
||||
this.pendingPayments = new HashSet<>();
|
||||
this.authenticating = new HashSet<>();
|
||||
//you are now authenticated, at the next frame the Validator list will be updated
|
||||
@@ -296,8 +299,10 @@ public class WebServiceMethods {
|
||||
if (body == null) {
|
||||
request = builder.GET().build();
|
||||
} else {
|
||||
ObjectMapper objectmapper = new ObjectMapper();
|
||||
objectmapper.registerModule(new JavaTimeModule());
|
||||
request = builder
|
||||
.POST(HttpRequest.BodyPublishers.ofString(new ObjectMapper().writeValueAsString(body)))
|
||||
.POST(HttpRequest.BodyPublishers.ofString(objectmapper.writeValueAsString(body)))
|
||||
.build();
|
||||
}
|
||||
|
||||
@@ -327,7 +332,7 @@ public class WebServiceMethods {
|
||||
public boolean authenticateServer(String _publicKeyBase64, String _signedMessageBase64, String _connectionString, String _signedConnectionStringBase64) {
|
||||
if (
|
||||
!Encryption.verifySignedMessage(this.requestAuthenticationStringToSign(), _publicKeyBase64, _signedMessageBase64)
|
||||
|| !Encryption.verifySignedMessage(_connectionString+ _publicKeyBase64, _publicKeyBase64, _signedConnectionStringBase64)
|
||||
|| !Encryption.verifySignedMessage(_connectionString, _publicKeyBase64, _signedConnectionStringBase64)
|
||||
) {
|
||||
//TODO 3 maybe put on a blacklist
|
||||
//this authentication failed
|
||||
@@ -362,6 +367,7 @@ public class WebServiceMethods {
|
||||
{
|
||||
//start everything up
|
||||
this.sendData();
|
||||
this.sendData();
|
||||
//should not be needed, but here anyway if it turns out we need to explicitly initialize the caller
|
||||
//WebServiceMethods.callServerMethod(validatorNode.getConnectionString(),"initialize",this.statusDataContract);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user