public PeerAddressManagerBehaviour(IDateTimeProvider dateTimeProvider, IPeerAddressManager peerAddressManager, IPeerBanning peerBanning, ILoggerFactory loggerFactory) { Guard.NotNull(dateTimeProvider, nameof(dateTimeProvider)); Guard.NotNull(peerAddressManager, nameof(peerAddressManager)); Guard.NotNull(peerAddressManager, nameof(peerBanning)); Guard.NotNull(peerAddressManager, nameof(loggerFactory)); this.dateTimeProvider = dateTimeProvider; this.logger = loggerFactory.CreateLogger(this.GetType().FullName, $"[{this.GetHashCode():x}] "); this.loggerFactory = loggerFactory; this.peerBanning = peerBanning; this.Mode = PeerAddressManagerBehaviourMode.AdvertiseDiscover; this.peerAddressManager = peerAddressManager; this.addrPayloadSent = false; }
/// <inheritdoc/> public void StartConnectAsync(NetworkPeerConnectionParameters parameters, PeerAddressManagerBehaviourMode mode) { this.parentParameters = parameters; this.CurrentParameters = this.parentParameters.Clone(); this.CurrentParameters.ConnectCancellation = this.nodeLifetime.ApplicationStopping; this.CurrentParameters.PeerAddressManagerBehaviour().Mode = mode; this.CurrentParameters.TemplateBehaviors.Add(new PeerConnectorBehaviour(this)); this.asyncLoop = this.asyncLoopFactory.Run($"{this.GetType().Name}.{nameof(this.ConnectAsync)}", async token => { await this.ConnectAsync(); }, this.nodeLifetime.ApplicationStopping, repeatEvery: TimeSpans.Second); }