/// <summary> /// Constructs a new <see cref="BootstrapperNode" />. /// </summary> public BootstrapperNode() { Application.Start(); if (_node != null) { return; } try { InitializeLock.Wait(); if (_node != null) { return; } Node node = new Node(); node.Initialize(); _node = node; _bootstrapper = this; if (_node != null && _node.IsInitialized) { Log.Info("Initialized successfully."); } else { Log.Error("Initialization failed."); } } catch (Exception ex) { Log.Error("Initialization failed."); if (ex is AddressAlreadyInUseException) { Log.Warn("A Kademlia.Bootstrapper is already running on this machine."); } else { Log.Error(ex); throw; } } finally { InitializeLock.Release(); } }
/// <summary> /// Force initializes the <see cref="Node" />. /// </summary> public void Initialize() { if (CheckIsInitialized) { return; } try { _initializeDisposeLock.EnterWriteLock(); if (CheckIsInitialized) { return; } if (!Started) { Start(); } if (_serviceHost == null) { _serviceHost = new NodeServiceHost(this); } if (!_serviceHost.IsInitialized) { _serviceHost.Initialize(); } if (!IsBootstrapper && !KnowsAboutBootstrapper) { INode node = this; foreach (IContact contact in BootstrapperNode.GetContacts()) { node.PingContact(contact); node.BucketContainer.Add(contact); } node.IterativeFindNode(node.Contact.NodeId); node.BucketContainer.RefreshNeighbours(); } } finally { _initializeDisposeLock.ExitWriteLock(); } }