예제 #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);
        }
예제 #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));
        }
예제 #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));
 }
예제 #4
0
파일: Message.cs 프로젝트: pkahle/NBitcoin
        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);
        }