CS计算机代考程序代写 chain distributed system data structure junit algorithm Java Hive Due: 19 March 2019(Tuesday Week 4) by 11:59 PM
Due: 19 March 2019(Tuesday Week 4) by 11:59 PM
COMP3221 Assignment 1: CS Blockchain
The goal of this project is to implement a Client-Server (CS) Blockchain application in Java which could be able to store messages and detect tampering.
1 Submission Details
The assignment comprises 3 tasks, each can be submitted separately. The final version of your assignment should be submitted electronically via PASTA by 11:59PM on the Tuesday of Week 4 (Hard Deadline). The project is an individual project, and each student has to submit his/her own version.
1.1 Program structure
For task 1, three java files must be submitted. It is recommended to submit by 11:59 PM on the Friday of Week 2 (Soft Deadline).
• A Blockchain.java file. • A Block.java file.
• A Transaction.java file.
For task 2, four java files must be submitted. It is recommended to submit by 11:59 PM on the Sunday of Week 2 (Soft Deadline).
• A Blockchain.java file.
• A Block.java file.
• A Transaction.java file.
• A BlockchainServer.java file.
For task 3, five java files must be submitted. It is recommended to submit by 11:59 PM on the Sunday of Week 3 (Soft Deadline).
• A Blockchain.java file. • A Block.java file.
1
• A Transaction.java file.
• A BlockchainServer.java file. • A BlockchainClient.java file.
All classes will be stored in the same default package (no package header in java files), and all files should be located in the same src folder with no subfolders. All present .java files should be correct and do not forget to remove any dummy files that do not count as source files (E.g. junit test cases, class files). Please zip the src folder and submit the resulting archive src.zip by the deadline given above. The program should compile with Java 8. No optional packages that are not part of the default Java 8 JDK can be used.
1.2 Submission system
PASTA will be used to assess that your program correctly implements the Client-Server Blockchain protocol. The archive src.zip should be submitted at https://pastpd01191.srv. sydney.edu.au/PASTA. To access this website, you will have to be connected to the net- work of the University of Sydney (physically on campus or through VPN).
PASTA stands for “Programming Assessment Submission and Testing Application” and is a web-based application that automates the compilation, execution and testing of your pro- gram. When you submit your src.zip archive in PASTA, the system enqueues your submis- sion in the shared queue of all assignments to be tested. It may take more time close to the deadline as many students will try to submit at the same time.
1.3 Academic Honesty / Plagiarism
By uploading your submission to PASTA you implicitly agree to abide by the University policies regarding academic honesty, and in particular that all the work is original and not plagiarised from the work of others. If you believe that part of your submission is not your work you must bring this to the attention of your tutor or lecturer immediately. See the policy slides released in Week 1 for further details.
In assessing a piece of submitted work, the School of IT may reproduce it entirely, may provide a copy to another member of faculty, and/or communicate a copy of this assignment to a plagiarism checking service or in-house computer program. A copy of the assignment may be maintained by the service or the School of IT for the purpose of future plagiarism checking.
2 Marking
This assignment is worth 10% of your final grade for this unit of study.
The first category of tasks, called Blockchain: Data Structure, assesses the quality of the message being stored in the block chain. If you could pass all tests, 4 marks are given.
COMP3221 Client-Server Blockchain
Distributed Systems Page 2
• Maximum 1 mark for rejecting invalid transactions.
• Maximum 1 mark for storing transaction into pool properly.
• Maximum 2 mark for committing transactions from pool to blockchain correctly.
The second category, called Blockchain: Server, assesses the behaviour of the server with respect to protocol requirements. If you could pass all tests, 3 marks are given.
• Maximum 1 mark for server listening to connections continuously.
• Maximum 1 mark for server replying to add transaction request correctly. • Maximum 1 mark for server replying to print blockchain request correctly.
The third category, called Blockchain: Client, assesses the behaviour of the client with respect to protocol requirements. If you could pass all tests, 3 marks are given.
• Maximum 1 mark for client connecting to the server properly.
• Maximum 1 mark for client forwarding requests to the server correctly. • Maximum 1 mark for client printing replies correctly.
Please make sure previous tasks are implemented correctly, before moving to next task. You may face cascading failures due to improper implementation of previous tasks.
2.1 Feedback
PASTA provides feedback about each individual submission, one at a time. It will output a list of tests and outcomes indicating whether your program passed each visible test successfully or failed. The feedback provided is indicative, intentionally high-level and will not precisely identify the nature of any bug of your program. Please write your personal test cases and thoroughly test all your code before submission.
3 Functionalities of a Client-Server Blockchain
The goal of this project is to implement a Client-Server (CS) Blockchain application. While the original blockchain operates in a distributed and P2P mode, your current CS Blockchain program will only require one client and one server running at the same time. The following tasks indicate the features that should be implemented, one solution for each task is expected to be submitted.
COMP3221 Client-Server Blockchain
Distributed Systems Page 3
Task 1 Blockchain: Data Structure
In task 1, you are required to build the Blockchain’s core data structure, which is a linked list of blocks of transactions. If you would like to have a better view of what we are trying to build, please have a look at Assignment 0.
Transaction. A transaction is defined as the container to store a single message (sender + content).
• Message sender, e.g., test0001
• Message content, e.g., welcome to comp2121!
You should perform some checks before you consider a message as a valid transaction. The message sender must present and should match a unikey-like form (regex: [a-z]{4}[0-9]{4}). The message content cannot have more than 70 English characters or contain a ‘|’ character. (| is used as delimiter later). If a transaction violates those rules, it should be considered as an invalid transaction.
Please use the skeleton code below to implement your Transaction class.
1 public class Transaction {
2 private String sender;
3 private String content;
4
5 // getters and setters
6 public void setSender(String sender) { this.sender = sender; }
7 public void setContent(String content) { this.content = content; }
8 public String getSender() { return sender; }
9 public String getContent() { return content; }
10
11 public String toString() {
12 return String.format(“|%s|%70s|
”, sender, content);
13 }
14
15 // implement helper functions here if you need any
16 }
Block. A block contains a list of transactions and a hash value of the previous block as the pointer:
• a list of transactions contains the messages;
• a hash pointer stores the hash value of the previous block.
The important thing here is to calculate the hash precisely. The hash function is SHA- 256. The first thing gets hashed is the previous block’s hash value using dos.write() method, then each transaction in the list gets hashed using the dos.writeUTF() method. writeUTF() method expects string as input. Therefore, you should convert each transaction to tx|
COMP3221 Client-Server Blockchain
Distributed Systems Page 4
1 H = SHA-256(H,tx1,tx2,tx3)
Please use the skeleton code below to implement your Block class.
1 public class Block { 2
3 private Block previousBlock;
4 private byte[] previousHash;
5 private ArrayList
6
7 public Block() { transactions = new ArrayList<>(); } 8
9 // getters and setters
10 public Block getPreviousBlock() { return previousBlock; }
11 public byte[] getPreviousHash() { return previousHash; }
12 public ArrayList
13 public void setPreviousBlock(Block previousBlock) { this.previousBlock = previousBlock; }
14 public void setPreviousHash(byte[] previousHash) { this.previousHash = previousHash; }
15 public void setTransactions(ArrayList
16 this.transactions = transactions;
17 }
18
19 public String toString() {
20 String cutOffRule = new String(new char[81]).replace(“