/// <summary> /// Main threaded loop that control broadcassting server loop start. /// </summary> protected static void ThreadingServerLoop_PP_Broadcast(object server) { if (server is BroadcastServer broadcastingServer) { #region Init Thread.CurrentThread.CurrentUICulture = new System.Globalization.CultureInfo("en-us"); Console.WriteLine("BROADCASTING THREAD STARTED: {0}", Thread.CurrentThread.Name); // Name of pipe server that will established. // Access to this pipe by clients will be available by this name. string serverName = broadcastingServer.ServerThread.Name; #endregion #region Server establishing // Start server loop. BroadcastTransmissionController.ServerLoop( serverName, broadcastingServer.pipeName, broadcastingServer.securityLevel, broadcastingServer.GetMessage); #endregion } else { // Throw error. throw new InvalidCastException( "Requires a `Standard.BroadcastingServer` server as the shared object."); } }
/// <summary> /// Building a message suitable for the bradcasting. /// </summary> /// <param name="_">Not using.</param> /// <returns>A Query with public key info</returns> public static byte[] ToBroadcastMessage(BroadcastTransmissionController _) { // Converting the query to the binary format. var binaryData = UniformDataOperator.Binary.BinaryHandler.ToByteArray(PKQuery); // Retunina converted data. return(binaryData); }
/// <summary> /// Redirect recived query from current server to other. /// </summary> /// <param name="controller">Controller that manage curernt transmission.</param> public static byte[] QueryHandler_BroadcastingRelay(BroadcastTransmissionController controller) { // Tries to detect a relay instruction. if (!RelayInstruction.TryToDetectTarget( UniformClient.BaseClient.routingTable.intructions, controller.PipeName, out RelayInstruction relayInstruction)) { Console.WriteLine( "Relay instruction for \"" + controller.PipeName + "\" not found. Add instuction to \"BaseClient.routingTable.intructions\" collection."); return(UniformDataOperator.Binary.BinaryHandler.ToByteArray("Error 404: Routing server not found. Con'tact administrator.")); } // Markers for managing thread. bool relayedMessageRecieved = false; byte[] relayedData = null; // Log Console.WriteLine("Requesting broadcasting: " + relayInstruction.routingIP + "/" + relayInstruction.pipeName); // Requiest message from relaying broadcasting server. UniformClient.BaseClient.ReceiveAnonymousBroadcastMessage( relayInstruction.routingIP, relayInstruction.pipeName, delegate(TransmissionLine lint, UniformQueries.Query query) { // Conver message to string. relayedData = UniformDataOperator.Binary.BinaryHandler.ToByteArray(query); // Unlock thread. relayedMessageRecieved = true; }); // Wait until broadcasting message. while (!relayedMessageRecieved) { Thread.Sleep(15); } // Return recived message. return(relayedData); }
/// <summary> /// Starting the server loop that will control relay query handler. /// </summary> protected static void ThreadingServerLoop_BroadcastingRelay(object server) { #region Init Thread.CurrentThread.CurrentUICulture = new System.Globalization.CultureInfo("en-us"); Console.WriteLine("BROADCASTING RELAY THREAD STARTED: {0}", Thread.CurrentThread.Name); // Name of pipe server that will established. // Access to this pipe by clients will be available by this name. string serverName = ((RelayServer)server).ServerThread.Name; #endregion #region Server establishing // Start server loop. BroadcastTransmissionController.ServerLoop( serverName, ((RelayServer)server).pipeName, ((RelayServer)server).securityLevel, QueryHandler_BroadcastingRelay); #endregion }
/// <summary> /// Authorizes a new token with guests rights /// and returns an information in a query format. /// /// Mades `AuthorizeNewGuestToken` comatible to the <see cref="BroadcastTransmissionController"/> handler. /// </summary> /// <param name="_">Droped param not relative to this broadcasting.</param> /// <returns>A token that can be used by client in queries.</returns> public static byte[] AuthorizeNewGuestToken(BroadcastTransmissionController _) { return(AuthorizeNewGuestToken()); }