Class ApplicationMessage
- java.lang.Object
-
- org.drasyl.handler.remote.protocol.ApplicationMessage
-
- All Implemented Interfaces:
io.netty.util.ReferenceCounted
,AutoCloseable
,FullReadMessage<ApplicationMessage>
,RemoteMessage
public abstract class ApplicationMessage extends Object implements io.netty.util.ReferenceCounted, AutoCloseable
Describes a message sent by an application running on drasyl. The message's body is structured as follows:- Payload: The payload sent by the application (any number of bytes).
This is an immutable object.
-
-
Field Summary
-
Fields inherited from interface org.drasyl.handler.remote.protocol.RemoteMessage
MAGIC_NUMBER
-
-
Constructor Summary
Constructors Constructor Description ApplicationMessage()
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description ArmedProtocolMessage
arm(io.netty.buffer.ByteBuf byteBuf, Crypto cryptoInstance, SessionPair sessionPair)
Returns an armed version (ArmedProtocolMessage
) of this message for sending it through untrustworthy channels.void
close()
Callsrelease()
.abstract io.netty.buffer.ByteBuf
getPayload()
Returns the payload.ApplicationMessage
incrementHopCount()
Returns this message with incremented hop count.static ApplicationMessage
of(int networkId, IdentityPublicKey recipient, IdentityPublicKey sender, ProofOfWork proofOfWork, io.netty.buffer.ByteBuf payload)
static ApplicationMessage
of(HopCount hopCount, boolean isArmed, int networkId, Nonce nonce, DrasylAddress recipient, DrasylAddress sender, ProofOfWork proofOfWork, io.netty.buffer.ByteBuf payload)
Creates new application message.int
refCnt()
boolean
release()
boolean
release(int decrement)
io.netty.util.ReferenceCounted
retain()
io.netty.util.ReferenceCounted
retain(int increment)
io.netty.util.ReferenceCounted
touch()
io.netty.util.ReferenceCounted
touch(Object hint)
protected void
writeBodyTo(io.netty.buffer.ByteBuf out)
protected void
writePrivateHeaderTo(io.netty.buffer.ByteBuf out)
protected void
writePublicHeaderTo(io.netty.buffer.ByteBuf out)
void
writeTo(io.netty.buffer.ByteBuf out)
Writes this message to the bufferout
.-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface org.drasyl.handler.remote.protocol.FullReadMessage
getRecipient
-
Methods inherited from interface org.drasyl.handler.remote.protocol.RemoteMessage
getArmed, getHopCount, getNetworkId, getNonce, getProofOfWork, getSender
-
-
-
-
Method Detail
-
of
public static ApplicationMessage of(HopCount hopCount, boolean isArmed, int networkId, Nonce nonce, DrasylAddress recipient, DrasylAddress sender, ProofOfWork proofOfWork, io.netty.buffer.ByteBuf payload)
Creates new application message.ReferenceCounted.release()
ownership ofgetPayload()
is transferred to thisPartialReadMessage
.- Parameters:
hopCount
- the hop countisArmed
- if the message is armed or notnetworkId
- the network idnonce
- the noncerecipient
- the public key of the recipientsender
- the public key of the senderproofOfWork
- the proof of work ofsender
payload
- the payload- Throws:
NullPointerException
- ifnonce
,sender
,proofOfWork
,recipient
,hopCount
, orpayload
isnull
-
of
public static ApplicationMessage of(int networkId, IdentityPublicKey recipient, IdentityPublicKey sender, ProofOfWork proofOfWork, io.netty.buffer.ByteBuf payload)
Creates new application message with randomNonce
, and minimalHopCount
value.ReferenceCounted.release()
ownership ofgetPayload()
is transferred to thisPartialReadMessage
.- Parameters:
networkId
- the network idrecipient
- the public key of the recipientsender
- the public key of the senderproofOfWork
- the proof of work ofsender
payload
- the payload- Throws:
NullPointerException
- ifsender
,proofOfWork
,recipient
, orpayload
isnull
-
getPayload
public abstract io.netty.buffer.ByteBuf getPayload()
Returns the payload.- Returns:
- the payload
-
incrementHopCount
public ApplicationMessage incrementHopCount()
Returns this message with incremented hop count.ReferenceCounted.release()
ownership ofgetPayload()
is transferred to thisPartialReadMessage
.- Specified by:
incrementHopCount
in interfaceFullReadMessage<ApplicationMessage>
- Specified by:
incrementHopCount
in interfaceRemoteMessage
- Returns:
-
writePrivateHeaderTo
protected void writePrivateHeaderTo(io.netty.buffer.ByteBuf out)
-
writeBodyTo
protected void writeBodyTo(io.netty.buffer.ByteBuf out)
-
refCnt
public int refCnt()
- Specified by:
refCnt
in interfaceio.netty.util.ReferenceCounted
-
retain
public io.netty.util.ReferenceCounted retain()
- Specified by:
retain
in interfaceio.netty.util.ReferenceCounted
-
retain
public io.netty.util.ReferenceCounted retain(int increment)
- Specified by:
retain
in interfaceio.netty.util.ReferenceCounted
-
touch
public io.netty.util.ReferenceCounted touch()
- Specified by:
touch
in interfaceio.netty.util.ReferenceCounted
-
touch
public io.netty.util.ReferenceCounted touch(Object hint)
- Specified by:
touch
in interfaceio.netty.util.ReferenceCounted
-
release
public boolean release()
- Specified by:
release
in interfaceio.netty.util.ReferenceCounted
-
release
public boolean release(int decrement)
- Specified by:
release
in interfaceio.netty.util.ReferenceCounted
-
close
public void close() throws Exception
Callsrelease()
.- Specified by:
close
in interfaceAutoCloseable
- Throws:
Exception
-
arm
public ArmedProtocolMessage arm(io.netty.buffer.ByteBuf byteBuf, Crypto cryptoInstance, SessionPair sessionPair) throws InvalidMessageFormatException
Description copied from interface:FullReadMessage
Returns an armed version (ArmedProtocolMessage
) of this message for sending it through untrustworthy channels.- Specified by:
arm
in interfaceFullReadMessage<T extends FullReadMessage<?>>
- Parameters:
byteBuf
- theByteBuf
to write throughcryptoInstance
- the crypto instance that should be usedsessionPair
- will be used for encryption- Returns:
- the armed version of this message
- Throws:
InvalidMessageFormatException
- if arming was not possible
-
writeTo
public void writeTo(io.netty.buffer.ByteBuf out)
Description copied from interface:RemoteMessage
Writes this message to the bufferout
.- Specified by:
writeTo
in interfaceRemoteMessage
- Parameters:
out
- writes this envelope to this buffer
-
writePublicHeaderTo
protected void writePublicHeaderTo(io.netty.buffer.ByteBuf out)
-
-