✨ Launch 2 nodes
This commit is contained in:
@@ -11,7 +11,7 @@ import Network
|
||||
public class Node {
|
||||
// Network properties
|
||||
private var peers: [NWConnection] = []
|
||||
private let port: NWEndpoint.Port = 8333
|
||||
private var port: NWEndpoint.Port
|
||||
private var listener: NWListener?
|
||||
private let queue = DispatchQueue(label: "com.blockchain.node")
|
||||
|
||||
@@ -21,7 +21,8 @@ public class Node {
|
||||
private var pendingTransactions: [Transaction] = []
|
||||
private let maxTransactionsPerBlock: Int = 10
|
||||
|
||||
public init() {
|
||||
public init(port: NWEndpoint.Port = 8333) {
|
||||
self.port = port
|
||||
self.accountManager = AccountManager()
|
||||
self.blockchain = Blockchain()
|
||||
setupListener()
|
||||
@@ -135,8 +136,9 @@ public class Node {
|
||||
}
|
||||
|
||||
// Connexion à un pair
|
||||
public func connectToPeer(host: String) {
|
||||
let endpoint = NWEndpoint.hostPort(host: NWEndpoint.Host(host), port: port)
|
||||
public func connectToPeer(host: String, port: NWEndpoint.Port? = nil) {
|
||||
let peerPort = port ?? self.port
|
||||
let endpoint = NWEndpoint.hostPort(host: NWEndpoint.Host(host), port: peerPort)
|
||||
let connection = NWConnection(to: endpoint, using: .tcp)
|
||||
|
||||
connection.stateUpdateHandler = { [weak self] state in
|
||||
|
||||
Reference in New Issue
Block a user