-
Notifications
You must be signed in to change notification settings - Fork 0
/
calabu.js
29 lines (23 loc) · 935 Bytes
/
calabu.js
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
import net from 'net'
import { Peer, ConnectedPeer, PeerManager } from './peers.js'
import { BlockchainManager } from './blockchain.js'
//import { MiningManager } from './miningManager.js'
const blockchainManager = new BlockchainManager()
const peerManager = new PeerManager({ blockchainManager })
//const miningManager = new MiningManager({ blockchainManager, peerManager })
//miningManager.minerSetUp()
//new Promise (async () => miningManager.mine())
await peerManager.loadKnownPeers()
//console.log(peerManager.knownPeers)
const server = net.createServer(socket => {
new ConnectedPeer({ socket, peerManager })
})
server.listen(18018, '0.0.0.0')
Object.values(peerManager.knownPeers).forEach(peer => {
peerManager.connectToPeer(peer)
})
if (Object.entries(peerManager.knownPeers).length === 0) {
const startingPeer = new Peer()
startingPeer.address = '149.28.220.241:18018'
peerManager.connectToPeer(startingPeer)
}