🐛 Fix blockchain sync
This commit is contained in:
@@ -72,10 +72,12 @@ class Node {
|
|||||||
print("Connected to peer: \(host)")
|
print("Connected to peer: \(host)")
|
||||||
self?.peers.append(connection)
|
self?.peers.append(connection)
|
||||||
self?.startReceiving(connection)
|
self?.startReceiving(connection)
|
||||||
|
// Demander la blockchain au pair
|
||||||
|
self?.requestBlockchain(from: connection)
|
||||||
case .failed(let error):
|
case .failed(let error):
|
||||||
print("Connection failed: \(error)")
|
print("Connection failed: \(error)")
|
||||||
case .cancelled:
|
case .cancelled:
|
||||||
print("Connection cancelled to: \(host)")
|
print("Connection cancelled: \(host)")
|
||||||
default:
|
default:
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
@@ -180,14 +182,14 @@ class Node {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Quand un pair se connecte, demander sa blockchain
|
|
||||||
private func handleNewConnection(_ connection: NWConnection) {
|
private func handleNewConnection(_ connection: NWConnection) {
|
||||||
connection.start(queue: queue)
|
connection.start(queue: queue)
|
||||||
peers.append(connection)
|
peers.append(connection)
|
||||||
startReceiving(connection)
|
startReceiving(connection)
|
||||||
|
print("New connection established with: \(connection.endpoint)")
|
||||||
|
|
||||||
// Demander la blockchain
|
// Envoyer notre blockchain au nouveau pair
|
||||||
requestBlockchain(from: connection)
|
sendBlockchain(to: connection)
|
||||||
}
|
}
|
||||||
|
|
||||||
private func requestBlockchain(from peer: NWConnection) {
|
private func requestBlockchain(from peer: NWConnection) {
|
||||||
|
|||||||
Reference in New Issue
Block a user