Example #1
0
        public static Message ReadNext(Stream stream, Network network, ProtocolVersion version, CancellationToken cancellationToken, byte[] buffer, out PerformanceCounter counter)
        {
            BitcoinStream bitStream = new BitcoinStream(stream, false)
            {
                ProtocolVersion       = version,
                ReadCancellationToken = cancellationToken
            };

            if (!network.ReadMagic(stream, cancellationToken, true))
            {
                throw new FormatException("Magic incorrect, the message comes from another network");
            }

            Message message = new Message();

            message._Buffer = buffer;
            using (message.SkipMagicScope(true))
            {
                message.Magic = network.Magic;
                message.ReadWrite(bitStream);
            }
            counter = bitStream.Counter;
            return(message);
        }
Example #2
0
        public static Message ReadNext(Socket socket, Network network, ProtocolVersion version, CancellationToken cancellationToken, byte[] buffer, out PerformanceCounter counter)
        {
            var stream = new NetworkStream(socket, false);

            return(ReadNext(stream, network, version, cancellationToken, buffer, out counter));
        }
Example #3
0
 public static Message ReadNext(Stream stream, Network network, ProtocolVersion version, CancellationToken cancellationToken, out PerformanceCounter counter)
 {
     return(ReadNext(stream, network, version, cancellationToken, null, out counter));
 }
Example #4
0
        public static Message ReadNext(Socket socket, Network network, ProtocolVersion version, CancellationToken cancellationToken, out PerformanceCounter counter)
        {
            var           stream    = new NetworkStream(socket, false);
            BitcoinStream bitStream = new BitcoinStream(stream, false)
            {
                ProtocolVersion       = version,
                ReadCancellationToken = cancellationToken
            };

            network.ReadMagic(stream, cancellationToken);

            Message message = new Message();

            using (message.SkipMagicScope(true))
            {
                message.Magic = network.Magic;
                message.ReadWrite(bitStream);
            }
            counter = bitStream.Counter;
            return(message);
        }