- Visual_Project_Description
- Project Overview
- Project Summary
- Project Details
- Key Methods and Responsibilities
This collaborative project provides hands-on coding experience with multithreading and Merkle roots. It serves as an opportunity to reinforce essential skills related to SHA256 Hashing, Merkle trees, and Multithreading.
The project introduces a console application that combines multithreading and Merkle roots in a simple game. Here's an overview of how the game works:
-
User Input: The user starts by entering the Merkle root of four words they intend to provide to the Merkle thread. The Merkle root can be manually calculated using a provided method or an online tool.
-
Multithreading: The application employs multithreading, allowing the user to submit strings on the main thread. Each submitted string is grabbed by either a Merkle or Rogue background thread, depending on the timing of the user.
-
Merkle Thread: If the Merkle thread successfully gathers four words, it creates a Merkle tree and generates a Merkle root string. If this root matches the initially entered Merkle root, the user wins the game. Otherwise, they lose.
-
Rogue Thread: The Rogue thread is responsible for accumulating "strikes" every time it grabs a word. If the user accumulates three strikes, they lose the game.
-
Random Delays: Both background threads introduce an element of randomness by sleeping for a random number of seconds. This challenge requires the user to time their submissions correctly to ensure the Merkle thread grabs the words.
-
Monitor Thread: A third Monitor thread in the background constantly checks the progress and terminates the application once the user either wins or loses.
- Console Application: This project is designed as a console application.
- User Input: To facilitate user input, it's recommended to use JOptionPane rather than System.in, as the latter can be problematic due to interactions with the threads.
- Classes: The project consists of several classes, including
MerkleManager_Test
,MerkleManager
,MerkleThread
,RogueThread
,MonitorThread
,MerkleNode
, andUtil
.
-
MerkleManager_Test: Contains the main method, instantiates an instance of
MerkleManager
, and calls themanage
function. -
MerkleManager: Manages the game and contains instance variables for user input and game state. It starts three separate threads:
MerkleThread
,RogueThread
, andMonitorThread
. It also handles user input for words. -
MerkleThread: Implements Runnable, collects words, and calculates the Merkle root when enough words are collected.
-
RogueThread: Implements Runnable, simulates a rogue thread that accumulates strikes when grabbing words.
-
MonitorThread: Implements Runnable, constantly monitors game progress and terminates the app when the user either wins or loses.
-
MerkleNode: Represents nodes in the Merkle tree, with instance variables for hash, left, and right nodes.
-
Util: Contains utility methods shared among classes, such as calculating the Merkle root, generating hashes, prompting the user, and introducing random delays in threads.