-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Domain Sockets and Named Pipes (#151)
- Loading branch information
Showing
9 changed files
with
140 additions
and
72 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
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
64 changes: 64 additions & 0 deletions
64
src/fiskaltrust.Launcher/Factories/IpcConnectionFactory.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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
using System.IO.Pipes; | ||
using System.Net; | ||
using System.Net.Sockets; | ||
using System.Security.Principal; | ||
using fiskaltrust.Launcher.Common.Configuration; | ||
|
||
namespace fiskaltrust.Launcher.Factories | ||
{ | ||
public interface IConnectionFactory | ||
{ | ||
public ValueTask<Stream> ConnectAsync(SocketsHttpConnectionContext _, CancellationToken cancellationToken); | ||
} | ||
|
||
public class IpcConnectionFactory : IConnectionFactory | ||
{ | ||
private IConnectionFactory _connectionFactory; | ||
public IpcConnectionFactory(LauncherConfiguration configuration) | ||
{ | ||
if (OperatingSystem.IsWindows()) | ||
{ | ||
_connectionFactory = new NamedPipesConnectionFactory(configuration.LauncherServiceUri!); | ||
} | ||
else | ||
{ | ||
_connectionFactory = new UnixDomainSocketsConnectionFactory(configuration.LauncherServiceUri!); | ||
} | ||
} | ||
public ValueTask<Stream> ConnectAsync(SocketsHttpConnectionContext _, CancellationToken cancellationToken) => _connectionFactory.ConnectAsync(_, cancellationToken); | ||
} | ||
|
||
public class NamedPipesConnectionFactory : IConnectionFactory | ||
{ | ||
private readonly string _uri; | ||
|
||
public NamedPipesConnectionFactory(string uri) | ||
{ | ||
_uri = uri; | ||
} | ||
|
||
public async ValueTask<Stream> ConnectAsync(SocketsHttpConnectionContext _, CancellationToken cancellationToken) | ||
{ | ||
var clientStream = new NamedPipeClientStream(".", _uri, PipeDirection.InOut, PipeOptions.WriteThrough | PipeOptions.Asynchronous, TokenImpersonationLevel.Anonymous); | ||
await clientStream.ConnectAsync(cancellationToken).ConfigureAwait(false); | ||
return clientStream; | ||
} | ||
} | ||
|
||
public class UnixDomainSocketsConnectionFactory : IConnectionFactory | ||
{ | ||
private readonly EndPoint _endPoint; | ||
|
||
public UnixDomainSocketsConnectionFactory(string uri) | ||
{ | ||
_endPoint = new UnixDomainSocketEndPoint(uri); | ||
} | ||
|
||
public async ValueTask<Stream> ConnectAsync(SocketsHttpConnectionContext _, CancellationToken cancellationToken) | ||
{ | ||
var socket = new Socket(AddressFamily.Unix, SocketType.Stream, ProtocolType.Unspecified); | ||
await socket.ConnectAsync(_endPoint, cancellationToken).ConfigureAwait(false); | ||
return new NetworkStream(socket, ownsSocket: 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
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
Oops, something went wrong.