root / src / protocols / Delete.java
History | View | Annotate | Download (1.39 KB)
1 |
package protocols; |
---|---|
2 |
|
3 |
import chord.ChordManager; |
4 |
import chord.ConnectionInfo; |
5 |
import files.FileHandler; |
6 |
import messages.*; |
7 |
import peer.Peer; |
8 |
|
9 |
import java.io.IOException; |
10 |
import java.math.BigInteger; |
11 |
import java.net.InetAddress; |
12 |
import java.net.UnknownHostException; |
13 |
import java.nio.file.Files; |
14 |
import java.nio.file.Paths; |
15 |
import java.security.NoSuchAlgorithmException; |
16 |
import java.util.concurrent.ExecutionException; |
17 |
|
18 |
public class Delete implements Runnable{ |
19 |
private BigInteger hashfile; |
20 |
|
21 |
public Delete(String filename) { |
22 |
|
23 |
try {
|
24 |
String [] params = new String[] {filename, FileHandler.getFileSize(filename)}; |
25 |
this.hashfile = ChordManager.encrypt(params);
|
26 |
} catch (Exception e) { |
27 |
e.printStackTrace(); |
28 |
} |
29 |
|
30 |
} |
31 |
|
32 |
@Override
|
33 |
public void run() { |
34 |
if(FileHandler.checkFileExists("./peerDisk/peer" + Peer.getPeerAccessPoint() + "-" + ChordManager.peerHash + "/backup/" + hashfile)){ |
35 |
try {
|
36 |
Files.deleteIfExists(Paths.get("./peerDisk/peer" + Peer.getPeerAccessPoint() + "-" + ChordManager.peerHash + "/backup/" + hashfile)); |
37 |
} catch (IOException e) { |
38 |
e.printStackTrace(); |
39 |
} |
40 |
} |
41 |
|
42 |
MessageForwarder.sendMessage(new DeleteMessage(hashfile,ChordManager.peerHash,ChordManager.getFingerTable().get(0).getIp(),ChordManager.getFingerTable().get(0).getPort())); |
43 |
} |
44 |
} |