diff --git a/SwiftChain/Models/Node.swift b/SwiftChain/Models/Node.swift index a8759ca..88de9cb 100644 --- a/SwiftChain/Models/Node.swift +++ b/SwiftChain/Models/Node.swift @@ -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) {