Skip to content

Commit

Permalink
Port to 1.10.1
Browse files Browse the repository at this point in the history
  • Loading branch information
JPWatson committed Aug 1, 2018
1 parent 4493169 commit d1ac7ac
Show file tree
Hide file tree
Showing 23 changed files with 232 additions and 83 deletions.
2 changes: 1 addition & 1 deletion RELEASE.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#### Port
Aeron.NET has been ported against Java version:
- Agrona: 0.9.18-13-g0378ffa
- Aeron: 1.9.2-341-gf6b702d9c
- Aeron: 1.10.1
2 changes: 1 addition & 1 deletion driver/Aeron.Driver.nuspec
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<package >
<metadata>
<id>Aeron.Driver</id>
<version>1.10.0</version>
<version>1.10.1</version>
<title>Aeron Driver</title>
<authors>Adaptive Financial Consulting Ltd.</authors>
<owners>Adaptive Financial Consulting Ltd.</owners>
Expand Down
Binary file modified driver/media-driver.jar
Binary file not shown.
2 changes: 1 addition & 1 deletion driver/version.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
Driver source:
http://repo1.maven.org/maven2/io/aeron/aeron-all/1.10.0/aeron-all-1.10.0.jar
http://repo1.maven.org/maven2/io/aeron/aeron-all/1.10.1/aeron-all-1.10.1.jar
2 changes: 1 addition & 1 deletion src/Adaptive.Aeron/Adaptive.Aeron.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<PropertyGroup>
<TargetFrameworks>netstandard2.0;net45</TargetFrameworks>
<PackageId>Aeron.Client</PackageId>
<VersionPrefix>1.10.0</VersionPrefix>
<VersionPrefix>1.10.1</VersionPrefix>
<Authors>Adaptive Financial Consulting Ltd.</Authors>
<Company>Adaptive Financial Consulting Ltd.</Company>
<Product>Aeron Client</Product>
Expand Down
3 changes: 1 addition & 2 deletions src/Adaptive.Aeron/ChannelUri.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
using System.Text;
using Adaptive.Aeron.LogBuffer;
using Adaptive.Agrona.Collections;
using Adaptive.Agrona.Concurrent;

