-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(repeater): refrain from utilizing non standard ports
closes #165
- Loading branch information
Showing
41 changed files
with
1,163 additions
and
523 deletions.
There are no files selected for viewing
This file contains 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 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,58 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using Microsoft.Extensions.DependencyInjection; | ||
using Microsoft.Extensions.Logging; | ||
using SecTester.Core; | ||
using SecTester.Core.Utils; | ||
using SocketIO.Serializer.MessagePack; | ||
using SocketIOClient; | ||
|
||
namespace SecTester.Repeater.Bus; | ||
|
||
public class DefaultRepeaterBusFactory : IRepeaterBusFactory | ||
{ | ||
private readonly Configuration _config; | ||
private readonly ILoggerFactory _loggerFactory; | ||
private readonly IServiceScopeFactory _scopeFactory; | ||
|
||
public DefaultRepeaterBusFactory(Configuration config, ILoggerFactory loggerFactory, IServiceScopeFactory scopeFactory) | ||
{ | ||
_config = config ?? throw new ArgumentNullException(nameof(config)); | ||
_loggerFactory = loggerFactory ?? throw new ArgumentNullException(nameof(loggerFactory)); | ||
_scopeFactory = scopeFactory ?? throw new ArgumentNullException(nameof(scopeFactory)); | ||
} | ||
|
||
public IRepeaterBus Create(string repeaterId) | ||
{ | ||
if (_config.Credentials is null) | ||
{ | ||
throw new InvalidOperationException( | ||
"Please provide credentials to establish a connection with the bus." | ||
); | ||
} | ||
|
||
var url = new Uri(_config.Api); | ||
var options = new SocketIOOptions | ||
{ | ||
Path = "/api/ws/v1", | ||
ReconnectionAttempts = 20, | ||
ReconnectionDelayMax = 86400000, | ||
ConnectionTimeout = TimeSpan.FromSeconds(10), | ||
Auth = new List<KeyValuePair<string, string>> | ||
{ | ||
new("token", _config.Credentials.Token), new("domain", repeaterId) | ||
}, | ||
}; | ||
|
||
var client = new SocketIOClient.SocketIO(url, options) | ||
{ | ||
Serializer = new SocketIOMessagePackSerializer() | ||
}; | ||
var wrapper = new SocketIoClientWrapper(client); | ||
|
||
var scope = _scopeFactory.CreateAsyncScope(); | ||
var timerProvider = scope.ServiceProvider.GetRequiredService<ITimerProvider>(); | ||
|
||
return new SocketIoRepeaterBus(url, wrapper, timerProvider, _loggerFactory.CreateLogger<IRepeaterBus>()); | ||
} | ||
} |
38 changes: 0 additions & 38 deletions
38
src/SecTester.Repeater/Bus/DefaultRepeaterEventBusFactory.cs
This file was deleted.
Oops, something went wrong.
This file contains 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,15 @@ | ||
using System; | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
|
||
namespace SecTester.Repeater.Bus; | ||
|
||
public interface IRepeaterBus : IAsyncDisposable | ||
{ | ||
event Func<IncomingRequest, Task<OutgoingResponse>> RequestReceived; | ||
event Action<Exception> ErrorOccurred; | ||
event Action<Version> UpgradeAvailable; | ||
|
||
Task Connect(); | ||
Task Deploy(string repeaterId, Runtime? runtime = null, CancellationToken? cancellationToken = null); | ||
} |
This file contains 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,6 @@ | ||
namespace SecTester.Repeater.Bus; | ||
|
||
public interface IRepeaterBusFactory | ||
{ | ||
IRepeaterBus Create(string repeaterId); | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains 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,14 @@ | ||
using System; | ||
using System.Threading.Tasks; | ||
|
||
namespace SecTester.Repeater.Bus; | ||
|
||
public interface ISocketIoClient : IDisposable | ||
{ | ||
public bool Connected { get; } | ||
public Task Connect(); | ||
public Task Disconnect(); | ||
public void On(string eventName, Action<ISocketIoResponse> callback); | ||
public void Off(string eventName); | ||
public Task EmitAsync(string eventName, params object[] data); | ||
} |
This file contains 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,11 @@ | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
|
||
namespace SecTester.Repeater.Bus; | ||
|
||
public interface ISocketIoResponse | ||
{ | ||
public T GetValue<T>(int i = 0); | ||
public Task CallbackAsync(params object[] data); | ||
public Task CallbackAsync(CancellationToken cancellationToken, params object[] data); | ||
} |
7 changes: 1 addition & 6 deletions
7
...ter.Repeater/Bus/RequestExecutingEvent.cs → ...SecTester.Repeater/Bus/IncomingRequest.cs
This file contains 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
7 changes: 3 additions & 4 deletions
7
...er.Repeater/Bus/RequestExecutingResult.cs → ...ecTester.Repeater/Bus/OutgoingResponse.cs
This file contains 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 was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
30 changes: 0 additions & 30 deletions
30
src/SecTester.Repeater/Bus/RequestExecutingEventListener.cs
This file was deleted.
Oops, something went wrong.
This file contains 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,29 @@ | ||
using System; | ||
using System.Threading.Tasks; | ||
|
||
namespace SecTester.Repeater.Bus; | ||
|
||
public class SocketIoClientWrapper : ISocketIoClient | ||
{ | ||
private readonly SocketIOClient.SocketIO _socketIo; | ||
|
||
public SocketIoClientWrapper(SocketIOClient.SocketIO socketIo) => _socketIo = socketIo ?? throw new ArgumentNullException(nameof(socketIo)); | ||
|
||
public void Dispose() | ||
{ | ||
_socketIo.Dispose(); | ||
GC.SuppressFinalize(this); | ||
} | ||
|
||
public bool Connected => _socketIo.Connected; | ||
|
||
public Task Connect() => _socketIo.ConnectAsync(); | ||
|
||
public Task Disconnect() => _socketIo.DisconnectAsync(); | ||
|
||
public void On(string eventName, Action<ISocketIoResponse> callback) => _socketIo.On(eventName, x => callback(x as ISocketIoResponse)); | ||
|
||
public void Off(string eventName) => _socketIo.Off(eventName); | ||
|
||
public Task EmitAsync(string eventName, params object[] data) => _socketIo.EmitAsync(eventName, data); | ||
} |
Oops, something went wrong.