-
Notifications
You must be signed in to change notification settings - Fork 89
Migrate SignalR feature into WebHost #121
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
0ba0753
Migrate SignalR feature into WebHost
sondreb fb8315b
Improve the Web Socket event handling
sondreb 5e84889
created a class to handle swagger api documentation xml file inclusion.
MithrilMan c15f86c
Fix issue with exceptions during type loading
sondreb ebd6cb9
Rename WebHost to NodeHost
sondreb 2111993
Rename WebHost folder to NodeHost
sondreb e0eefad
Removing the dependency on a static service provider
dangershony 4f8af1b
Remove the Hash and Height
sondreb b1794b4
Revert "Remove the Hash and Height"
sondreb e9643a0
Merge branch 'feature/migrate-signalr-to-webhost' of https://github.c…
sondreb f1bff6f
Move the resolving of HubContext so it only runs when WS is enabled
sondreb 9aa82ca
Remove hardcoded URL to JS and WS endpoints
sondreb ac76f1b
Handle serialization of IPAddress, add ignore on structures that cras…
sondreb 12b1983
Fix dependency issue for broadcasters when no IEventsSubscriptionServ…
sondreb 1306285
Update InitialBlockDownloadState.cs
sondreb File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
31 changes: 18 additions & 13 deletions
31
...s.SignalR/Broadcasters/BroadcasterBase.cs → ...Blockcore/Broadcasters/BroadcasterBase.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,50 +1,55 @@ | ||
| using System; | ||
| using System.Collections.Generic; | ||
| using Blockcore.AsyncWork; | ||
| using Blockcore.EventBus; | ||
| using Blockcore.Utilities; | ||
| using Microsoft.AspNetCore.SignalR; | ||
| using Microsoft.Extensions.Logging; | ||
|
|
||
| namespace Blockcore.Features.SignalR.Broadcasters | ||
| namespace Blockcore.Broadcasters | ||
| { | ||
| /// <summary> | ||
| /// Base class for all SignalR Broadcasters | ||
| /// Base class for all Web Socket Broadcasters | ||
| /// </summary> | ||
| public abstract class ClientBroadcasterBase : IClientEventBroadcaster | ||
| { | ||
| private readonly EventsHub eventsHub; | ||
| private readonly IEventsSubscriptionService eventsHub; | ||
| private readonly INodeLifetime nodeLifetime; | ||
| private readonly IAsyncProvider asyncProvider; | ||
| protected readonly ILogger logger; | ||
| private IAsyncLoop asyncLoop; | ||
| protected readonly ILogger log; | ||
|
|
||
| protected ClientBroadcasterBase( | ||
| EventsHub eventsHub, | ||
| ILoggerFactory loggerFactory, | ||
| INodeLifetime nodeLifetime, | ||
| IAsyncProvider asyncProvider) | ||
| IAsyncProvider asyncProvider, | ||
| IEventsSubscriptionService subscriptionService = null | ||
| ) | ||
| { | ||
| this.eventsHub = eventsHub; | ||
| this.eventsHub = subscriptionService; | ||
| this.nodeLifetime = nodeLifetime; | ||
| this.asyncProvider = asyncProvider; | ||
| this.logger = loggerFactory.CreateLogger(this.GetType().FullName); | ||
| this.log = loggerFactory.CreateLogger(this.GetType().FullName); | ||
| } | ||
|
|
||
| public void Init(ClientEventBroadcasterSettings broadcasterSettings) | ||
| { | ||
| this.logger.LogDebug($"Initialising SignalR Broadcaster {this.GetType().Name}"); | ||
| this.log.LogDebug($"Initialising Web Socket Broadcaster {this.GetType().Name}"); | ||
|
|
||
| this.asyncLoop = this.asyncProvider.CreateAndRunAsyncLoop( | ||
| $"Broadcast {this.GetType().Name}", | ||
| async token => | ||
| { | ||
| foreach (IClientEvent clientEvent in this.GetMessages()) | ||
| foreach (EventBase clientEvent in this.GetMessages()) | ||
| { | ||
| await this.eventsHub.SendToClientsAsync(clientEvent).ConfigureAwait(false); | ||
| this.eventsHub.OnEvent(clientEvent); | ||
| } | ||
| }, | ||
| this.nodeLifetime.ApplicationStopping, | ||
| repeatEvery: TimeSpan.FromSeconds(Math.Max(broadcasterSettings.BroadcastFrequencySeconds, 5))); | ||
| repeatEvery: TimeSpan.FromSeconds(Math.Max(broadcasterSettings.BroadcastFrequencySeconds, 5)), | ||
| startAfter: TimeSpans.FiveSeconds); | ||
| } | ||
|
|
||
| protected abstract IEnumerable<IClientEvent> GetMessages(); | ||
| protected abstract IEnumerable<EventBase> GetMessages(); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| namespace Blockcore.Broadcasters | ||
| { | ||
| public class ClientEventBroadcasterSettings | ||
| { | ||
| public int BroadcastFrequencySeconds { get; set; } | ||
| } | ||
| } |
4 changes: 3 additions & 1 deletion
4
...atures.SignalR/IClientEventBroadcaster.cs → ...e/Broadcasters/IClientEventBroadcaster.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| using System.Threading.Tasks; | ||
| using Blockcore.Broadcasters; | ||
| using Blockcore.EventBus; | ||
| using Microsoft.AspNetCore.SignalR; | ||
|
|
||
| namespace Blockcore.Broadcasters | ||
| { | ||
| public interface IEventsSubscriptionService | ||
| { | ||
| void Init(); | ||
|
|
||
| void Subscribe(string id, string name); | ||
|
|
||
| void Unsubscribe(string id, string name); | ||
|
|
||
| void UnsubscribeAll(string id); | ||
|
|
||
| void OnEvent(EventBase @event); | ||
|
|
||
| void SetHub<T>(IHubContext<T> hubContext) where T : Hub; | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,5 @@ | ||
| using System.Net; | ||
| using Newtonsoft.Json; | ||
|
|
||
| namespace Blockcore.EventBus.CoreEvents.Peer | ||
| { | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,5 @@ | ||
| using NBitcoin; | ||
| using System; | ||
| using NBitcoin; | ||
|
|
||
| namespace Blockcore.EventBus.CoreEvents | ||
| { | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,26 @@ | ||
| using System; | ||
| using System.Collections.Generic; | ||
| using System.Linq; | ||
| using System.Reflection; | ||
| using System.Text; | ||
|
|
||
| namespace Blockcore.Utilities.Extensions | ||
| { | ||
| public static class AssemblyExtensions | ||
| { | ||
| /// <summary> | ||
| /// Gets the loadable types, ignoring assembly that can't be loaded for any reason. | ||
| /// </summary> | ||
| public static IEnumerable<Type> GetLoadableTypes(this Assembly assembly) | ||
| { | ||
| try | ||
| { | ||
| return assembly.GetTypes(); | ||
| } | ||
| catch (ReflectionTypeLoadException e) | ||
| { | ||
| return e.Types.Where(t => t != null); | ||
| } | ||
| } | ||
| } | ||
| } |
26 changes: 26 additions & 0 deletions
26
src/Blockcore/Utilities/JsonConverters/IPAddressConverter.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,26 @@ | ||
| using System; | ||
| using System.Collections.Generic; | ||
| using System.Net; | ||
| using System.Text; | ||
| using Newtonsoft.Json; | ||
|
|
||
| namespace Blockcore.Utilities.JsonConverters | ||
| { | ||
| public class IPAddressConverter : JsonConverter | ||
| { | ||
| public override bool CanConvert(Type objectType) | ||
| { | ||
| return (objectType == typeof(IPAddress)); | ||
| } | ||
|
|
||
| public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer) | ||
| { | ||
| writer.WriteValue(value.ToString()); | ||
| } | ||
|
|
||
| public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer) | ||
| { | ||
| return IPAddress.Parse((string)reader.Value); | ||
| } | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fingers crossed