Skip to content

Commit

Permalink
Added BlockHeader and Block objects
Browse files Browse the repository at this point in the history
  • Loading branch information
Eric Meehan committed Apr 10, 2021
1 parent c8988d5 commit 1f6bc3e
Show file tree
Hide file tree
Showing 14 changed files with 263 additions and 89 deletions.
Binary file modified DataStructures/DataStructures.a
Binary file not shown.
9 changes: 5 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ all: Main DataStructures Networking Systems

# Creates just the top level static library
Main: DataStructuresSub NetworkingSub SystemsSub
ar rcs libeom.a Node.o LinkedList.o Queue.o BinarySearchTree.o Entry.o Dictionary.o Client.o Server.o HTTPServer.o HTTPRequest.o ThreadPool.o PeerToPeer.o
ar rcs libeom.a Node.o LinkedList.o Queue.o BinarySearchTree.o Entry.o Dictionary.o Client.o Server.o HTTPServer.o HTTPRequest.o ThreadPool.o PeerToPeer.o Files.o



Expand Down Expand Up @@ -90,15 +90,16 @@ HTTPRequest:

# Creates the systems library
Systems: SystemsSub
ar rcs Systems/System.a ThreadPool.o
ar rcs Systems/System.a ThreadPool.o Files.o

# Sub components of the systems library
SystemsSub: ThreadPool
SystemsSub: ThreadPool Files

ThreadPool:
gcc -c Systems/ThreadPool.c


Files:
gcc -c Systems/Files.c


###############################################################################
Expand Down
Binary file modified Networking/Networking.a
Binary file not shown.
15 changes: 15 additions & 0 deletions Networking/Protocols/BlockHeaders.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
//
// ==================================
// libeom
//
// an open source c library.
// ==================================
//
// BlockHeaders.c
//
// Eric Meehan
// 4/1/21
//
//

#include "BlockHeaders.h"
34 changes: 34 additions & 0 deletions Networking/Protocols/BlockHeaders.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
//
// ==================================
// libeom
//
// an open source c library.
// ==================================
//
// BlockHeaders.h
//
// Eric Meehan
// 4/1/21
//
//

#ifndef BlockHeaders_h
#define BlockHeaders_h

struct BlockHeaders // Bytes:
{
unsigned char previous[64]; // 0 - 63
unsigned long nonce; // 64 - 71

unsigned char by[64]; // 72 - 135
char timestamp[20]; // 136 - 155
unsigned long size; // 156 - 164
};

struct Block
{
struct BlockHeaders headers;
unsigned char data;
};

#endif /* BlockHeaders_h */
2 changes: 2 additions & 0 deletions Systems.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,6 @@

#include "Systems/ThreadPool.h"

#include "Systems/Files.h"

#endif /* System_h */
58 changes: 58 additions & 0 deletions Systems/Files.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
//
// ==================================
// libeom
//
// an open source c library.
// ==================================
//
// Files.c
//
// Eric Meehan
// 4/2/21
//
//

#include "Files.h"

#include <stdio.h>
#include <stdlib.h>

unsigned long get_file_size(char *path)
{
FILE *file = fopen(path, "r");
fseek(file, 0, SEEK_END);
unsigned long size = ftell(file);
fclose(file);
return size;
}

unsigned long get_file_size_internal(FILE *file)
{
fseek(file, 0, SEEK_END);
unsigned long size = ftell(file);
fseek(file, 0, SEEK_SET);
return size;
}

void write_file(char *path, void *data, unsigned long size)
{
FILE *file = fopen(path, "w");
fwrite(data, size, 1, file);
fclose(file);
}

void append_file(char *path, void *data, unsigned long size)
{
FILE *file = fopen(path, "a");
fwrite(data, size, 1, file);
fclose(file);
}

void * read_file(char *path)
{
FILE *file = fopen(path, "r");
unsigned long size = get_file_size_internal(file);
void *data = malloc(size);
fread(data, size, 1, file);
return data;
}
23 changes: 23 additions & 0 deletions Systems/Files.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
//
// ==================================
// libeom
//
// an open source c library.
// ==================================
//
// Files.h
//
// Eric Meehan
// 4/2/21
//
//

