Skip to content

Commit

Permalink
Refactors time verifier communication
Browse files Browse the repository at this point in the history
  • Loading branch information
Ashy5000 committed Apr 5, 2024
1 parent c8930de commit 0fc2f42
Show file tree
Hide file tree
Showing 14 changed files with 20 additions and 16 deletions.
2 changes: 1 addition & 1 deletion block_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ func TestBlock(t *testing.T) {
var b big.Int
b.SetUint64(321)
var parameters dsa.Parameters
dsa.GenerateParameters(&parameters, rand.Reader, dsa.ParameterSizes(0))
dsa.GenerateParameters(&parameters, rand.Reader, dsa.ParameterSizes(3))
block := Block{
Transactions: []Transaction{
{
Expand Down
Binary file modified builds/node/node_darwin-amd64
Binary file not shown.
Binary file modified builds/node/node_darwin-arm64
Binary file not shown.
Binary file modified builds/node/node_linux-386
Binary file not shown.
Binary file modified builds/node/node_linux-amd64
Binary file not shown.
Binary file modified builds/node/node_linux-arm
Binary file not shown.
Binary file modified builds/node/node_linux-arm64
Binary file not shown.
Binary file modified builds/node/node_windows-386
Binary file not shown.
Binary file modified builds/node/node_windows-amd64
Binary file not shown.
Binary file modified builds/node/node_windows-arm
Binary file not shown.
Binary file modified builds/node/node_windows-arm64
Binary file not shown.
2 changes: 1 addition & 1 deletion cmdline.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ func RunCmd(input string) {
} else if action == "keygen" {
var privateKey dsa.PrivateKey
var params dsa.Parameters
err := dsa.GenerateParameters(&params, rand.Reader, dsa.ParameterSizes(0))
err := dsa.GenerateParameters(&params, rand.Reader, dsa.ParameterSizes(3))
if err != nil {
panic(err)
}
Expand Down
20 changes: 15 additions & 5 deletions create_block.go
Original file line number Diff line number Diff line change
Expand Up @@ -150,14 +150,24 @@ func CreateBlock() (Block, error) {
fmt.Println("Time verifier believes block is invalid.")
continue
}
// Unmarshal the response body
responseBlock := Block{}
err = json.Unmarshal(bodyBytes, &responseBlock)
// Split the response body into the signature and the public key
split := strings.Split(string(bodyBytes), ":")
// Unmarshal the signature
var signature Signature
err = json.Unmarshal([]byte(split[0]), &signature)
if err != nil {
panic(err)
}
// Set the time verifiers
block.TimeVerifiers = responseBlock.TimeVerifiers // TODO: Verify time verifiers
// Unmarshal the public key
var publicKey dsa.PublicKey
err = json.Unmarshal([]byte(split[1]), &publicKey)
if err != nil {
panic(err)
}
// Add the time verifier to the block
block.TimeVerifiers = append(block.TimeVerifiers, publicKey)
// Add the time verifier signature to the block
block.TimeVerifierSignatures = append(block.TimeVerifierSignatures, signature)
}
if int64(len(block.TimeVerifiers)) < GetMinerCount(len(blockchain))/5 {
fmt.Println("Not enough time verifiers.")
Expand Down
12 changes: 3 additions & 9 deletions server.go
Original file line number Diff line number Diff line change
Expand Up @@ -224,18 +224,12 @@ func HandleVerifyTimeRequest(w http.ResponseWriter, req *http.Request) {
R: *r,
S: *s,
}
block.TimeVerifierSignatures = append(block.TimeVerifierSignatures, signature)
block.TimeVerifiers = append(block.TimeVerifiers, key.PublicKey)
// Convert the block back to JSON
blockBytes, err := json.Marshal(&block)
if err != nil {
panic(err)
}
// Send the block back to the requester
_, err = io.WriteString(w, string(blockBytes))
// Send the signature and public key back to the requester
signatureBytes, err := json.Marshal(signature)
if err != nil {
panic(err)
}
_, err = io.WriteString(w, string(signatureBytes)+":"+key.Y.String())
}

func HandlePeersRequest(w http.ResponseWriter, _ *http.Request) {
Expand Down

0 comments on commit 0fc2f42

Please sign in to comment.