- Building a P2P file-sharing software like BitTorrent.
- About 800 line for midpoint check on March 10
- Final Submission 4/20
Please follow the cmd below, and use the cmd in script if needed any adjustment.
Before running the script, please put the configurations and the default file directories in the path of
- ~/final_project/demo/
If the debug in peerProcess is true, the program will it reads PeerInfo_local.cfg in the config path.
In this mode, all peers will build locally with different port.
-
compile
sh ~/final_project/compileProcess.sh
The java class will be established at ~/final_project/project/
-
start process
sh ~/final_project/test/startPeers.sh
Wait till all nodes, showing
-
kill process if needed
sh ~/final_project/test/killAllPeer.sh
-
check the files result by using diff command or use the script below
sh ~/final_project/test/checkFileDiff.sh
It should not show any output which means the file are all the same.
When you login into the server on csie, you could use these command to start the peer manually.
Be aware that the configurations to remain in
- ~/final_project/{target_file}/
- {target_file} = demo in default, change it if necessary.
-
Compile the project - use script or javac directly
sh ~/final_project/compileProcess.sh
javac -Xlint -d [target_file] src/PeerProcess.java src/peer/* src/utils/*
-
Compile remote deployer
sh ~/final_project/demo/compileDeployer.sh
-
Start the deployment
java ~/final_project/demo/StartRemotePeer
-
Kill process on ubuntu if needed
ps aux | grep java | grep PeerProces | awk '{print $2}' | xargs /bin/kill
The log is stored in ~/final_project/{target_file}/log, with specific file names. The logs are seperate into debug level and info level, which the former one contains every level logs, and the latter one only contains info level (logs request by project description).
- default {target_file} = demo, where we compiled the project
Here is a example, the file name is debug_log_peer_[1001]_[2021-04-13].log. With FINE and INFO level logs record in the file.
[2021-04-13 12:24:21] [FINE] [utils.LogHandler] Peer [1001] Peer [1001] receive Handshake success from [1008]
[2021-04-13 12:24:21] [FINE] [utils.LogHandler] Peer [1001] Peer [1001] check if [1008] is neighbor
[2021-04-13 12:24:21] [FINE] [utils.LogHandler] Peer [1001] (server thread) # 2 client is connected
[2021-04-13 12:24:21] [INFO] [utils.LogHandler] Peer [1001] (server) sending handshake message to peer [1008]
The logs are seperate into 3 files for each node.
-
error - with only [SEVERE] Level record inside
-
info - with only [INFO] Level record inside
-
Debug - with only [Debug] Level record inside
- PeerProcess (YiMing)
- Server (YiMing)
- Client (YiMing)
- HandShakeMsg (YiMing)
- ActualMsg (Jim)
- FileManager (Jim)
- LogHandler (YiMing)
Class ActualMsg categorize the type of the msg and serialize them into object.
a. noPayloadMsg
- end, choke, unchoke, interested and not interested
b. shortMsg
- have, request contains 4 bytes payload
- have
- payload = 4-byte piece index field.
- sender uses payload to inform receiver it's properties.
- request
- payload = 4-byte piece index field
- receiver request piece x from sender, which x represents by payload.
c. bitfieldMsg
- bitfield
- contains variable length bitfield
- every byte is 8 bit which represents 8 different pieces of file.
- For example, first byte = 3 --> 00000110. (pieces = blockIdx 0 ~ 7) Sender contains peices with blockIdx = 1 and 2.
d. pieceMsg
- piece
- payload consists of a 4-byte piece index field and the content of the piece.
Function Names | input | return | description |
---|---|---|---|
recv | InputStream in | byte type | tranform input stream |
Function Names | input | return | description |
---|---|---|---|
send | OutputStream out, byte type, int blockIdx | None | use for noPayloadMsg and shortMsg |
send | OutputStream out, byte type, byte[] bitfield | None | use for bitfieldMsg |
send | OutputStream out, byte type, int blockIdx, byte[] data | None | use for pieceMsg |
FileManager is a singleton, new it as the class's default variables. Then you are able to call it's functions shown in the function list.
Function Names | input | return | description |
---|---|---|---|
insertBitfield | int peerId, byte[] b, int len | None | record what peices does others have |
updateHave | String peerId, int blockIdx | None | update others' have peices |
buildOwnBitfield | int remainderBits | None | Build own bit field record in memory |
updateOwnBitfield | int blockIdx | None | update own bit field |
getOwnBitfield | None | get own bit field | |
pickInterestedFileBlock | String peerId | int blockIdx | use for request msg, random pick a interested block which the other peer (peerId) have |
isInterested | String peerId | boolean | interested in target Peer's blocks |
Function Names | input | return | description |
---|---|---|---|
read | int blockIdx, byte[] b, int len | int byteRead | read the block, return the length of bytes which just be read |
write | int blockIdx, byte[] b, int len | int byteWrite | write the block, return the lenght of bytes which just be written |
close | None | close the file |
Function Names | input | return | description |
---|---|---|---|
isComplete | None | is peer finishing download the file | |
printByteArray | byte[] bytes | None | print bytes to string |
-
LogHandler is a singleton, new it as the class's default variables. Then you are able to call it's functions shown in the function list.
LogHandler logging = new LogHandler(); ... logging.writeLog("This is a test log");
-
Please naming the functions with this rule
log{Actions}
Function Names | input | return | description |
---|---|---|---|
logStartConn | Peer client, Peer targetHost | None | log start connection |
logChangePrefersPeers | None | None | log change of preferred neighbors |
logChangeUnchokedPeer | None | None | change of unchoke neighbors |
logUnchoking | Peer sender | None | log unchoke targe peer |
logChoking | Peer sender | None | log choke target peer |
logReceiveHaveMsg | Peer sender | None | log server send have msg |
logReceiveInterestMsg | Peer sender | None | log cleint send interest msg |
logReceiveNotInterestMsg | Peer sender | None | log cleint send not interest msg |
logDownload | Peer sender, int blockIdx, int numBlocks | None | log download block |
logCompleteFile | None | None | log complete downloading the file |
logCloseConn | Peer targetPeer | None | log close connection |
logSendHandShakeMsg | String targetPeerID, String threadType | None | log send hand shake msg |
Function Names | input | return | description |
---|---|---|---|
logConnError | (Peer client, Peer targetHost) | None | Connection Error |