001/**
002 * Copyright 2012 Matt Corallo
003 *
004 * Licensed under the Apache License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 *
008 *    http://www.apache.org/licenses/LICENSE-2.0
009 *
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 * See the License for the specific language governing permissions and
014 * limitations under the License.
015 */
016
017package com.google.bitcoin.core;
018
019import java.io.IOException;
020import java.io.OutputStream;
021
022public class Pong extends Message {
023    /** The smallest protocol version that supports the pong response (BIP 31). Anything beyond version 60000. */
024    public static final int MIN_PROTOCOL_VERSION = 60001;
025
026    private long nonce;
027
028    public Pong(NetworkParameters params, byte[] payloadBytes) throws ProtocolException {
029        super(params, payloadBytes, 0);
030    }
031    
032    /**
033     * Create a Pong with a nonce value.
034     * Only use this if the remote node has a protocol version > 60000
035     */
036    public Pong(long nonce) {
037        this.nonce = nonce;
038    }
039    
040    @Override
041    void parse() throws ProtocolException {
042        nonce = readInt64();
043        length = 8;
044    }
045    
046    public void bitcoinSerializeToStream(OutputStream stream) throws IOException {
047        Utils.int64ToByteStreamLE(nonce, stream);
048    }
049    
050    @Override
051    protected void parseLite() {
052    }
053    
054    long getNonce() {
055        return nonce;
056    }
057}