public async Task HandleAsync() { NodeResponse response; if (request.KeyId == null) { response = new PublicKeyNodeResponse( request.RequestId, NodeData.Instance.NodeKeys.PublicKey, NodeData.Instance.NodeKeys.SignPublicKey, NodeData.Instance.NodeKeys.KeyId, NodeData.Instance.NodeKeys.ExpirationTime); } else { var key = await keysService.GetNodeKeysAsync(NodeSettings.Configs.Node.Id, request.KeyId.Value); if (key == null) { response = new ResultNodeResponse(request.RequestId, ObjectsLibrary.Enums.ErrorCode.ObjectDoesNotExists, "The key was not found."); } else { response = new PublicKeyNodeResponse(request.RequestId, key.PublicKey, key.SignPublicKey, key.KeyId, key.ExpirationTime); } } await NodeWebSocketCommunicationManager.SendResponseAsync(response, current).ConfigureAwait(false); }
public async Task HandleAsync() { NodeResponse response = default; try { TokenVm token = await tokensService.CheckTokenAsync(request.Token, NodeSettings.Configs.Node.Id).ConfigureAwait(false); UserVm user = await loadUsersService.GetUserAsync(token.UserId).ConfigureAwait(false); response = new UserTokensNodeResponse(request.RequestId, token, user); } catch (InvalidTokenException) { response = new ResultNodeResponse(request.RequestId, ErrorCode.InvalidAccessToken); } catch (TokensTimeoutException) { response = new ResultNodeResponse(request.RequestId, ErrorCode.AccessTokenTimeout); } catch (Exception ex) { Logger.WriteLog(ex); response = new ResultNodeResponse(request.RequestId, ErrorCode.UnknownError); } finally { NodeWebSocketCommunicationManager.SendResponse(response, current); } }
public async Task HandleAsync() { NodeResponse response; try { switch (request.RequestType) { case Enums.NodeRequestType.GetChats: { IEnumerable <ChatVm> chats = await loadChatsService.GetChatsByIdAsync(request.ObjectsId, request.RequestorUserId).ConfigureAwait(false); response = new ChatsNodeResponse(request.RequestId, chats); } break; case Enums.NodeRequestType.GetUsers: { IEnumerable <UserVm> users = await loadUsersService.GetUsersByIdAsync(request.ObjectsId, request.RequestorUserId).ConfigureAwait(false); users = await privacyService.ApplyPrivacySettingsAsync(users, request.RequestorUserId).ConfigureAwait(false); response = new UsersNodeResponse(request.RequestId, users); } break; case Enums.NodeRequestType.GetChannels: { IEnumerable <ChannelDto> channels = await loadChannelsService.GetChannelsWithSubscribersAsync(request.ObjectsId).ConfigureAwait(false); response = new ChannelsNodeResponse(request.RequestId, channels); } break; case Enums.NodeRequestType.GetFiles: { IEnumerable <FileInfoVm> files = await filesService.GetFilesInfoAsync(request.FilesIds).ConfigureAwait(false); response = new FilesInformationResponse(request.RequestId, files); } break; default: response = new ResultNodeResponse(request.RequestId, ObjectsLibrary.Enums.ErrorCode.InvalidRequestData, "Unsupported request type."); break; } } catch { response = new ResultNodeResponse(request.RequestId, ObjectsLibrary.Enums.ErrorCode.UnknownError, "An error occurred while processing the request."); } NodeWebSocketCommunicationManager.SendResponse(response, nodeConnection); }
private async void HandleRequest(NodeRequest request, NodeConnection current) { try { ICommunicationHandler requestHandler = null; switch (request.RequestType) { case NodeRequestType.CheckToken: { requestHandler = new CheckTokenRequestHandler(request, current, appServiceProvider.TokensService, appServiceProvider.LoadUsersService); } break; case NodeRequestType.Connect: { requestHandler = new ConnectRequestHandler( request, current, appServiceProvider.ConnectionsService, appServiceProvider.NodesService, appServiceProvider.NodeNoticeService); } break; case NodeRequestType.GetInfoBlocks: { requestHandler = new GetInfoBlocksRequestHandler(request, current); } break; case NodeRequestType.GetMessages: { requestHandler = new GetMessagesRequestHandler(request, current, appServiceProvider.LoadMessagesService, appServiceProvider.ConversationsService); } break; case NodeRequestType.Proxy: { requestHandler = new ProxyUsersCommunicationsNodeRequestHandler(request, current, appServiceProvider); } break; case NodeRequestType.GetUsers: case NodeRequestType.GetChats: case NodeRequestType.GetChannels: case NodeRequestType.GetFiles: { requestHandler = new GetObjectsInfoNodeRequestHandler(request, current, appServiceProvider.LoadChatsService, appServiceProvider.LoadUsersService, appServiceProvider.LoadChannelsService, appServiceProvider.PrivacyService, appServiceProvider.FilesService); } break; case NodeRequestType.Search: { requestHandler = new SearchNodeRequestHandler(request, current, appServiceProvider.LoadChatsService, appServiceProvider.LoadUsersService, appServiceProvider.LoadChannelsService, appServiceProvider.PrivacyService); } break; case NodeRequestType.GetFullChatInformation: { requestHandler = new GetFullChatInformationNodeRequestHandler(request, current, appServiceProvider.LoadChatsService); } break; case NodeRequestType.GetChatUsersInformation: { requestHandler = new GetChatUsersInformationNodeRequestHandler(request, current, appServiceProvider.LoadChatsService); } break; case NodeRequestType.GetPublicKey: { requestHandler = new GetPublicKeyNodeRequestHandler(request, current, appServiceProvider.KeysService); } break; case NodeRequestType.GetPolls: { requestHandler = new GetPollInformationNodeRequestHandler(request, current, appServiceProvider.PollsService); } break; case NodeRequestType.BatchPhonesSearch: { requestHandler = new BatchPhonesSearchNodeRequestHandler(request, current, appServiceProvider.LoadUsersService, appServiceProvider.PrivacyService); } break; case NodeRequestType.GetConversationsUsers: { requestHandler = new GetConversationsUsersNodeRequestHandler(request, current, appServiceProvider.LoadChannelsService, appServiceProvider.LoadChatsService); } break; } if (requestHandler.IsObjectValid()) { await requestHandler.HandleAsync().ConfigureAwait(false); } else { ResultNodeResponse response = new ResultNodeResponse(request.RequestId, ErrorCode.InvalidRequestData); SendResponse(response, current); } } catch (Exception ex) { Logger.WriteLog(ex); } }