Skip to content

Commit

Permalink
Daemon: Construct SocketConnector instances with SocketConnectorFactory.
Browse files Browse the repository at this point in the history
task: #12
  • Loading branch information
lewishazell committed May 23, 2021
1 parent 472768a commit ce83c28
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
6 changes: 4 additions & 2 deletions cmpctircd/IRCd.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

public class IRCd {
private readonly ISocketListenerFactory socketListenerFactory;
private readonly ISocketConnectorFactory socketConnectorFactory;
private readonly IList<SocketListener> Listeners = new List<SocketListener>();
public readonly IList<SocketConnector> Connectors = new List<SocketConnector>();
public PacketManager PacketManager { get; }
Expand Down Expand Up @@ -51,10 +52,11 @@ public class IRCd {

public List<Client> Clients => ClientLists.SelectMany(clientList => clientList).ToList();
public List<Server> Servers => ServerLists.SelectMany(serverList => serverList).ToList();
public IRCd(Log log, CmpctConfigurationSection config, IServiceProvider services, ISocketListenerFactory socketListenerFactory) {
public IRCd(Log log, CmpctConfigurationSection config, IServiceProvider services, ISocketListenerFactory socketListenerFactory, ISocketConnectorFactory socketConnectorFactory) {
this.Log = log;
this.Config = config;
this.socketListenerFactory = socketListenerFactory;
this.socketConnectorFactory = socketConnectorFactory;

// Interpret the ConfigData
SID = config.SID;
Expand Down Expand Up @@ -112,7 +114,7 @@ public void Run() {
if (server.IsOutbound) {
// <server> tag with outbound="true"
// We want to connect out to this server, not have them connect to us
var sc = new SocketConnector(this, server);
var sc = socketConnectorFactory.CreateSocketConnector(this, server);
Log.Info($"==> Connecting to: {server.Destination}:{server.Port} ({server.Host}) ({(server.IsTls ? "TLS" : "Plain" )})");

Connectors.Add(sc);
Expand Down
1 change: 1 addition & 0 deletions cmpctircd/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ static IHostBuilder CreateHostBuilder(string[] args) {
services.AddScoped(sp => sp.GetRequiredService<IrcContext>().Sender as Client);
services.AddScoped(sp => sp.GetRequiredService<IrcContext>().Sender as Server);
services.AddTransient<ISocketListenerFactory, SocketListenerFactory>();
services.AddTransient<ISocketConnectorFactory, SocketConnectorFactory>();
services.AddHostedService<IrcApplicationLifecycle>();
});
}
Expand Down

0 comments on commit ce83c28

Please sign in to comment.