/// <summary> /// When a client connects, assign them a unique RSA keypair for handshake. /// </summary> /// <param name="clientSocket"></param> private static void HandleConnect(WebSocket clientSocket) { var connectionId = CookieManager.GetConnectionId(clientSocket); AuthClient authClient; AllClients.TryGetValue(connectionId, out authClient); if (authClient != null) { MessageQueueManager manager; //check if a manager for that port exist, if not, create one if (!authClient.MessageQueueManagers.TryGetValue(clientSocket.LocalEndpoint.Port, out manager)) { if (authClient.MessageQueueManagers.TryAdd(clientSocket.LocalEndpoint.Port, new MessageQueueManager())) { Console.WriteLine("Manager started for " + clientSocket.LocalEndpoint.Port); } } return; } Console.WriteLine("Connection from " + clientSocket.RemoteEndpoint); var rsa = new Rsa(); rsa.GenerateKeyPairs(); var client = new AuthClient { PublicKey = rsa.PublicKey, PrivateKey = rsa.PrivateKey, MessageQueueManagers = new ConcurrentDictionary <int, MessageQueueManager>() }; client.MessageQueueManagers.TryAdd(clientSocket.LocalEndpoint.Port, new MessageQueueManager()); AllClients.AddOrUpdate(connectionId, client, (key, value) => value); SendWelcomeMessage(client, clientSocket); }
/// <summary> /// When a client connects, assign them a unique RSA keypair for handshake. /// </summary> /// <param name="clientSocket"></param> private static void HandleConnect(WebSocket clientSocket) { Console.WriteLine("Connection from " + clientSocket.RemoteEndpoint); var client = new AuthClient(clientSocket); var rsa = new Rsa(); rsa.GenerateKeyPairs(); client.PublicKey = rsa.PublicKey; client.PrivateKey = rsa.PrivateKey; AllClients.AddOrUpdate(clientSocket.GetHashCode().ToString(), client, (key, value) => value); SendWelcomeMessage(client, clientSocket); }
/// <summary> /// When a client connects, assign them a unique RSA keypair for handshake. /// </summary> /// <param name="clientSocket"></param> private static async void HandleConnect(WebSocket clientSocket) { var connectionId = CookieManager.GetConnectionId(clientSocket); AuthClient authClient; AllClients.TryGetValue(connectionId, out authClient); var host = new Uri($"ws://{clientSocket.HttpRequest.Headers[RequestHeader.Host]}", UriKind.Absolute); if (authClient != null) { if (RunningAsService) { MessageQueueManager agentManager; if (!authClient.MessageQueueManagers.TryGetValue(22005, out agentManager)) { if (authClient.MessageQueueManagers.TryAdd(22005, new MessageQueueManager())) { Console.WriteLine("Service Manager Started"); } } } MessageQueueManager manager; //check if a manager for that port exist, if not, create one if (!authClient.MessageQueueManagers.TryGetValue(host.Port, out manager)) { if (authClient.MessageQueueManagers.TryAdd(host.Port, new MessageQueueManager())) { Console.WriteLine($"Manager started for {host.Port}"); } } return; } Console.WriteLine("Connection from " + clientSocket.RemoteEndpoint); var rsa = new Rsa(); rsa.GenerateKeyPairs(); var client = new AuthClient { PublicKey = rsa.PublicKey, PrivateKey = rsa.PrivateKey, MessageQueueManagers = new ConcurrentDictionary <int, MessageQueueManager>() }; client.MessageQueueManagers.TryAdd(host.Port, new MessageQueueManager()); AllClients.AddOrUpdate(connectionId, client, (key, value) => value); await SendWelcomeMessage(client, clientSocket); }
private static void HandleConnect(WebSocket clientSocket) { Console.WriteLine("Connection from " + clientSocket.RemoteEndpoint); var client = new AuthClient(clientSocket); var apiController = new ApiController(clientSocket) { //set the auth Client so we can use it later authClient = client }; AllClients.AddOrUpdate(client.GetHashCode().ToString(), client, (key, value) => value); ApiControllers.AddOrUpdate(apiController.authClient.GetHashCode().ToString(), apiController, (key, value) => value); SendWelcomeMessage(clientSocket); }