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