Ejemplo n.º 1
0
        /// <summary>
        ///   Starts reading messages from the remote peer.
        /// </summary>
        public async void ReadMessages(CancellationToken cancel)
        {
            log.Debug($"start reading messsages from {RemoteAddress}");

            // TODO: Only a subset of protocols are allowed until
            // the remote is authenticated.
            IPeerProtocol protocol = new Multistream1();

            try
            {
                while (!cancel.IsCancellationRequested && Stream != null)
                {
                    await protocol.ProcessMessageAsync(this, Stream, cancel);
                }
            }
            catch (IOException e)
            {
                log.Error("reading message failed " + e.Message);
                // eat it.
            }
            catch (Exception e)
            {
                if (!cancel.IsCancellationRequested && Stream != null)
                {
                    log.Error("reading message failed", e);
                }
            }

            Stream?.Dispose();
            log.Debug($"stop reading messsages from {RemoteAddress}");
        }
Ejemplo n.º 2
0
        /// <summary>
        ///   Starts reading messages from the remote peer on the specified stream.
        /// </summary>
        public async void ReadMessages(Stream stream, CancellationToken cancel)
        {
            IPeerProtocol protocol = new Multistream1();

            try
            {
                while (!cancel.IsCancellationRequested && stream != null && stream.CanRead)
                {
                    await protocol.ProcessMessageAsync(this, stream, cancel);
                }
            }
            catch (EndOfStreamException)
            {
                // eat it.
            }
            catch (Exception e)
            {
                if (!cancel.IsCancellationRequested && stream != null)
                {
                    log.Error($"reading message failed {RemoteAddress} {RemotePeer}", e);
                }
            }
        }