public void Handle(RegisterPeerCommand message) { if (_blacklistedMachines.Contains(Context !.Originator.SenderMachineName !)) { throw new InvalidOperationException($"Peer {Context.SenderId} on host {Context.Originator.SenderMachineName} is not allowed to register on this directory"); } var peerTimestampUtc = message.Peer.TimestampUtc; if (!peerTimestampUtc.HasValue) { throw new InvalidOperationException("The TimestampUtc must be provided when registering"); } var utcNow = SystemDateTime.UtcNow; if (_configuration.MaxAllowedClockDifferenceWhenRegistering != null && peerTimestampUtc.Value > utcNow + _configuration.MaxAllowedClockDifferenceWhenRegistering) { throw new InvalidOperationException($"The client provided timestamp [{peerTimestampUtc}] is too far ahead of the the server's current time [{utcNow}]"); } var stopwatch = Stopwatch.StartNew(); var peerDescriptor = message.Peer; peerDescriptor.Peer.IsUp = true; peerDescriptor.Peer.IsResponding = true; var existingPeer = _peerRepository.Get(peerDescriptor.PeerId); if (IsPeerInConflict(existingPeer, peerDescriptor)) { throw new DomainException(DirectoryErrorCodes.PeerAlreadyExists, string.Format("Peer {0} already exists (running on {1})", peerDescriptor.PeerId, existingPeer.Peer.EndPoint)); } _peerRepository.RemoveAllDynamicSubscriptionsForPeer(peerDescriptor.PeerId, DateTime.SpecifyKind(peerDescriptor.TimestampUtc !.Value, DateTimeKind.Utc)); _peerRepository.AddOrUpdatePeer(peerDescriptor); _bus.Publish(new PeerStarted(peerDescriptor)); var registredPeerDescriptors = _peerRepository.GetPeers(loadDynamicSubscriptions: true); _bus.Reply(new RegisterPeerResponse(registredPeerDescriptors.ToArray())); _speedReporter.ReportRegistrationDuration(stopwatch.Elapsed); }