-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathP2P History
44 lines (39 loc) · 1.14 KB
/
P2P History
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
// const wrtc = require('wrtc');
// const Exchange = require('peer-exchange');
// const p2p = new Exchange(...);
// const net = require("net");
// const messageType = { ... };
// const { ... } = messageType;
// class PeerToPeer {
// constructor(karchain) { ... }
// startServer(port) { ... }
// discoverPeers() { ... }
// connectToPeer(host, port) { ... }
// closeConnection() { ... }
// broadcastLatest() { ... }
// broadcast(message) { ... }
// write(peer, message) { ... }
// initConnection(connection) { ... }
// initMessageHandler(connection) { ... }
// initErrorHandler(connection) { ... }
// handleMessage(peer, message) { ... }
handleReceivedLatestBar(message, peer) {
// if (latestBar.hash === receivedBar.previousHash) {
// ...
} else if (receivedBar.index > latestBar.index) {
this.write(peer, Messages.getKArchain());
} else {
// Do nothing.
}
}
handleReceivedKarchain(message) {
const receivedChain = message.data;
try {
this.karchain.replaceChain(receivedChain);
} catch(err) {
throw err;
}
}
// }
// module.exports = PeerToPeer;
// class Messages { ... }