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); }
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)); }
public static Message ReadNext(Stream stream, Network network, ProtocolVersion version, CancellationToken cancellationToken, out PerformanceCounter counter) { return(ReadNext(stream, network, version, cancellationToken, null, out counter)); }
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); }