public void OnReceive(IConnectionChannel channel, IConnectionSession session, byte[] bytes) { var factory = channel.Factory; var dispatcher = channel.Dispatcher; string crid = null; try { var message = Encoding.UTF8.GetString(bytes); MessageLogger.LogDebug($"Received: {message}"); var isError = false; var wrapper = factory.DeserializeMessage(message, out crid, ref isError); if (isError) { return; } if (!dispatcher.Dispatch(session, wrapper, (r, rc) => channel.Send(session, new ResponseMessage(r, r.GetType().Name, crid, (byte)rc)))) { channel.SendError(session, crid); } } catch (Exception e) { channel.SendError(session, crid); Logger.Log("ConnectionService ex:", e); } }
// TODO why here ? private void SendSignedNewLedgerNotification(IConnectionSession session) { var signedLedger = LedgerService.LedgerManager.GetSignedLedger(); var notification = NotificationHelper.CreateSignedNewLedgerNotification(signedLedger); ConnectionService.BlockchainChannel.Send(session, notification); }
public void ShouldOpen(IConnectionSession session) { if (shouldOpen(session)) { session.Session.OpenChannel(Channel); } }
public void Send(IConnectionSession session, NotificationMessage message) { var serialized = Factory.SerializeNotification(message); messageLogger.LogDebug($"Sent: {serialized}"); var bytes = Encoding.UTF8.GetBytes(serialized); Channel.Send(session.Session, bytes); }
public void Send(IConnectionSession session, ErrorMessage message) { var responseMessage = Factory.SerializeError(message); messageLogger.LogDebug($"Sent: {responseMessage}"); var bytes = Encoding.UTF8.GetBytes(responseMessage); Channel.Send(session.Session, bytes); }
void OnSessionEnded(IConnectionSession connection) { if (_contexts.TryRemove(connection, out IInstanceContext context)) { this.SessionInstanceRemoved?.Invoke(this, context); } else { //TODO log info } }
private bool TryRequest(IConnectionSession session, long incoming, long next) { if (preventHeight.HasValue && preventHeight.Value == next) { return(false); } // if incoming height is next or greater than next then request next if (next <= incoming) { targetHeight = incoming; ConnectionService.BlockchainChannel.Send(session, RequestHelper.CreateGetSignedLedgerRequest(next)); logger.Log($"CatchupManager : Requesting [{next} of {incoming}] "); preventHeight = next; return(true); } return(false); }
public SignedNewLedgerCommand(SignedNewLedger data, IConnectionSession session) : base(data) { this.session = session; }
// TODO Change name // we need to see if an incoming height is ahead of us public bool TryProcessIncomingHeight(IConnectionSession session, long incoming) { return(TryRequest(session, incoming, LedgerService.LedgerManager.GetNextHeight())); }
// TODO Change name // after we receive a ledger and we catch up public bool TryProcessHeight(IConnectionSession session) { return(TryProcessIncomingHeight(session, targetHeight)); }
public void Send(IConnectionSession session, Request request) { Send(session, new RequestMessage(request, request.GetType().Name, Guid.NewGuid().ToString("N"))); }
public void SendError(IConnectionSession session, string crid) { Send(session, new ErrorMessage(crid, (byte)ResultCode.Failed)); }