public LidgrenClientMessageContextFactory(IDeserializerStrategy deserializationStrategy) { if (deserializationStrategy == null) throw new ArgumentNullException(nameof(deserializationStrategy), $"Provided {nameof(IDeserializerStrategy)} cannot be null."); deserializer = deserializationStrategy; }
//Message responses are dispatched right after requests with this strategy. This is much different //than what is normally found in GladNet2 implementations. /// <summary> /// Creates a new <see cref="IWebRequestEnqueueStrategy"/> that handles requests on the calling thread /// and blocks. /// </summary> /// <param name="baseURL">Base string for the end-poind webserver. (Ex. www.google.com/)</param> /// <param name="deserializationService">Deserialization strategy for responses.</param> /// <param name="responseReciever">Message receiver service for dispatching recieved resposne messages.</param> public RestSharpCurrentThreadEnqueueRequestHandlerStrategy(string baseURL, IDeserializerStrategy deserializationService, ISerializerStrategy serializerStrategy, INetworkMessageReceiver responseReciever, int connectionAUID #if !ENDUSER , INetworkMessageRouteBackService routebackService) //unfortunaly the single-threaded blocking enqueue strat needs the routeback service to function. #endif { if (String.IsNullOrEmpty(baseURL)) throw new ArgumentException($"Parameter {baseURL} is not valid. Either null or empty. Base URL must be the base URL of the web server. (Ex. www.google.com)"); if (deserializationService == null) throw new ArgumentNullException(nameof(baseURL), $"Parameter {deserializationService} must not be null. Deserialization for incoming responses is required."); #if !ENDUSER if (routebackService == null) throw new ArgumentNullException(nameof(routebackService), $"{nameof(RestSharpCurrentThreadEnqueueRequestHandlerStrategy)} requires {(nameof(INetworkMessageRouteBackService))} as it handles responses too."); #endif serializer = serializerStrategy; deserializer = deserializationService; responseMessageRecieverService = responseReciever; restsharpMiddlewares = new List<IRestSharpMiddleWare>(2); ServicePointManager.ServerCertificateValidationCallback += (sender, certificate, chain, sslPolicyErrors) => true; System.Net.ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls; httpClient = new RestClient(baseURL) { Timeout = 15000 }; #if !ENDUSER messageRoutebackService = routebackService; #endif }
public LidgrenNetworkMessagePublisherService(IDeserializerStrategy deserializerStrat) { if (deserializerStrat == null) throw new ArgumentNullException(nameof(deserializerStrat), $"Must provide non-null {nameof(IDeserializerStrategy)} for {nameof(LidgrenNetworkMessagePublisherService)}"); deserializer = deserializerStrat; }
protected ApplicationBase(IDeserializerStrategy deserializer, ISerializerStrategy serializer, ILog logger, IManagedClientSessionFactory sessionManagedFactory) { if (deserializer == null) { throw new ArgumentNullException(nameof(deserializer)); } if (serializer == null) { throw new ArgumentNullException(nameof(serializer)); } if (logger == null) { throw new ArgumentNullException(nameof(logger)); } Logger = logger; //Init internal services/components //Create these first; thread needs them peerServiceCollection = new AUIDServiceCollection <ClientSessionServiceContext>(50); netPeerAUIDService = new AUIDNetPeerServiceDecorator(peerServiceCollection); managedNetworkThread = new ManagedLidgrenNetworkThread(serializer, new LidgrenServerMessageContextFactory(deserializer), new PeerSendServiceSelectionStrategy(peerServiceCollection), e => Logger.Fatal($"{e.Message} StackTrace: {e.StackTrace}")); InternalClientSessionFactory sessionFactory = new InternalClientSessionFactory(peerServiceCollection, serializer, Logger, netPeerAUIDService, sessionManagedFactory); sessionlessHandler = new SessionlessMessageHandler(sessionFactory, Logger); }
public LidgrenServerMessageContextFactory(IDeserializerStrategy deserializationStrategy) { if (deserializationStrategy == null) { throw new ArgumentNullException(nameof(deserializationStrategy)); } deserializer = deserializationStrategy; }
public LidgrenNetworkMessagePublisherService(IDeserializerStrategy deserializerStrat) { if (deserializerStrat == null) { throw new ArgumentNullException(nameof(deserializerStrat), $"Must provide non-null {nameof(IDeserializerStrategy)} for {nameof(LidgrenNetworkMessagePublisherService)}"); } deserializer = deserializerStrat; }
public LidgrenClientMessageContextFactory(IDeserializerStrategy deserializationStrategy) { if (deserializationStrategy == null) { throw new ArgumentNullException(nameof(deserializationStrategy), $"Provided {nameof(IDeserializerStrategy)} cannot be null."); } deserializer = deserializationStrategy; }
public GladNetClientPeer(InitRequest request, INetworkMessageReceiver reciever, IDeserializerStrategy deserializationStrat, IDisconnectionServiceHandler disconnectionService) : base(request) { Throw<ArgumentNullException>.If.IsNull(reciever)?.Now(nameof(reciever)); Throw<ArgumentNullException>.If.IsNull(deserializationStrat)?.Now(nameof(deserializationStrat)); Throw<ArgumentNullException>.If.IsNull(disconnectionService)?.Now(nameof(disconnectionService)); disconnectionServiceHandler = disconnectionService; networkReciever = reciever; deserializer = deserializationStrat; }
public GladNetInboundS2SPeer(InitResponse response, INetworkMessageReceiver reciever, IDeserializerStrategy deserializationStrat, IDisconnectionServiceHandler disconnectionService) : base(response) { Throw <ArgumentNullException> .If.IsNull(reciever)?.Now(nameof(reciever)); Throw <ArgumentNullException> .If.IsNull(deserializationStrat)?.Now(nameof(deserializationStrat)); Throw <ArgumentNullException> .If.IsNull(disconnectionService)?.Now(nameof(disconnectionService)); disconnectionServiceHandler = disconnectionService; networkReciever = reciever; deserializer = deserializationStrat; }
public LidgrenNetworkMessageMessageContext(NetIncomingMessage incomingMessage, IDeserializerStrategy deserializer) : base(incomingMessage) { //The message.LengthBytes - message.PositionInBytes is from GladNet1 //We need to read the byte[] chunk that is from the current position to the end. //For why we do this read this old exerp from GladNet2: //"Due to message recycling we cannot trust the internal array of data to be of only the information that should be used for this package. //We can trust the indicated size, not the length of .Data, and get a byte[] that represents the sent [Data]. //However, this will incur a GC penalty which may become an issue; more likely to be an issue on clients." byte[] bytes = incomingMessage.ReadBytes(incomingMessage.LengthBytes - incomingMessage.PositionInBytes); //Deserializer the network message and the payload. GeneratedNetworkMessage = deserializer.Deserialize<NetworkMessage>(bytes); GeneratedNetworkMessage?.Payload?.Deserialize(deserializer); }
public GladNetOutboundS2SPeer(GladNetAppBase appBase, INetworkMessageReceiver reciever, IDeserializerStrategy deserializationStrat, IDisconnectionServiceHandler disconnectionService) : base(appBase) { Throw<ArgumentNullException>.If.IsNull(appBase)?.Now(nameof(appBase)); Throw<ArgumentNullException>.If.IsNull(reciever)?.Now(nameof(reciever)); Throw<ArgumentNullException>.If.IsNull(deserializationStrat)?.Now(nameof(deserializationStrat)); Throw<ArgumentNullException>.If.IsNull(disconnectionService)?.Now(nameof(disconnectionService)); disconnectionServiceHandler = disconnectionService; networkReciever = reciever; deserializer = deserializationStrat; //Publish that we are connecting networkReciever.OnNetworkMessageReceive(new PhotonStatusMessageAdapter(NetStatus.Connecting), null); }
public GladNetOutboundS2SPeer(GladNetAppBase appBase, INetworkMessageReceiver reciever, IDeserializerStrategy deserializationStrat, IDisconnectionServiceHandler disconnectionService) : base(appBase) { Throw <ArgumentNullException> .If.IsNull(appBase)?.Now(nameof(appBase)); Throw <ArgumentNullException> .If.IsNull(reciever)?.Now(nameof(reciever)); Throw <ArgumentNullException> .If.IsNull(deserializationStrat)?.Now(nameof(deserializationStrat)); Throw <ArgumentNullException> .If.IsNull(disconnectionService)?.Now(nameof(disconnectionService)); disconnectionServiceHandler = disconnectionService; networkReciever = reciever; deserializer = deserializationStrat; //Publish that we are connecting networkReciever.OnNetworkMessageReceive(new PhotonStatusMessageAdapter(NetStatus.Connecting), null); }
public JWTAuthenticationMiddleware(IDeserializerStrategy deserializer, ISerializerStrategy serializer, ITokenRegistry tokenRegistry) { if (deserializer == null) { throw new ArgumentNullException(nameof(deserializer)); } if (serializer == null) { throw new ArgumentNullException(nameof(serializer)); } if (tokenRegistry == null) { throw new ArgumentNullException(nameof(tokenRegistry)); } deserializerStrategy = deserializer; serializerStrategy = serializer; tokenRegistryService = tokenRegistry; }
/// <summary> /// Adds the <see cref="GladNetInputFormatter"/> and <see cref="GladNetOutputFormatter"/> to the known formatters. /// Also registers the gladnet media header to map to these formatters. /// </summary> /// <param name="builder">Builder to chain off.</param> /// <param name="serializerStrat">Serialization strategy</param> /// <param name="deserializerStrat">Deserialization strategy.</param> /// <returns>The fluent <see cref="IMvcCoreBuilder"/> instance.</returns> public static IMvcBuilder AddGladNetFormatters([NotNull] this IMvcBuilder builder, [NotNull] ISerializerStrategy serializerStrat, [NotNull] IDeserializerStrategy deserializerStrat) { if (builder == null) { throw new ArgumentNullException(nameof(builder)); } if (serializerStrat == null) { throw new ArgumentNullException(nameof(serializerStrat)); } if (deserializerStrat == null) { throw new ArgumentNullException(nameof(deserializerStrat)); } //Add the formatters to the options. return(builder.AddMvcOptions(options => { options.InputFormatters.Add(new GladNetInputFormatter(deserializerStrat)); options.OutputFormatters.Add(new GladNetOutputFormatter(serializerStrat)); options.FormatterMappings.SetMediaTypeMappingForFormat("GladNet", MediaTypeHeaderValue.Parse("application/gladnet")); })); }
/// <inheritdoc /> public InternalUnityApplicationBase(IDeserializerStrategy deserializer, ISerializerStrategy serializer, ILog logger, IManagedClientSessionFactory sessionManagedFactory) : base(deserializer, serializer, logger, sessionManagedFactory) { }
/// <summary> /// Adds the <see cref="GladNetInputFormatter"/> and <see cref="GladNetOutputFormatter"/> to the known formatters. /// Also registers the gladnet media header to map to these formatters. /// </summary> /// <param name="builder">Builder to chain off.</param> /// <param name="serializerStrat">Serialization strategy</param> /// <param name="deserializerStrat">Deserialization strategy.</param> /// <param name="registry">Serialization registry.</param> /// <returns>The fluent <see cref="IServiceCollection"/> instance.</returns> public static IServiceCollection AddGladNet(this IServiceCollection builder, ISerializerStrategy serializerStrat, IDeserializerStrategy deserializerStrat, ISerializerRegistry registry) { if (builder == null) { throw new ArgumentNullException(nameof(builder)); } if (serializerStrat == null) { throw new ArgumentNullException(nameof(serializerStrat)); } if (deserializerStrat == null) { throw new ArgumentNullException(nameof(deserializerStrat)); } if (registry == null) { throw new ArgumentNullException(nameof(registry)); } //need to register these types registry.Register(typeof(NetworkMessage)); registry.Register(typeof(PacketPayload)); registry.Register(typeof(RequestMessage)); registry.Register(typeof(ResponseMessage)); return(builder.AddMvcCore() .AddGladNetFormatters(serializerStrat, deserializerStrat).Services); }
public GladNetInputFormatter(IDeserializerStrategy deserializationStrategy) { deserializerStrategy = deserializationStrategy ?? throw new ArgumentNullException(nameof(deserializationStrategy), $"Input formatter requires a deserialization strategy."); }
/// <summary> /// Registers the Middlewares required for JWT authorization. /// </summary> /// <typeparam name="TMiddlewareRegistryType"></typeparam> /// <param name="middlewarRegistry"></param> /// <param name="serializer"></param> /// <param name="deserializer"></param> /// <param name="tokenService"></param> /// <returns>Registy to fluently chain on.</returns> public static TMiddlewareRegistryType RegisterAuthorizationMiddleware <TMiddlewareRegistryType>(this TMiddlewareRegistryType middlewarRegistry, ISerializerStrategy serializer, IDeserializerStrategy deserializer, ITokenService tokenService) where TMiddlewareRegistryType : IMiddlewareRegistry { //Register the middlewares middlewarRegistry.Register(new JWTAuthorizationHeaderMiddleware(tokenService)); //return for fluent chaining return(middlewarRegistry); }
/// <summary> /// Registers the Middlewares required for authentication. /// </summary> /// <typeparam name="TMiddlewareRegistryType"></typeparam> /// <param name="middlewarRegistry"></param> /// <param name="serializer"></param> /// <param name="deserializer"></param> /// <param name="tokenRegister"></param> /// <returns>Registy to fluently chain on.</returns> public static TMiddlewareRegistryType RegisterAuthenticationMiddleware <TMiddlewareRegistryType>(this TMiddlewareRegistryType middlewarRegistry, ISerializerStrategy serializer, IDeserializerStrategy deserializer, ITokenRegistry tokenRegister) where TMiddlewareRegistryType : IMiddlewareRegistry { //Register the middlewares middlewarRegistry.Register(new JWTAuthenticationMiddleware(deserializer, serializer, tokenRegister)); //return for fluent chaining return(middlewarRegistry); }
public LidgrenNetworkMessageMessageContext(NetIncomingMessage incomingMessage, IDeserializerStrategy deserializer) : base(incomingMessage) { if (incomingMessage == null) { throw new ArgumentNullException(nameof(incomingMessage)); } if (deserializer == null) { throw new ArgumentNullException(nameof(deserializer)); } //The message.LengthBytes - message.PositionInBytes is from GladNet1 //We need to read the byte[] chunk that is from the current position to the end. //For why we do this read this old exerp from GladNet2: //"Due to message recycling we cannot trust the internal array of data to be of only the information that should be used for this package. //We can trust the indicated size, not the length of .Data, and get a byte[] that represents the sent [Data]. //However, this will incur a GC penalty which may become an issue; more likely to be an issue on clients." byte[] bytes = incomingMessage.ReadBytes(incomingMessage.LengthBytes - incomingMessage.PositionInBytes); //Deserializer the network message and the payload. GeneratedNetworkMessage = deserializer.Deserialize <NetworkMessage>(bytes); GeneratedNetworkMessage?.Payload?.Deserialize(deserializer); }