Search in sources :

Example 1 with MalformedRLPInputException

use of org.hyperledger.besu.ethereum.rlp.MalformedRLPInputException in project besu by hyperledger.

the class PongPacketData method readFrom.

public static PongPacketData readFrom(final RLPInput in) {
    in.enterList();
    final Endpoint to = Endpoint.decodeStandalone(in);
    final Bytes hash = in.readBytes();
    final long expiration = in.readLongScalar();
    UInt64 enrSeq = null;
    if (!in.isEndOfCurrentList()) {
        try {
            enrSeq = UInt64.valueOf(in.readBigIntegerScalar());
            LOG.debug("read PONG enr from scalar");
        } catch (MalformedRLPInputException malformed) {
            LOG.debug("failed to read PONG enr from scalar, trying as byte array");
            enrSeq = UInt64.fromBytes(in.readBytes());
        }
    }
    in.leaveListLenient();
    return new PongPacketData(to, hash, expiration, enrSeq);
}
Also used : Bytes(org.apache.tuweni.bytes.Bytes) Endpoint(org.hyperledger.besu.ethereum.p2p.discovery.Endpoint) MalformedRLPInputException(org.hyperledger.besu.ethereum.rlp.MalformedRLPInputException) UInt64(org.apache.tuweni.units.bigints.UInt64)

Example 2 with MalformedRLPInputException

use of org.hyperledger.besu.ethereum.rlp.MalformedRLPInputException in project besu by hyperledger.

the class PingPacketData method readFrom.

public static PingPacketData readFrom(final RLPInput in) {
    in.enterList();
    // The first element signifies the "version", but this value is ignored as of EIP-8
    in.readBigIntegerScalar();
    Optional<Endpoint> from = Optional.empty();
    Optional<Endpoint> to = Optional.empty();
    if (in.nextIsList()) {
        to = Endpoint.maybeDecodeStandalone(in);
        // https://github.com/ethereum/devp2p/blob/master/discv4.md#ping-packet-0x01
        if (in.nextIsList()) {
            // if there are two, the first is the from address, next is the to
            // address
            from = to;
            to = Endpoint.maybeDecodeStandalone(in);
        }
    } else {
        throw new DevP2PException("missing address in ping packet");
    }
    final long expiration = in.readLongScalar();
    UInt64 enrSeq = null;
    if (!in.isEndOfCurrentList()) {
        try {
            enrSeq = UInt64.valueOf(in.readBigIntegerScalar());
            LOG.debug("read PING enr as long scalar");
        } catch (MalformedRLPInputException malformed) {
            LOG.debug("failed to read PING enr as scalar, trying to read bytes instead");
            enrSeq = UInt64.fromBytes(in.readBytes());
        }
    }
    in.leaveListLenient();
    return new PingPacketData(from, to.get(), expiration, enrSeq);
}
Also used : Endpoint(org.hyperledger.besu.ethereum.p2p.discovery.Endpoint) MalformedRLPInputException(org.hyperledger.besu.ethereum.rlp.MalformedRLPInputException) UInt64(org.apache.tuweni.units.bigints.UInt64)

Aggregations

UInt64 (org.apache.tuweni.units.bigints.UInt64)2 Endpoint (org.hyperledger.besu.ethereum.p2p.discovery.Endpoint)2 MalformedRLPInputException (org.hyperledger.besu.ethereum.rlp.MalformedRLPInputException)2 Bytes (org.apache.tuweni.bytes.Bytes)1