🐛 Fix blockchain sync

This commit is contained in:
Victor Bodinaud
2024-11-30 11:57:05 +01:00
parent 6d0777930d
commit fa8c75d25f

View File

@@ -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) {