-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
227 additions
and
176 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,56 +1,27 @@ | ||
package buzhashChunker | ||
|
||
import ( | ||
"crypto/sha512" | ||
"testing" | ||
|
||
"github.com/i5heu/ouroboros-db/pkg/types" | ||
) | ||
|
||
func TestChunkBytes(t *testing.T) { | ||
// Initialize variables for testing | ||
var input []byte = []byte("Hello World") | ||
expectedHash := sha512.Sum512([]byte("Hello World")) | ||
var expectedChunk types.Chunk = types.Chunk{ | ||
ChunkMeta: types.ChunkMeta{ | ||
Hash: expectedHash, | ||
DataLength: uint32(len(input)), | ||
}, | ||
Data: input, | ||
} | ||
var expectedChunks types.ChunkCollection = types.ChunkCollection{expectedChunk} | ||
var expectedMeta types.ChunkMetaCollection = types.ChunkMetaCollection{expectedChunk.ChunkMeta} | ||
|
||
// Call the function with the test input | ||
chunks, meta, err := ChunkBytes(input) | ||
if err != nil { | ||
t.Errorf("ChunkBytes(%s) returned an error: %v", input, err) | ||
expectedChunk := ChunkInformation{ | ||
ChunkNumber: 0, | ||
Data: []byte("Hello World"), | ||
} | ||
|
||
// Check the function's output against the expected output | ||
if len(chunks) != len(expectedChunks) { | ||
t.Errorf("ChunkBytes(%s) returned %d chunks, expected %d", input, len(chunks), len(expectedChunks)) | ||
} | ||
|
||
if len(meta) != len(expectedMeta) { | ||
t.Errorf("ChunkBytes(%s) returned %d metadata chunks, expected %d", input, len(meta), len(expectedMeta)) | ||
} | ||
// Call the function | ||
resultChan, _ := ChunkBytes(input) | ||
result := <-resultChan | ||
|
||
for i, chunk := range chunks { | ||
if chunk.Hash != expectedChunks[i].Hash { | ||
t.Errorf("ChunkBytes(%s)[%d].Hash = %x, expected %x", input, i, chunk.Hash, expectedChunks[i].Hash) | ||
} | ||
if string(chunk.Data) != string(expectedChunks[i].Data) { | ||
t.Errorf("ChunkBytes(%s)[%d].Data = %s, expected %s", input, i, chunk.Data, expectedChunks[i].Data) | ||
} | ||
// Check the result | ||
if result.ChunkNumber != expectedChunk.ChunkNumber { | ||
t.Errorf("Expected chunk number %d, got %d", expectedChunk.ChunkNumber, result.ChunkNumber) | ||
} | ||
|
||
for i, metaChunk := range meta { | ||
if metaChunk.Hash != expectedMeta[i].Hash { | ||
t.Errorf("ChunkBytes(%s) Metadata[%d].Hash = %x, expected %x", input, i, metaChunk.Hash, expectedMeta[i].Hash) | ||
} | ||
if metaChunk.DataLength != expectedMeta[i].DataLength { | ||
t.Errorf("ChunkBytes(%s) Metadata[%d].DataLength = %d, expected %d", input, i, metaChunk.DataLength, expectedMeta[i].DataLength) | ||
} | ||
if string(result.Data) != string(expectedChunk.Data) { | ||
t.Errorf("Expected data %s, got %s", string(expectedChunk.Data), string(result.Data)) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package messanger | ||
|
||
import ( | ||
"crypto" | ||
|
||
"github.com/i5heu/ouroboros-db/pkg/types" | ||
) | ||
|
||
type Identity struct { | ||
Hash types.Hash | ||
PublicKey *crypto.PublicKey | ||
RootSignature1 []byte // ed25519 | ||
RootSignature2 []byte // dilithium/mode5 - post quantum | ||
} | ||
|
||
type RootCertificate struct { | ||
RootPublicKey *crypto.PublicKey | ||
} | ||
|
||
type selfIdentity struct { | ||
privatekey *crypto.PrivateKey | ||
} | ||
|
||
type Message struct { | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package messanger | ||
|
||
type MessangerService interface { | ||
Init() error | ||
SendMessage(message string) error | ||
SendMessageToPeer(peer string, message string) error | ||
DistributeMessage(message string, numberOfSuccessors int) error | ||
GetAllPeers() ([]string, error) | ||
MessageHandler(handler func(message string) error) | ||
AddPeer(peer string) error | ||
Close() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.