#ifndef Files_h
#define Files_h

unsigned long get_file_size(char *path);
void write_file(char *path, void *data, unsigned long size);
void append_file(char *path, void *data, unsigned long size);
void * read_file(char *path);

#endif /* Files_h */
Binary file modified Systems/System.a
Binary file not shown.
Binary file modified eom.a
Binary file not shown.
2 changes: 2 additions & 0 deletions libeom.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,6 @@

#include "Systems.h"



#endif /* libeom_h */
16 changes: 16 additions & 0 deletions libeom.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
/* Begin PBXBuildFile section */
0702102725E2E7FA00D60AD5 /* HTTPServer.h in Headers */ = {isa = PBXBuildFile; fileRef = 0702102525E2E7FA00D60AD5 /* HTTPServer.h */; };
0702102825E2E7FA00D60AD5 /* HTTPServer.c in Sources */ = {isa = PBXBuildFile; fileRef = 0702102625E2E7FA00D60AD5 /* HTTPServer.c */; };
0705734626173CDB00D9EE57 /* Files.h in Headers */ = {isa = PBXBuildFile; fileRef = 0705734426173CDB00D9EE57 /* Files.h */; };
0705734726173CDB00D9EE57 /* Files.c in Sources */ = {isa = PBXBuildFile; fileRef = 0705734526173CDB00D9EE57 /* Files.c */; };
070973D525CCF85800343E54 /* Node.c in Sources */ = {isa = PBXBuildFile; fileRef = 070973D425CCF85800343E54 /* Node.c */; };
070A830025D70F5F00E97DE2 /* Entry.h in Headers */ = {isa = PBXBuildFile; fileRef = 070A82FE25D70F5F00E97DE2 /* Entry.h */; };
070A830125D70F5F00E97DE2 /* Entry.c in Sources */ = {isa = PBXBuildFile; fileRef = 070A82FF25D70F5F00E97DE2 /* Entry.c */; };
Expand All @@ -18,6 +20,8 @@
070A831925D8316100E97DE2 /* libeom.h in Headers */ = {isa = PBXBuildFile; fileRef = 070A831725D8316100E97DE2 /* libeom.h */; };
070A831F25D8318B00E97DE2 /* Networking.h in Headers */ = {isa = PBXBuildFile; fileRef = 070A831D25D8318B00E97DE2 /* Networking.h */; };
070F6B1A25F2BDD100335EEE /* Cryptography.h in Headers */ = {isa = PBXBuildFile; fileRef = 070F6B1825F2BDD100335EEE /* Cryptography.h */; };
0722E083261615B20029A936 /* BlockHeaders.h in Headers */ = {isa = PBXBuildFile; fileRef = 0722E081261615B20029A936 /* BlockHeaders.h */; };
0722E084261615B20029A936 /* BlockHeaders.c in Sources */ = {isa = PBXBuildFile; fileRef = 0722E082261615B20029A936 /* BlockHeaders.c */; };
0734F71925F7D1730099F481 /* Client.h in Headers */ = {isa = PBXBuildFile; fileRef = 0734F71725F7D1730099F481 /* Client.h */; };
0734F71A25F7D1730099F481 /* Client.c in Sources */ = {isa = PBXBuildFile; fileRef = 0734F71825F7D1730099F481 /* Client.c */; };
0737A2F825D06F85009CCE74 /* Server.h in Headers */ = {isa = PBXBuildFile; fileRef = 0737A2F625D06F85009CCE74 /* Server.h */; };
Expand Down Expand Up @@ -57,6 +61,8 @@
/* Begin PBXFileReference section */
0702102525E2E7FA00D60AD5 /* HTTPServer.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = HTTPServer.h; sourceTree = "<group>"; };
0702102625E2E7FA00D60AD5 /* HTTPServer.c */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.c; path = HTTPServer.c; sourceTree = "<group>"; };
0705734426173CDB00D9EE57 /* Files.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = Files.h; sourceTree = "<group>"; };
0705734526173CDB00D9EE57 /* Files.c */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.c; path = Files.c; sourceTree = "<group>"; };
070973D425CCF85800343E54 /* Node.c */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.c; path = Node.c; sourceTree = "<group>"; };
070A82FE25D70F5F00E97DE2 /* Entry.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = Entry.h; sourceTree = "<group>"; };
070A82FF25D70F5F00E97DE2 /* Entry.c */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.c; path = Entry.c; sourceTree = "<group>"; };
Expand All @@ -69,6 +75,8 @@
070A832625D8337400E97DE2 /* README.md */ = {isa = PBXFileReference; lastKnownFileType = net.daringfireball.markdown; path = README.md; sourceTree = "<group>"; };
070A832725D8338200E97DE2 /* README.md */ = {isa = PBXFileReference; lastKnownFileType = net.daringfireball.markdown; path = README.md; sourceTree = "<group>"; };
070F6B1825F2BDD100335EEE /* Cryptography.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = Cryptography.h; sourceTree = "<group>"; };
0722E081261615B20029A936 /* BlockHeaders.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = BlockHeaders.h; sourceTree = "<group>"; };
0722E082261615B20029A936 /* BlockHeaders.c */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.c; path = BlockHeaders.c; sourceTree = "<group>"; };
0734F71725F7D1730099F481 /* Client.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = Client.h; sourceTree = "<group>"; };
0734F71825F7D1730099F481 /* Client.c */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.c; path = Client.c; sourceTree = "<group>"; };
0737A2DE25CE316E009CCE74 /* README.md */ = {isa = PBXFileReference; lastKnownFileType = net.daringfireball.markdown; path = README.md; sourceTree = "<group>"; };
Expand Down Expand Up @@ -145,6 +153,8 @@
children = (
07EEDA1E25D3244700078FED /* HTTPRequest.h */,
07EEDA1F25D3244700078FED /* HTTPRequest.c */,
0722E081261615B20029A936 /* BlockHeaders.h */,
0722E082261615B20029A936 /* BlockHeaders.c */,
);
path = Protocols;
sourceTree = "<group>";
Expand Down Expand Up @@ -208,6 +218,8 @@
0773445B25E9781C0063555F /* Systems */ = {
isa = PBXGroup;
children = (
0705734426173CDB00D9EE57 /* Files.h */,
0705734526173CDB00D9EE57 /* Files.c */,
0773445C25E9782F0063555F /* ThreadPool.h */,
0773445D25E9782F0063555F /* ThreadPool.c */,
);
Expand Down Expand Up @@ -276,6 +288,8 @@
070A830C25D7752400E97DE2 /* DataStructures.h in Headers */,
070A830025D70F5F00E97DE2 /* Entry.h in Headers */,
0702102725E2E7FA00D60AD5 /* HTTPServer.h in Headers */,
0722E083261615B20029A936 /* BlockHeaders.h in Headers */,
0705734626173CDB00D9EE57 /* Files.h in Headers */,
070A831F25D8318B00E97DE2 /* Networking.h in Headers */,
0737A2F825D06F85009CCE74 /* Server.h in Headers */,
0773445E25E9782F0063555F /* ThreadPool.h in Headers */,
Expand Down Expand Up @@ -378,11 +392,13 @@
0734F71A25F7D1730099F481 /* Client.c in Sources */,
070A830125D70F5F00E97DE2 /* Entry.c in Sources */,
07BF315A25CB344800A41C5D /* Queue.c in Sources */,
0705734726173CDB00D9EE57 /* Files.c in Sources */,
07EEDA2125D3244700078FED /* HTTPRequest.c in Sources */,
070973D525CCF85800343E54 /* Node.c in Sources */,
07BF312325C732C300A41C5D /* LinkedList.c in Sources */,
0768DF3425D5C5EF00410685 /* BinarySearchTree.c in Sources */,
076C3A3C25F16CB400DF3B58 /* ArbitrarilyPreciseInteger.c in Sources */,
0722E084261615B20029A936 /* BlockHeaders.c in Sources */,
07CE3A2D25FD2B9F00A0DC89 /* PeerToPeer.c in Sources */,
0737A2F925D06F85009CCE74 /* Server.c in Sources */,
0773445F25E9782F0063555F /* ThreadPool.c in Sources */,
Expand Down
Binary file not shown.
Loading

0 comments on commit 1f6bc3e

Please sign in to comment.