public async Task SendAfterInit() { this.RegisterType <RequestSenderService>(); ContextGetterBuilder.Build(Container); var msession = this.BuildClientSettingsProps(); msession.Object.ClientSession.AuthKey = new AuthKey(Fixture.CreateMany <byte>(256).ToArray()); var mContext = this.Resolve <Mock <IChannelHandlerContext> >(); var mRequestService = this.Resolve <Mock <IRequestService> >(); var requestPing = new RequestPing(); //-- var requestSender = this.Resolve <RequestSenderService>(); await requestSender.SendRequestAsync(requestPing, CancellationToken.None); //-- mContext.Verify(context => context.WriteAndFlushAsync(requestPing), Times.Once); mRequestService.Verify(context => context.RegisterRequest(requestPing, It.IsAny <CancellationToken>()), Times.Once); }
public void HandleError(int errorCode) { this.BuildClientSettingsProps(); this.RegisterType <BadMsgNotificationHandler>(); var requestEncoder = this.Resolve <BadMsgNotificationHandler>(); var channel = new EmbeddedChannel(requestEncoder); var messageId = Fixture.Create <long>(); var badServerSalt = new TBadMsgNotification { BadMsgId = messageId, BadMsgSeqno = Fixture.Create <int>(), ErrorCode = errorCode }; var request = new RequestPing(); badServerSalt.ErrorCode = errorCode; var mRequestService = this.Resolve <Mock <IRequestService> >(); mRequestService.BuildGetRequestToReply(messageId, request); // --- channel.WriteInbound(badServerSalt); // --- Assert.Equal(request, channel.ReadOutbound <RequestPing>()); }
public void WaitForInitizalize() { this.RegisterType <RequestSenderService>(); var mSettings = this.BuildClientSettingsProps(); mSettings.Object.ClientSession.AuthKey = null; var mContextGetter = this.Resolve <Mock <IContextGetter> >(); var resultTaskSource = new TaskCompletionSource <object>(); var request = new RequestPing(); this.Resolve <Mock <IRequestService> >() .BuildRegisterRequest <RequestPing>(resultTaskSource.Task); var senderService = this.Resolve <RequestSenderService>(); // --- var resultTask = senderService.SendRequestAsync(request, CancellationToken.None); // --- Assert.Equal(TaskStatus.WaitingForActivation, resultTask.Status); mContextGetter.Verify(getter => getter.Context, Times.Never); }
public void SendPing(int cid = 0) { RequestPing rp = new RequestPing { Cid = cid }; string msg = CBitfinexJsonSerializer.SerializeObject(rp); SendMessage(msg); }
public async Task SendPing() { var requestPing = new RequestPing { PingId = Random.NextLong() }; var pong = await ClientApi.CustomRequestsService.SendRequestAsync(requestPing, CancellationToken.None).ConfigureAwait(false); Assert.Equal(requestPing.PingId, pong.PingId); }
public async Task <string> GetRealIP(string IPorDomain) { string sResult = IPorDomain; if (!CheckValidIP(IPorDomain)) { RequestPing P = new RequestPing(); ReturnPing RV = await P.getRequestPingObj(IPorDomain); sResult = RV.Address; } return(sResult); }
/// <inheritdoc /> public void KeepAliveConnection() { _keepAliveTimer = new Timer( _ => { var requestPing = new RequestPing { PingId = new Random().NextLong() }; CustomRequestsService.SendRequestAsync(requestPing, CancellationToken.None).ConfigureAwait(false); }, null, TimeSpan.FromMinutes(1), TimeSpan.FromHours(0)); }
// Ping private void MessagePing(MessageInfo messageInfo) { RequestPing requestPing = ProtoTransfer.DeserializeProtoBuf3 <RequestPing>(messageInfo.Buffer); User user = UserManager.Instance.GetUserByToken(requestPing.Token); if (user != null) { ResponsePing responsePing = new ResponsePing() { Uid = user.Id, Token = user.Token }; MessageBuffer _message = new MessageBuffer((int)MessageID.ScResponsePing, ProtoTransfer.SerializeProtoBuf3(responsePing), user.Id); Send(new MessageInfo(_message, messageInfo.Session)); } }
public async Task Send_SimpleCall_NotThrows() { const ulong SendMessageId = 1234; var authKey = SessionMock.GenerateAuthKeyData(); ulong sessionId = 1231231; ulong salt = 5432111; var seqNo = 123; var mSession = SessionMock.Create() .BuildGenerateMessageSeqNo(confirm => Tuple.Create(SendMessageId, seqNo)) .BuildSession(sessionId, salt, authKey); var request = new RequestPing(); var mTcpTransport = TcpTransportMock.Create(); AddSendHandler(mTcpTransport, request); this.RegisterMock(mTcpTransport); var mClientSettings = ClientSettingsMock.Create().AttachSession(() => mSession.Object); this.RegisterMock(mClientSettings); var mConfirmRecieve = ConfirmationRecieveServiceMock.Create() .BuildWaitForConfirm(messageId => { Assert.Equal(SendMessageId, messageId); return(Task.FromResult(true)); }); this.RegisterMock(mConfirmRecieve); this.RegisterType <MtProtoSendService>(); // --- var mtProtoPlainSender = this.Resolve <MtProtoSendService>(); var sendResult = mtProtoPlainSender.Send(request); await sendResult.Result.Item1; // -- mTcpTransport.Verify(transport => transport.Send(It.IsAny <byte[]>()), Times.Once); mConfirmRecieve.Verify(store => store.WaitForConfirm(It.IsAny <ulong>()), Times.Once); }
public static RequestPing QueryRequestPingAbg(PingModel objectItem) { //RequestPing var requestPing = new RequestPing(); //RequestPing - OTA_PingRQ var otaPingRq = new OTA_PingRQ(); otaPingRq.EchoToken = Guid.NewGuid().ToString(); otaPingRq.Version = objectItem.Version; //RequestPing - OTA_PingRQ - EchoData otaPingRq.EchoData = objectItem.Message; requestPing.OTA_PingRQ = otaPingRq; return(requestPing); }
public void SendAfterInit() { this.RegisterType <TopHandlerAdapter>(); var mSettings = this.BuildClientSettingsProps(); var authKey = mSettings.Object.ClientSession.AuthKey; var resultTaskSource = new TaskCompletionSource <object>(); var request = new RequestPing(); var response = new TPong(); var config = new TConfig { DcOptions = new TVector <IDcOption>() }; this.Resolve <Mock <IRequestService> >() .BuildGetAllRequestToReply(request) .BuildRegisterRequest <RequestInvokeWithLayer>(Task.FromResult((object)config)); var handlerAdapter = this.Resolve <TopHandlerAdapter>(); // --- mSettings.Object.ClientSession.AuthKey = null; var channel = new EmbeddedChannel(handlerAdapter); mSettings.Object.ClientSession.AuthKey = authKey; channel.Pipeline.FireUserEventTriggered(ESystemNotification.HandshakeComplete); resultTaskSource.SetResult(response); // --- Assert.NotNull(channel.ReadOutbound <RequestInvokeWithLayer>()); Assert.Equal(request, channel.ReadOutbound <RequestPing>()); }
public async Task RepeatSendMessage() { this.RegisterType <BadServerSaltHandler>(); this.BuildClientSettingsProps(); const int BadMsgId = 1; var request = new RequestPing(); this.Resolve <Mock <ISessionWriter> >() .BuildSuccessSave(); var mRequestService = this.Resolve <Mock <IRequestService> >(); mRequestService.Setup(rs => rs.GetRequestToReply(BadMsgId)) .Returns(() => request); var requestEncoder = this.Resolve <BadServerSaltHandler>(); var channel = new EmbeddedChannel(requestEncoder); var badServerSalt = new TBadServerSalt { BadMsgId = BadMsgId, NewServerSalt = Random.NextLong() }; // --- channel.WriteInbound(badServerSalt); await Task.Delay(500).ConfigureAwait(false); // --- Assert.Equal(request, channel.ReadOutbound <object>()); }
public async Task InvokeAsync(HttpContext context, AppDbContext dbContext, IAppLogger appLogger) { var response = ""; // log only this endpoint traffic if (context.Request.Path.StartsWithSegments(_endpointPath, StringComparison.Ordinal)) { Console.WriteLine( $"Request for {context.Request.Path} received ({context.Request.ContentLength ?? 0} bytes). Client ip: {context.Connection.RemoteIpAddress}"); await appLogger.DebugAsync("request", $"Request for {context.Request.Path} received ({context.Request.ContentLength ?? 0} bytes). Client ip: {context.Connection.RemoteIpAddress}"); } // p2p responses - who do we know already if (context.Request.Path.StartsWithSegments(_endpointPath + "/addr", StringComparison.Ordinal)) { response = await RequestAddr.Response(dbContext, context); } // p2p responses - ping if (context.Request.Path.StartsWithSegments(_endpointPath + "/ping", StringComparison.Ordinal)) { response = await RequestPing.Response(dbContext, context, _publicKey); } // ledger - get blocks from start to end if (context.Request.Path.StartsWithSegments(_endpointPath + "/blocks", StringComparison.Ordinal)) { response = await RequestBlocks.Response(dbContext, context); } // ledger - merkle root of current ledger if (context.Request.Path.StartsWithSegments(_endpointPath + "/info", StringComparison.Ordinal)) { response = await RequestInfo.Response(dbContext, context); } if (context.Request.Path.StartsWithSegments(_endpointPath + "/singleblock", StringComparison.Ordinal)) { response = await RequestSingleBlock.Response(dbContext, context); } if (context.Request.Path.StartsWithSegments(_endpointPath + "/createblock", StringComparison.Ordinal)) // && context.Request.Method == "POST" { response = await RequestCreateBlock.Response(dbContext, context, _publicKey, _privateKey, _dbLock); } if (context.Request.Path.StartsWithSegments(_endpointPath + "/receiveblock", StringComparison.Ordinal) && context.Request.Method == "POST") { response = await RequestReceiveBlock.Response(dbContext, context, _publicKey, _privateKey, _dbLock); } if (context.Request.Path.StartsWithSegments(_endpointPath + "/receiveledger", StringComparison.Ordinal) && context.Request.Method == "POST") { response = await RequestReceiveLedger.Response(dbContext, context, _publicKey, _privateKey, _dbLock); } // ledger - get one specific block // this has to be final for logging to work correctly if (context.Request.Path.StartsWithSegments(_endpointPath + "/log", StringComparison.Ordinal)) { response = await RequestLog.Response(dbContext); } else if (!string.IsNullOrWhiteSpace(response)) { await appLogger.DebugAsync($"response - {context.Request.Path}", response); } //allow ajax requests from browsers context.Response.Headers.Add("Access-Control-Allow-Origin", "*"); context.Response.Headers.Add("Access-Control-Allow-Methods", "POST, GET, OPTIONS, DELETE"); if (!string.IsNullOrWhiteSpace(response)) { await context.Response.WriteAsync(response); } // Call the next delegate/middleware in the pipeline if (_next != null) { await _next(context); } /* * if (context.Request.Path.StartsWithSegments(_endpointPath, StringComparison.Ordinal)) * { * await context.Response.WriteAsync("------- After Ledger ------"); * } */ }