-
Notifications
You must be signed in to change notification settings - Fork 0
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
Increases usage of dependency injection #14
Draft
lewishazell
wants to merge
7
commits into
master
Choose a base branch
from
task/12-expand-dependency-injection
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
585c936
Network: Create SocketListenerFactory.
lewishazell 9747851
Network: Pass log directly into SocketListener constructor.
lewishazell ae1f9c5
Network: Use private log property in SocketListener instead of IRCd p…
lewishazell d56f0b1
Network: Add log parameter to SocketConnector constructor.
lewishazell 0381653
Network: Add SocketConnectorFactory.
lewishazell 35dca07
Daemon: Construct SocketConnector instances with SocketConnectorFactory.
lewishazell 9279ed6
Network: Use log property in SocketConnector instead of Log in IRCd.
lewishazell 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 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,7 @@ | ||
using cmpctircd.Configuration; | ||
|
||
namespace cmpctircd { | ||
public interface ISocketConnectorFactory { | ||
SocketConnector CreateSocketConnector(IRCd ircd, ServerElement config); | ||
} | ||
} |
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,7 @@ | ||
using cmpctircd.Configuration; | ||
|
||
namespace cmpctircd { | ||
public interface ISocketListenerFactory { | ||
SocketListener CreateSocketListener(IRCd ircd, SocketElement config); | ||
} | ||
} |
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
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,16 @@ | ||
using cmpctircd.Configuration; | ||
using System; | ||
|
||
namespace cmpctircd { | ||
public class SocketConnectorFactory : ISocketConnectorFactory { | ||
private readonly Log log; | ||
|
||
public SocketConnectorFactory(Log log) { | ||
this.log = log ?? throw new ArgumentNullException(nameof(log)); | ||
} | ||
|
||
public SocketConnector CreateSocketConnector(IRCd ircd, ServerElement config) { | ||
return new SocketConnector(log, ircd, config); | ||
} | ||
} | ||
} |
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 |
---|---|---|
|
@@ -12,6 +12,7 @@ | |
|
||
namespace cmpctircd { | ||
public class SocketListener { | ||
private readonly Log log; | ||
protected IRCd _ircd; | ||
private Boolean _started = false; | ||
private TcpListener _listener = null; | ||
|
@@ -25,7 +26,8 @@ public class SocketListener { | |
public int ServerCount = 0; | ||
public int AuthServerCount = 0; | ||
|
||
public SocketListener(IRCd ircd, SocketElement info) { | ||
public SocketListener(Log log, IRCd ircd, SocketElement info) { | ||
this.log = log ?? throw new ArgumentNullException(nameof(log)); | ||
this._ircd = ircd; | ||
this.Info = info; | ||
_listener = new TcpListener(info.Host, info.Port); | ||
|
@@ -43,7 +45,7 @@ public virtual void Bind() { | |
} | ||
public virtual void Stop() { | ||
if (_started) { | ||
_ircd.Log.Debug($"Shutting down listener [IP: {Info.Host}, Port: {Info.Port}, TLS: {Info.IsTls}]"); | ||
log.Debug($"Shutting down listener [IP: {Info.Host}, Port: {Info.Port}, TLS: {Info.IsTls}]"); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I can already see that this is so much better than passing around everything inside IRCd |
||
_listener.Stop(); | ||
_started = false; | ||
} | ||
|
@@ -61,7 +63,7 @@ public async Task ListenToClients() { | |
TcpClient tc = await _listener.AcceptTcpClientAsync(); | ||
HandleClientAsync(tc); // this should split off execution | ||
} catch(Exception e) { | ||
_ircd.Log.Error($"Exception in ListenToClients(): {e.ToString()}"); | ||
log.Error($"Exception in ListenToClients(): {e.ToString()}"); | ||
} | ||
} | ||
} | ||
|
@@ -72,7 +74,7 @@ protected async Task<Stream> HandshakeIfNeededAsync(TcpClient tc, Stream stream) | |
try { | ||
stream = await HandshakeTlsAsServerAsync(tc); | ||
} catch (Exception e) { | ||
_ircd.Log.Debug($"Exception in {nameof(HandshakeTlsAsServerAsync)}: {e}"); | ||
log.Debug($"Exception in {nameof(HandshakeTlsAsServerAsync)}: {e}"); | ||
tc.Close(); | ||
} | ||
} | ||
|
@@ -189,7 +191,7 @@ public async Task<SslStream> HandshakeTlsAsClient(TcpClient tc, string host, boo | |
if (verifyCert) { | ||
stream = new SslStream(tc.GetStream(), true); | ||
} else { | ||
_ircd.Log.Warn($"[SERVER] Connecting out to server {host} with TLS verification disabled: this is dangerous!"); | ||
log.Warn($"[SERVER] Connecting out to server {host} with TLS verification disabled: this is dangerous!"); | ||
stream = new SslStream(tc.GetStream(), true, (sender, certificate, chain, sslPolicyErrors) => true); | ||
} | ||
|
||
|
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,16 @@ | ||
using cmpctircd.Configuration; | ||
using System; | ||
|
||
namespace cmpctircd { | ||
public class SocketListenerFactory : ISocketListenerFactory { | ||
private readonly Log log; | ||
|
||
public SocketListenerFactory(Log log) { | ||
this.log = log ?? throw new ArgumentNullException(nameof(log)); | ||
} | ||
|
||
public SocketListener CreateSocketListener(IRCd ircd, SocketElement config) { | ||
return new SocketListener(log, ircd, config); | ||
} | ||
} | ||
} |
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.
This (and SocketListenerFactory) are only really just returning an object conditionless at the moment, I am guessing this is being done with a bigger picture in mind? I can see it nicely abstracts the Log creation but I don't really have the bigger picture in my head at the moment