public ChannelPairing(IActiveChannel external, IConnection connection, ListenerForProxying parent)
 {
     _external   = external.Required(nameof(external));
     _parent     = parent.Required(nameof(parent));
     _tagAsILInt = new ReadOnlySequence <byte>(connection.MessageTag.AsILInt());
     _proxied    = connection.AllocateChannel(this);
 }
Ejemplo n.º 2
0
 protected void Send(IActiveChannel channel, ILTag payload)
 {
     try {
         channel.Send(ToMessage(payload));
     } catch (SocketException) {
         // Do Nothing
     }
 }
Ejemplo n.º 3
0
        public void SendPing(IActiveChannel channel, bool visible = false)
        {
            var ping = new PingData(NodeId, DateTimeOffset.Now, SupportedNetworkProtocolFeatures.ToArray())
            {
                Visible = visible
            };

            Send(channel, ping.AsPayload);
        }
Ejemplo n.º 4
0
 private void Start(IActiveChannel channel)
 => Task.Run(() => {
     try {
         while (channel.Connected)
         {
             _clientProcessor.SendPing(channel);
             Task.Delay(1000).Wait();
         }
     } catch {
     } finally {
         Alive = false;
     }
 }).RunOnThread("Liveness");
Ejemplo n.º 5
0
 public abstract Task <Success> SinkAsync(ReadOnlySequence <byte> messageBytes, IActiveChannel channel);
 public override Task <Success> SinkAsync(ReadOnlySequence <byte> messageBytes, IActiveChannel channel)
 {
     _queue.Enqueue((messageBytes, channel));
     return(Task.FromResult(Success.Next));
 }
Ejemplo n.º 7
0
 public override async Task <Success> SinkAsync(IEnumerable <byte> message, IActiveChannel activeChannel)
 => Received(await Process(message, activeChannel.Channel));
Ejemplo n.º 8
0
 public Task <Success> SinkAsync(IEnumerable <byte> message, IActiveChannel channel) => Task.FromResult(Success.Next);
Ejemplo n.º 9
0
 public override Task <Success> SinkAsync(IEnumerable <byte> message, IActiveChannel channel)
 {
     _queue.Enqueue((message, channel));
     return(Task.FromResult(Success.Next));
 }
 public override async Task <Success> SinkAsync(ReadOnlySequence <byte> messageBytes, IActiveChannel activeChannel)
 => Received(await Process(messageBytes, activeChannel.Channel));
#pragma warning restore CA2253 // Named placeholders should not be numeric values

        public override Task <Success> SinkAsync(ReadOnlySequence <byte> messageBytes, IActiveChannel channel)
        => DoAsync(async() => {
 public void LogSinked(ReadOnlySequence <byte> message, IActiveChannel channel, bool newPair, ulong proxiedChannelId, bool sent)
 => _logger.LogDebug("Sinked Message '{0}' from Channel {1} using {2} pair to Proxied Channel {3}. Sent: {4}", message.ToUrlSafeBase64(), channel, newPair ? "new" : "existing", proxiedChannelId, sent);
 public void LogResponded(ReadOnlySequence <byte> message, IActiveChannel channel, ulong externalChannelId, bool sent)
 => _logger.LogDebug("Responded with Message '{0}' from Channel {1} to External Channel {2}. Sent: {3}", message.ToUrlSafeBase64(), channel, externalChannelId, sent);
#pragma warning disable CA2253 // Named placeholders should not be numeric values

        public void LogError(ReadOnlySequence <byte> message, IActiveChannel channel, Exception e)
        => _logger.LogError(e, "Error processing Message '{0}' from Channel {1}:{2}", message.ToUrlSafeBase64(), channel?.ToString() ?? "?", e.Message);
            public async Task <Success> SinkAsync(ReadOnlySequence <byte> messageBytes, IActiveChannel channel)
            {
                return(await SinkThisAsync(messageBytes.Realloc(), channel));

                async Task <Success> SinkThisAsync(ReadOnlySequence <byte> messageBytes, IActiveChannel channel)
                {
                    try {
                        var sent = await _external.SendAsync(PrependTagAndLength(messageBytes));

                        _parent.Responded(messageBytes, channel, _external.Channel, sent);
                    } catch (Exception e) {
                        _parent.Errored(messageBytes, channel, e);
                    }
                    return(Success.Next);
                }
            }