Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file modified DataStructures/DataStructures.a
Binary file not shown.
81 changes: 54 additions & 27 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,17 @@
# Eric Meehan


###############################################################################
# COMPILER
###############################################################################

CC=gcc
CFLAGS=-Wall -pedantic
AR=ar
ARFLAGS=rcs
RM=rm -f


###############################################################################
# MARK: ALL
###############################################################################
Expand All @@ -14,15 +25,13 @@
all: Main DataStructures Networking Systems



###############################################################################
# MARK: MAIN
###############################################################################

# 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 Files.o

$(AR) $(ARFLAGS) 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 All @@ -31,81 +40,99 @@ Main: DataStructuresSub NetworkingSub SystemsSub

# Creates the data structures library
DataStructures: DataStructuresSub
ar rcs DataStructures/DataStructures.a Node.o LinkedList.o Queue.o BinarySearchTree.o Entry.o Dictionary.o
$(AR) $(ARFLAGS) DataStructures/DataStructures.a Node.o LinkedList.o Queue.o BinarySearchTree.o Entry.o Dictionary.o

# Sub components of the data structures library
DataStructuresSub: Node LinkedList Queue BinarySearchTree Entry Dictionary

Node:
gcc -c DataStructures/Common/Node.c
$(CC) $(CFLAGS) -c DataStructures/Common/Node.c

LinkedList:
gcc -c DataStructures/Lists/LinkedList.c
$(CC) $(CFLAGS) -c DataStructures/Lists/LinkedList.c

Queue:
gcc -c DataStructures/Lists/Queue.c
$(CC) $(CFLAGS) -c DataStructures/Lists/Queue.c

BinarySearchTree:
gcc -c DataStructures/Trees/BinarySearchTree.c
$(CC) $(CFLAGS) -c DataStructures/Trees/BinarySearchTree.c

Entry:
gcc -c DataStructures/Dictionary/Entry.c
$(CC) $(CFLAGS) -c DataStructures/Dictionary/Entry.c

Dictionary:
gcc -c DataStructures/Dictionary/Dictionary.c


$(CC) $(CFLAGS) -c DataStructures/Dictionary/Dictionary.c


###############################################################################
# MARK: NETWORKING
###############################################################################

# Creates the networking library
Networking: NetworkingSub
ar rcs Networking/Networking.a Server.o HTTPRequest.o HTTPServer.o Node.o LinkedList.o Queue.o BinarySearchTree.o Entry.o Client.o Dictionary.o ThreadPool.o PeerToPeer.o
$(AR) $(ARFLAGS) Networking/Networking.a Server.o HTTPRequest.o HTTPServer.o Node.o LinkedList.o Queue.o BinarySearchTree.o Entry.o Client.o Dictionary.o ThreadPool.o PeerToPeer.o

# Sub components of the networking library
NetworkingSub: DataStructuresSub SystemsSub Server Client HTTPRequest HTTPServer PeerToPeer

Server:
gcc -c Networking/Nodes/Server.c
$(CC) $(CFLAGS) -c Networking/Nodes/Server.c

Client:
gcc -c Networking/Nodes/Client.c
$(CC) $(CFLAGS) -c Networking/Nodes/Client.c

PeerToPeer:
gcc -c Networking/Nodes/PeerToPeer.c
$(CC) $(CFLAGS) -c Networking/Nodes/PeerToPeer.c

HTTPServer:
gcc -c Networking/Nodes/HTTPServer.c
$(CC) $(CFLAGS) -c Networking/Nodes/HTTPServer.c

HTTPRequest:
gcc -c Networking/Protocols/HTTPRequest.c


$(CC) $(CFLAGS) -c Networking/Protocols/HTTPRequest.c


###############################################################################
# MARK: Systems
###############################################################################

# Creates the systems library
Systems: SystemsSub
ar rcs Systems/System.a ThreadPool.o Files.o
$(AR) $(ARFLAGS) Systems/System.a ThreadPool.o Files.o

# Sub components of the systems library
SystemsSub: ThreadPool Files

ThreadPool:
gcc -c Systems/ThreadPool.c
$(CC) $(CFLAGS) -c Systems/ThreadPool.c

Files:
gcc -c Systems/Files.c
$(CC) $(CFLAGS) -c Systems/Files.c


###############################################################################
# MARK: TEST
###############################################################################

test: test_p2p test_linked_list test_queue

test_p2p: test/main.c
$(CC) $(CFLAGS) -o test_p2p test/main.c libeom.a

test_linked_list: test/test_linked_list.c
$(CC) $(CFLAGS) -o test_linked_list test/test_linked_list.c libeom.a

test_queue: test/test_queue.c
$(CC) $(CFLAGS) -o test_queue test/test_queue.c libeom.a


###############################################################################
# MARK: CLEAN
###############################################################################

