Search in sources :

Example 81 with DataFormatException

use of net.i2p.data.DataFormatException in project i2p.i2p by i2p.

the class RequestLeaseSetMessage method doWriteMessage.

@Override
protected byte[] doWriteMessage() throws I2CPMessageException, IOException {
    if (_sessionId == null)
        throw new I2CPMessageException("Unable to write out the message as there is not enough data");
    ByteArrayOutputStream os = new ByteArrayOutputStream(256);
    try {
        _sessionId.writeBytes(os);
        DataHelper.writeLong(os, 1, _endpoints.size());
        for (int i = 0; i < _endpoints.size(); i++) {
            Hash router = getRouter(i);
            router.writeBytes(os);
            TunnelId tunnel = getTunnelId(i);
            tunnel.writeBytes(os);
        }
        DataHelper.writeDate(os, _end);
    } catch (DataFormatException dfe) {
        throw new I2CPMessageException("Error writing out the message data", dfe);
    }
    return os.toByteArray();
}
Also used : DataFormatException(net.i2p.data.DataFormatException) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Hash(net.i2p.data.Hash) TunnelId(net.i2p.data.TunnelId)

Example 82 with DataFormatException

use of net.i2p.data.DataFormatException in project i2p.i2p by i2p.

the class RequestVariableLeaseSetMessage method doReadMessage.

@Override
protected void doReadMessage(InputStream in, int size) throws I2CPMessageException, IOException {
    try {
        if (_sessionId != null)
            throw new IllegalStateException();
        _sessionId = new SessionId();
        _sessionId.readBytes(in);
        int numTunnels = (int) DataHelper.readLong(in, 1);
        for (int i = 0; i < numTunnels; i++) {
            Lease lease = new Lease();
            lease.readBytes(in);
            _endpoints.add(lease);
        }
    } catch (DataFormatException dfe) {
        throw new I2CPMessageException("Unable to load the message data", dfe);
    }
}
Also used : DataFormatException(net.i2p.data.DataFormatException) Lease(net.i2p.data.Lease)

Example 83 with DataFormatException

use of net.i2p.data.DataFormatException in project i2p.i2p by i2p.

the class RequestVariableLeaseSetMessage method doWriteMessage.

@Override
protected byte[] doWriteMessage() throws I2CPMessageException, IOException {
    if (_sessionId == null)
        throw new I2CPMessageException("No data");
    ByteArrayOutputStream os = new ByteArrayOutputStream(256);
    try {
        _sessionId.writeBytes(os);
        DataHelper.writeLong(os, 1, _endpoints.size());
        for (int i = 0; i < _endpoints.size(); i++) {
            _endpoints.get(i).writeBytes(os);
        }
    } catch (DataFormatException dfe) {
        throw new I2CPMessageException("Error writing out the message data", dfe);
    }
    return os.toByteArray();
}
Also used : DataFormatException(net.i2p.data.DataFormatException) ByteArrayOutputStream(java.io.ByteArrayOutputStream)

Example 84 with DataFormatException

use of net.i2p.data.DataFormatException in project i2p.i2p by i2p.

the class SendMessageMessage method readMessage.

/**
 * Read the body into the data structures
 *
 * @throws IOException
 */
@Override
public void readMessage(InputStream in, int length, int type) throws I2CPMessageException, IOException {
    if (type != getType())
        throw new I2CPMessageException("Invalid message type (found: " + type + " supported: " + getType() + " class: " + getClass().getName() + ")");
    if (length < 0)
        throw new IOException("Negative payload size");
    try {
        _sessionId = new SessionId();
        _sessionId.readBytes(in);
        _destination = Destination.create(in);
        _payload = new Payload();
        _payload.readBytes(in);
        _nonce = DataHelper.readLong(in, 4);
    } catch (DataFormatException dfe) {
        throw new I2CPMessageException("Unable to load the message data", dfe);
    }
}
Also used : DataFormatException(net.i2p.data.DataFormatException) Payload(net.i2p.data.Payload) IOException(java.io.IOException)

Example 85 with DataFormatException

use of net.i2p.data.DataFormatException in project i2p.i2p by i2p.

the class SessionConfig method writeBytes.

public void writeBytes(OutputStream out) throws DataFormatException, IOException {
    if ((_destination == null) || (_options == null) || (_signature == null) || (_creationDate == null))
        throw new DataFormatException("Not enough data to create the session config");
    _destination.writeBytes(out);
    // UTF-8
    DataHelper.writeProperties(out, _options, true);
    DataHelper.writeDate(out, _creationDate);
    _signature.writeBytes(out);
}
Also used : DataFormatException(net.i2p.data.DataFormatException)

Aggregations

DataFormatException (net.i2p.data.DataFormatException)112 IOException (java.io.IOException)53 Destination (net.i2p.data.Destination)32 Properties (java.util.Properties)19 ByteArrayOutputStream (java.io.ByteArrayOutputStream)17 FileInputStream (java.io.FileInputStream)16 Hash (net.i2p.data.Hash)14 File (java.io.File)13 SigType (net.i2p.crypto.SigType)13 I2PSessionException (net.i2p.client.I2PSessionException)12 InputStream (java.io.InputStream)11 PrivateKey (net.i2p.data.PrivateKey)11 SigningPrivateKey (net.i2p.data.SigningPrivateKey)11 SigningPublicKey (net.i2p.data.SigningPublicKey)11 RouterInfo (net.i2p.data.router.RouterInfo)11 Signature (net.i2p.data.Signature)10 FileOutputStream (java.io.FileOutputStream)8 InterruptedIOException (java.io.InterruptedIOException)8 HashMap (java.util.HashMap)8 PublicKey (net.i2p.data.PublicKey)8