-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPeer.java
More file actions
97 lines (72 loc) · 3.6 KB
/
Peer.java
File metadata and controls
97 lines (72 loc) · 3.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
package unimelb.bitbox;
import java.io.IOException;
import java.security.NoSuchAlgorithmException;
import java.util.logging.Logger;
import unimelb.bitbox.util.Configuration;
//New added:
import unimelb.bitbox.util.FileSystemManager.FileSystemEvent;
import unimelb.bitbox.util.HostPort;
import java.util.ArrayList;
import java.lang.InterruptedException;
public class Peer {
private static Logger log = Logger.getLogger(Peer.class.getName());
public static void main( String[] args ) throws IOException, NumberFormatException, NoSuchAlgorithmException {
System.setProperty("java.util.logging.SimpleFormatter.format",
"[%1$tc] %2$s %4$s: %5$s%n");
log.info("BitBox Peer starting...");
Configuration.getConfiguration();
//new ServerMain();
ServerMain fileServer = new ServerMain();
//implemententation begins here:
//locol peer info
String hostLocal = Configuration.getConfigurationValue("advertisedName");
int portLocal = Integer.parseInt(Configuration.getConfigurationValue("port"));
HostPort peerLocal = new HostPort(hostLocal, portLocal);
log.info("BitBox Peer Host Port Info "+peerLocal.toString());
//default outgoing connecting remote peers' info
String[] peers = Configuration.getConfigurationValue("peers").split(",");
ArrayList<HostPort> peersRemote = new ArrayList<HostPort>();
for(String peer: peers) {
peersRemote.add(new HostPort(peer));
}
int maxInCon = Integer.parseInt(Configuration.getConfigurationValue("maximumIncommingConnections"));
long maxBlockSize = Long.parseLong(Configuration.getConfigurationValue("blockSize"));
ServerMasterThread server = new ServerMasterThread(peerLocal, maxInCon, fileServer, maxBlockSize);
server.start();
ClientMasterThread client = new ClientMasterThread(peerLocal, peersRemote, fileServer, maxBlockSize);
client.start();
// Periodic Synchronization
// General synchronization with all neighboring peers every syncInterval seconds.
// Appends events generateSyncEvents() to each peer interface's buffer.
int sInterval = Integer.parseInt(Configuration.getConfigurationValue("syncInterval"));
int msInterval = 1000 * sInterval;
while(true) {
try {
Thread.sleep(msInterval);
}
catch(InterruptedException e) {
System.out.println(e.getMessage());
}
//TBD
//Dynamic buffer injection issue:
//Is it stable enough in complicated/critical operation sequences?
//to all in con peers
for(int i=0; i<fileServer.inConPeerList.size(); i++) {
TransmitterThread tx = fileServer.inConPeerDic.get(fileServer.inConPeerList.get(i)).transmitter;
if(tx!=null) {
ArrayList<FileSystemEvent> syncEventList = fileServer.fileSystemManager.generateSyncEvents();
tx.fileEventList.addAll(syncEventList);
}
}
//to all out con peers
for(int i=0; i<fileServer.outConPeerList.size(); i++) {
TransmitterThread tx = fileServer.outConPeerDic.get(fileServer.outConPeerList.get(i)).transmitter;
if(tx!=null) {
ArrayList<FileSystemEvent> syncEventList = fileServer.fileSystemManager.generateSyncEvents();
tx.fileEventList.addAll(syncEventList);
}
}
log.info("BitBox Peer Periodic Synchronization...");
}
}
}