From fa8c75d25f20447184f9e6dd9e881268d57c1618 Mon Sep 17 00:00:00 2001 From: Victor Bodinaud Date: Sat, 30 Nov 2024 11:57:05 +0100 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20Fix=20blockchain=20sync?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- SwiftChain/Models/Node.swift | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) 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) {