internal static UriPrefixTable <HandshakeDelegate> BuildAddressTable(IServiceProvider services) { ILogger <NetMessageFramingConnectionHandler> logger = services.GetRequiredService <ILogger <NetMessageFramingConnectionHandler> >(); IServiceBuilder serviceBuilder = services.GetRequiredService <IServiceBuilder>(); IDispatcherBuilder dispatcherBuilder = services.GetRequiredService <IDispatcherBuilder>(); var addressTable = new UriPrefixTable <HandshakeDelegate>(); foreach (Type serviceType in serviceBuilder.Services) { List <IServiceDispatcher> dispatchers = dispatcherBuilder.BuildDispatchers(serviceType); foreach (IServiceDispatcher dispatcher in dispatchers) { if (dispatcher.BaseAddress == null) { // TODO: Should we throw? Ignore? continue; } // TODO: Limit to specifically TcpTransportBindingElement if net.tcp etc BindingElementCollection be = dispatcher.Binding.CreateBindingElements(); ConnectionOrientedTransportBindingElement cotbe = be.Find <ConnectionOrientedTransportBindingElement>(); if (cotbe == null) { // TODO: Should we throw? Ignore? continue; } HandshakeDelegate handshake = BuildHandshakeDelegateForDispatcher(dispatcher); logger.LogDebug($"Registering URI {dispatcher.BaseAddress} with NetMessageFramingConnectionHandler"); addressTable.RegisterUri(dispatcher.BaseAddress, cotbe.HostNameComparisonMode, handshake); } } return(addressTable); }
/// <summary> /// Branches the handshake pipeline based on the result of a predicate. /// If the predicate returns true the branch is executed. /// </summary> /// <param name="handshakeBuilder">The <see cref="IFramingConnectionHandshakeBuilder"/> instance.</param> /// <param name="predicate">The request path to match.</param> /// <param name="configuration">The branch to take for positive path matches.</param> /// <returns>The <see cref="IFramingConnectionHandshakeBuilder"/> instance.</returns> public static IFramingConnectionHandshakeBuilder Map(this IFramingConnectionHandshakeBuilder handshakeBuilder, Func <FramingConnection, bool> predicate, Action <IFramingConnectionHandshakeBuilder> configuration) { if (handshakeBuilder == null) { throw new ArgumentNullException(nameof(handshakeBuilder)); } if (configuration == null) { throw new ArgumentNullException(nameof(configuration)); } if (predicate == null) { throw new ArgumentNullException(nameof(predicate)); } // create branch IFramingConnectionHandshakeBuilder branchBuilder = handshakeBuilder.New(); configuration(branchBuilder); HandshakeDelegate branch = branchBuilder.Build(); var options = new MapOptions { Branch = branch, Predicate = predicate, }; return(handshakeBuilder.Use(next => new MapMiddleware(next, options).Invoke)); }
private HandshakeDelegate BuildHandshake(IFramingConnectionHandshakeBuilder handshakeBuilder) { handshakeBuilder.UseMiddleware <FramingModeHandshakeMiddleware>(); handshakeBuilder.Map(connection => connection.FramingMode == FramingMode.Duplex, configuration => { configuration.UseMiddleware <DuplexFramingMiddleware>(); configuration.Use(next => async(connection) => { UriPrefixTable <HandshakeDelegate> addressTable = configuration.HandshakeServices.GetRequiredService <UriPrefixTable <HandshakeDelegate> >(); HandshakeDelegate serviceHandshake = GetServiceHandshakeDelegate(addressTable, connection.Via); await serviceHandshake(connection); await next(connection); }); configuration.UseMiddleware <ServerFramingDuplexSessionMiddleware>(); configuration.UseMiddleware <ServerSessionConnectionReaderMiddleware>(); }); handshakeBuilder.Map(connection => connection.FramingMode == FramingMode.Singleton, configuration => { configuration.UseMiddleware <SingletonFramingMiddleware>(); configuration.Use(next => async(connection) => { UriPrefixTable <HandshakeDelegate> addressTable = configuration.HandshakeServices.GetRequiredService <UriPrefixTable <HandshakeDelegate> >(); HandshakeDelegate serviceHandshake = GetServiceHandshakeDelegate(addressTable, connection.Via); await serviceHandshake(connection); await next(connection); }); configuration.UseMiddleware <ServerFramingSingletonMiddleware>(); configuration.UseMiddleware <ServerSingletonConnectionReaderMiddleware>(); }); return(handshakeBuilder.Build()); }
public NetMessageFramingConnectionHandler(IServiceBuilder serviceBuilder, IDispatcherBuilder dispatcherBuilder, IFramingConnectionHandshakeBuilder handshakeBuilder) { _serviceBuilder = serviceBuilder; _dispatcherBuilder = dispatcherBuilder; _handshake = BuildHandshake(handshakeBuilder); _services = handshakeBuilder.HandshakeServices; serviceBuilder.Opened += OnServiceBuilderOpened; }
public void addHandshakeCompleteListener(HandshakeDelegate handshakeDelegate) { if (_handshakeComplete) { handshakeDelegate(_handshake); return; } _handshakeListeners.Add(handshakeDelegate); }
public HandshakeDelegate Build() { HandshakeDelegate app = context => { return(Task.CompletedTask); }; foreach (var component in _components.Reverse()) { app = component(app); } return(app); }
internal static HandshakeDelegate GetServiceHandshakeDelegate(UriPrefixTable <HandshakeDelegate> addressTable, Uri via) { HandshakeDelegate handshake = null; if (addressTable.TryLookupUri(via, HostNameComparisonMode.StrongWildcard, out handshake)) { return(handshake); } if (addressTable.TryLookupUri(via, HostNameComparisonMode.Exact, out handshake)) { return(handshake); } addressTable.TryLookupUri(via, HostNameComparisonMode.WeakWildcard, out handshake); return(handshake); }
public DuplexFramingMiddleware(HandshakeDelegate next) { _next = next; }
public ServerFramingSingletonMiddleware(HandshakeDelegate next) { _next = next; }
/// <summary> /// Creates a new instance of <see cref="MapMiddleware"/>. /// </summary> /// <param name="next">The delegate representing the next middleware in the request pipeline.</param> /// <param name="options">The middleware options.</param> public MapMiddleware(HandshakeDelegate next, MapOptions options) { _next = next ?? throw new ArgumentNullException(nameof(next)); _options = options ?? throw new ArgumentNullException(nameof(options)); }
public ServerFramingDuplexSessionMiddleware(HandshakeDelegate next) { _next = next; }
public FramingModeHandshakeMiddleware(HandshakeDelegate next) { _next = next; }
public FramingModeHandshakeMiddleware(HandshakeDelegate next, IApplicationLifetime appLifetime) { _next = next; _appLifetime = appLifetime; }
public NetMessageFramingConnectionHandler(IServiceBuilder serviceBuilder, IDispatcherBuilder dispatcherBuilder, IFramingConnectionHandshakeBuilder handshakeBuilder) { _serviceBuilder = serviceBuilder; _dispatcherBuilder = dispatcherBuilder; _handshake = BuildHandshake(handshakeBuilder); }
public ServerSingletonConnectionReaderMiddleware(HandshakeDelegate next, IServiceScopeFactory servicesScopeFactory) { _next = next; _servicesScopeFactory = servicesScopeFactory; }
public SingletonFramingMiddleware(HandshakeDelegate next) { _next = next; }
public ServerSessionConnectionReaderMiddleware(HandshakeDelegate next, IServiceScopeFactory servicesScopeFactory, IApplicationLifetime appLifetime) { _next = next; _servicesScopeFactory = servicesScopeFactory; _appLifetime = appLifetime; }