# Remove all .o files
# Remove all .o files and test files
clean:
rm *.o
$(RM) *.o
$(RM) test_p2p
$(RM) test_linked_list
$(RM) test_queue

Binary file modified Networking/Networking.a
Binary file not shown.
8 changes: 4 additions & 4 deletions Networking/Nodes/Client.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
In general, client objects are used to send requests to server APIs.
*/


#include "Client.h"

#include <stdlib.h>
Expand All @@ -27,7 +26,7 @@

// MARK: FUNCTION PROTOTYPES

char * request(struct Client *client, char *server_ip, void *request, unsigned long size);
char *request(struct Client *client, char *server_ip, void *request, unsigned long size);

// MARK: CONSTRUCTORS

Expand All @@ -36,6 +35,7 @@ struct Client client_constructor(int domain, int service, int protocol, int port
// Instantiate a client object.
struct Client client;
client.domain = domain;
client.service = service;
client.port = port;
client.interface = interface;
// Establish a socket connection.
Expand All @@ -47,7 +47,7 @@ struct Client client_constructor(int domain, int service, int protocol, int port

// MARK: PRIVATE MEMBER METHODS

char * request(struct Client *client, char *server_ip, void *request, unsigned long size)
char *request(struct Client *client, char *server_ip, void *request, unsigned long size)
{
// Create an address struct for the server.
struct sockaddr_in server_address;
Expand All @@ -57,7 +57,7 @@ char * request(struct Client *client, char *server_ip, void *request, unsigned l
server_address.sin_addr.s_addr = (int)client->interface;
// Make the connection.
inet_pton(client->domain, server_ip, &server_address.sin_addr);
connect(client->socket, (struct sockaddr*)&server_address, sizeof(server_address));
connect(client->socket, (struct sockaddr *)&server_address, sizeof(server_address));
// Send the request;
send(client->socket, request, size, 0);
// Read the response.
Expand Down
20 changes: 20 additions & 0 deletions Networking/Protocols/BlockHeaders.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#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 - 165
unsigned long size; // 156 - 164
};

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

#endif /* BlockHeaders_h */
7 changes: 1 addition & 6 deletions Networking/Protocols/HTTPRequest.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,16 +29,13 @@
#include <string.h>
#include <stdlib.h>


// MARK: PRIVATE MEMBER METHODS

// Functions for extracting the constituent elements from a request string.
void extract_request_line_fields(struct HTTPRequest *request, char *request_line);
void extract_header_fields(struct HTTPRequest *request, char *header_fields);
void extract_body(struct HTTPRequest *request, char *body);



// MARK: CONSTRUCTORS

// Creates an initialized instance of an HTTPRequest using a properly formatted string.
Expand Down Expand Up @@ -67,7 +64,7 @@ struct HTTPRequest http_request_constructor(char *request_string)
extract_body(&request, body);
// Return the final product.
return request;
};
}

// Destroy a request by freeing the memory in each constituent dictionary.
void http_request_destructor(struct HTTPRequest *request)
Expand All @@ -77,8 +74,6 @@ void http_request_destructor(struct HTTPRequest *request)
dictionary_destructor(&request->body);
}



// MARK: PRIVATE MEMBER METHODS

// Parses out the request line to retrieve the method, uri, and http version.
Expand Down
Binary file modified Systems/System.a
Binary file not shown.
Binary file modified libeom.a
Binary file not shown.
40 changes: 40 additions & 0 deletions test/test_linked_list.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
//
// test_linked_list.c
// hdelibc
//
// Created by Eric Meehan on 1/31/21.
//

#include "../libeom.h"

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

int main()
{
struct LinkedList list = linked_list_constructor();

for (int index = 0; index < 10; index++)
{
int *data = (int *)malloc(sizeof(int));
*data = index;
list.insert(&list, index, data, sizeof(int));
}

list.remove(&list, 3);
list.remove(&list, 7);

for (int index = 0; index < list.length; index++)
{
void *value = list.retrieve(&list, index);
if (value) // NULL denotes no node exists
{
printf("%d\n", *(int *)list.retrieve(&list, index));
}
}

// Should return NULL
list.retrieve(&list, 100);

linked_list_destructor(&list);
}
34 changes: 34 additions & 0 deletions test/test_queue.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
//
// test_queue.c
// hdelibc
//
// Created by Eric Meehan on 2/1/21.
//

#include "../libeom.h"

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

int main()
{
struct Queue queue = queue_constructor();

for (int i = 0; i < 10; i++)
{
int *data = (int *)malloc(sizeof(int));
*data = i;
queue.push(&queue, data, sizeof(data));
}

queue.pop(&queue);
queue.pop(&queue);

while (queue.list.length)
{
printf("%d\n", *(int *)queue.peek(&queue));
queue.pop(&queue);
}

queue_destructor(&queue);
}