namespace Adaptive.Aeron
{
Expand Down Expand Up @@ -64,7 +63,7 @@ public ChannelUri(string prefix, string media, IDictionary<string, string> @para
_media = media;
_params = @params;

_tags = SplitTags(_params[Aeron.Context.TAGS_PARAM_NAME]);
_tags = SplitTags(_params.GetOrDefault(Aeron.Context.TAGS_PARAM_NAME));
}

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
using System.Runtime.Serialization;
using Adaptive.Aeron.Exceptions;

namespace Adaptive.Cluster.Client
namespace Adaptive.Aeron.Security
{
/// <summary>
/// Used to indicated a failed authentication attempt when connecting to the cluster.
/// Used to indicated a failed authentication attempt when connecting to a system.
/// </summary>
public class AuthenticationException : AeronException
{
Expand Down
39 changes: 39 additions & 0 deletions src/Adaptive.Aeron/Security/DefaultAuthenticatorSupplier.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
using System;

namespace Adaptive.Aeron.Security
{
/// <summary>
/// Default Authenticator that authenticates all connection requests immediately.
/// </summary>
public class DefaultAuthenticatorSupplier : IAuthenticatorSupplier
{
public static readonly byte[] NULL_ENCODED_PRINCIPAL = new byte[0];
public static readonly IAuthenticator DEFAULT_AUTHENTICATOR = new DefaultAuthenticator();

public IAuthenticator Get()
{
return DEFAULT_AUTHENTICATOR;
}

private class DefaultAuthenticator : IAuthenticator
{
public void OnConnectRequest(long sessionId, byte[] encodedCredentials, long nowMs)
{
}

public void OnChallengeResponse(long sessionId, byte[] encodedCredentials, long nowMs)
{
}

public void OnConnectedSession(ISessionProxy sessionProxy, long nowMs)
{
sessionProxy.Authenticate(NULL_ENCODED_PRINCIPAL);
}

public void OnChallengedSession(ISessionProxy sessionProxy, long nowMs)
{
sessionProxy.Authenticate(NULL_ENCODED_PRINCIPAL);
}
}
}
}
52 changes: 52 additions & 0 deletions src/Adaptive.Aeron/Security/IAuthenticator.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
namespace Adaptive.Aeron.Security
{
/// <summary>
/// Interface for Authenticator to handle authentication of clients to a system.
/// <para>
/// The session-id refers to the authentication session and not the Aeron transport session assigned to a publication.
/// </para>
/// </summary>
public interface IAuthenticator
{
/// <summary>
/// Called upon reception of a Connect Request.
/// </summary>
/// <param name="sessionId"> to identify the client session connecting. </param>
/// <param name="encodedCredentials"> from the Connect Request. Will not be null, but may be 0 length. </param>
/// <param name="nowMs"> current epoch time in milliseconds. </param>
void OnConnectRequest(long sessionId, byte[] encodedCredentials, long nowMs);

/// <summary>
/// Called upon reception of a Challenge Response from an unauthenticated client.
/// </summary>
/// <param name="sessionId"> to identify the client session connecting. </param>
/// <param name="encodedCredentials"> from the Challenge Response. Will not be null, but may be 0 length. </param>
/// <param name="nowMs"> current epoch time in milliseconds. </param>
void OnChallengeResponse(long sessionId, byte[] encodedCredentials, long nowMs);

/// <summary>
/// Called when a client's response channel has been connected. This method may be called multiple times until the
/// session is timeouts, is challenged, authenticated, or rejected.
/// </summary>
/// <param name="sessionProxy"> to use to inform client of status. </param>
/// <param name="nowMs"> current epoch time in milliseconds. </param>
/// <seealso cref= SessionProxy </seealso>
void OnConnectedSession(ISessionProxy sessionProxy, long nowMs);

/// <summary>
/// Called when a challenged client should be able to accept a response from the authenticator.
/// <para>
/// When this is called, there is no assumption that a Challenge Response has been received, plus this method
/// may be called multiple times.
/// </para>
/// <para>
/// It is up to the concrete class to provide any timeout management.
///
/// </para>
/// </summary>
/// <param name="sessionProxy"> to use to inform client of status. </param>
/// <param name="nowMs"> current epoch time in milliseconds. </param>
/// <seealso cref= SessionProxy </seealso>
void OnChallengedSession(ISessionProxy sessionProxy, long nowMs);
}
}
10 changes: 10 additions & 0 deletions src/Adaptive.Aeron/Security/IAuthenticatorSupplier.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
namespace Adaptive.Aeron.Security
{
/// <summary>
/// Used to supply instances of <see cref="IAuthenticator"/>
/// </summary>
public interface IAuthenticatorSupplier
{
IAuthenticator Get();
}
}
Original file line number Diff line number Diff line change
@@ -1,25 +1,25 @@
namespace Adaptive.Cluster.Client
namespace Adaptive.Aeron.Security
{
/// <summary>
/// Supplier of credentials for authentication with a cluster leader.
/// Supplier of credentials for authentication with a system.
///
/// Implement this interface to supply credentials for clients. If no credentials are required then the
/// <seealso cref="NullCredentialsSupplier"/> can be used.
/// </summary>
public interface ICredentialsSupplier
{
/// <summary>
/// Provide a credential to be included in Session Connect message to the cluster.
/// Provide a credential to be included in Session Connect message to a system.
/// </summary>
/// <returns> a credential in binary form to be included in the Session Connect message to the cluster. </returns>
/// <returns> a credential in binary form to be included in the Session Connect message to system. </returns>
byte[] EncodedCredentials();

/// <summary>
/// Given some encoded challenge data, provide the credentials to be included in a Challenge Response as part of
/// authentication with a cluster.
/// authentication with a system.
/// </summary>
/// <param name="endcodedChallenge"> from the cluster to use in providing a credential. </param>
/// <returns> encoded credentials in binary form to be included in the Challenge Response to the cluster. </returns>
/// <returns> encoded credentials in binary form to be included in the Challenge Response to the system. </returns>
byte[] OnChallenge(byte[] endcodedChallenge);
}
}
33 changes: 33 additions & 0 deletions src/Adaptive.Aeron/Security/ISessionProxy.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
namespace Adaptive.Aeron.Security
{
/// <summary>
/// Representation for a session which is going through the authentication process.
/// </summary>
public interface ISessionProxy
{
/// <summary>
/// The session Id of the potential session assigned by the system.
/// </summary>
/// <returns> session id for the potential session </returns>
long SessionId();

/// <summary>
/// Inform the system that the session requires a challenge and to send the provided encoded challenge.
/// </summary>
/// <param name="encodedChallenge"> to send to the client. </param>
/// <returns> true if challenge was sent or false if challenge could not be sent. </returns>
bool Challenge(byte[] encodedChallenge);

/// <summary>
/// Inform the system that the session has met authentication requirements.
/// </summary>
/// <param name="encodedPrincipal"> that has passed authentication. </param>
/// <returns> true if success event was sent or false if success event could not be sent. </returns>
bool Authenticate(byte[] encodedPrincipal);

/// <summary>
/// Inform the system that the session has NOT met authentication requirements and should be rejected.
/// </summary>
void Reject();
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace Adaptive.Cluster.Client
namespace Adaptive.Aeron.Security
{
/// <summary>
/// Null provider of credentials when no authentication is required.
Expand Down
2 changes: 1 addition & 1 deletion src/Adaptive.Agrona/Adaptive.Agrona.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<TargetFrameworks>netstandard2.0;net45</TargetFrameworks>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<PackageId>Agrona</PackageId>
<VersionPrefix>1.10.0</VersionPrefix>
<VersionPrefix>1.10.1</VersionPrefix>
<Authors>Adaptive Financial Consulting Ltd.</Authors>
<Company>Adaptive Financial Consulting Ltd.</Company>
<Product>Agrona libraries initially included in Aeron Client</Product>
Expand Down
15 changes: 15 additions & 0 deletions src/Adaptive.Agrona/Collections/DictionaryExtensions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
using System.Collections.Generic;

namespace Adaptive.Agrona.Collections
{
public static class DictionaryExtensions
{
public static TValue GetOrDefault<TKey, TValue>(
this IDictionary<TKey, TValue> dictionary,
TKey key,
TValue @default = default(TValue))
{
return dictionary.TryGetValue(key, out var value) ? value : @default;
}
}
}
2 changes: 1 addition & 1 deletion src/Adaptive.Archiver/Adaptive.Archiver.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<TargetFrameworks>netstandard2.0;net45</TargetFrameworks>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<PackageId>Aeron.Archiver</PackageId>
<VersionPrefix>1.10.0</VersionPrefix>
<VersionPrefix>1.10.1</VersionPrefix>
<Authors>Adaptive Financial Consulting Ltd.</Authors>
<Company>Adaptive Financial Consulting Ltd.</Company>
<Product>Archiving over the Aeron transport</Product>
Expand Down
2 changes: 1 addition & 1 deletion src/Adaptive.Cluster/Adaptive.Cluster.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<TargetFrameworks>netstandard2.0;net45</TargetFrameworks>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<PackageId>Aeron.Cluster</PackageId>
<VersionPrefix>1.10.0</VersionPrefix>
<VersionPrefix>1.10.1</VersionPrefix>
<Authors>Adaptive Financial Consulting Ltd.</Authors>
<Company>Adaptive Financial Consulting Ltd.</Company>
<Product>Clustering libraries over the Aeron transport</Product>
Expand Down
17 changes: 9 additions & 8 deletions src/Adaptive.Cluster/Client/AeronCluster.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using Adaptive.Agrona;
using Adaptive.Agrona.Concurrent;
using Adaptive.Cluster.Codecs;
using Adaptive.Aeron.Security;

namespace Adaptive.Cluster.Client
{
Expand Down Expand Up @@ -40,7 +41,7 @@ public sealed class AeronCluster : IDisposable
private readonly BufferClaim _bufferClaim = new BufferClaim();
private readonly MessageHeaderEncoder _messageHeaderEncoder = new MessageHeaderEncoder();
private readonly SessionKeepAliveRequestEncoder _keepAliveRequestEncoder = new SessionKeepAliveRequestEncoder();

private readonly SessionHeaderEncoder _sessionHeaderEncoder = new SessionHeaderEncoder();
private readonly DirectBufferVector[] _vectors = new DirectBufferVector[2];
private readonly DirectBufferVector _messageBuffer = new DirectBufferVector();
Expand All @@ -52,7 +53,7 @@ private class Poller : IFragmentHandler
private readonly MessageHeaderDecoder _messageHeaderDecoder = new MessageHeaderDecoder();
private readonly SessionHeaderDecoder _sessionHeaderDecoder = new SessionHeaderDecoder();
private readonly NewLeaderEventDecoder _newLeaderEventDecoder = new NewLeaderEventDecoder();

private readonly ISessionMessageListener _sessionMessageListener;
private readonly long _clusterSessionId;
private readonly AeronCluster _cluster;
Expand All @@ -63,7 +64,7 @@ public Poller(ISessionMessageListener sessionMessageListener, long clusterSessio
_clusterSessionId = clusterSessionId;
_cluster = cluster;
}

public void OnFragment(IDirectBuffer buffer, int offset, int length, Header header)
{
_messageHeaderDecoder.Wrap(buffer, offset);
Expand Down Expand Up @@ -147,7 +148,7 @@ private AeronCluster(Context ctx)

_vectors[0] = new DirectBufferVector(headerBuffer, 0, SessionDecorator.SESSION_HEADER_LENGTH);
_vectors[1] = _messageBuffer;

_poller = new Poller(ctx.SessionMessageListener(), _clusterSessionId, this);
_fragmentAssembler = new FragmentAssembler(_poller);
}
Expand Down Expand Up @@ -432,7 +433,7 @@ private Publication ConnectToCluster()
string channel = channelUri.ToString();
publications[entry.Key] = AddIngressPublication(channel, ingressStreamId);
}

int connectedIndex = -1;
while (true)
{
Expand Down Expand Up @@ -814,7 +815,7 @@ public void OnMessage(
throw new ConfigurationException("sessionMessageListener must be specified on AeronCluster.Context");
}
}

private long _messageTimeoutNs = Configuration.MessageTimeoutNs();
private string _clusterMemberEndpoints = Configuration.ClusterMemberEndpoints();
private string _ingressChannel = Configuration.IngressChannel();
Expand Down Expand Up @@ -859,7 +860,7 @@ public void Conclude()
{
_credentialsSupplier = new NullCredentialsSupplier();
}

if (null == _sessionMessageListener)
{
_sessionMessageListener = new MissingSessionMessageListner();
Expand Down Expand Up @@ -1143,7 +1144,7 @@ public Context CredentialsSupplier(ICredentialsSupplier credentialsSupplier)
_credentialsSupplier = credentialsSupplier;
return this;
}

/// <summary>
/// Get the <seealso cref="ErrorHandler"/> to be used for handling any exceptions.
/// </summary>
Expand Down
Loading

0 comments on commit d1ac7ac

Please sign in to comment.