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 -
Method Summary
Modifier and TypeMethodDescriptionarm(io.netty.buffer.ByteBuf byteBuf, Crypto cryptoInstance, SessionPair sessionPair) Returns an armed version (ArmedProtocolMessage) of this message for sending it through untrustworthy channels.voidclose()Callsrelease().abstract io.netty.buffer.ByteBufReturns the payload.Returns this message with incremented hop count.static ApplicationMessageof(int networkId, IdentityPublicKey recipient, IdentityPublicKey sender, ProofOfWork proofOfWork, io.netty.buffer.ByteBuf payload) static ApplicationMessageof(HopCount hopCount, boolean isArmed, int networkId, Nonce nonce, DrasylAddress recipient, DrasylAddress sender, ProofOfWork proofOfWork, io.netty.buffer.ByteBuf payload) Creates new application message.intrefCnt()booleanrelease()booleanrelease(int decrement) io.netty.util.ReferenceCountedretain()io.netty.util.ReferenceCountedretain(int increment) io.netty.util.ReferenceCountedtouch()io.netty.util.ReferenceCountedprotected voidwriteBodyTo(io.netty.buffer.ByteBuf out) protected voidwritePrivateHeaderTo(io.netty.buffer.ByteBuf out) protected voidwritePublicHeaderTo(io.netty.buffer.ByteBuf out) voidwriteTo(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, waitMethods inherited from interface org.drasyl.handler.remote.protocol.FullReadMessage
getRecipientMethods inherited from interface org.drasyl.handler.remote.protocol.RemoteMessage
getArmed, getHopCount, getNetworkId, getNonce, getProofOfWork, getSender
-
Constructor Details
-
ApplicationMessage
public ApplicationMessage()
-
-
Method Details
-
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 ofsenderpayload- the payload- Throws:
NullPointerException- ifnonce,sender,proofOfWork,recipient,hopCount, orpayloadisnull
-
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 minimalHopCountvalue.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 ofsenderpayload- the payload- Throws:
NullPointerException- ifsender,proofOfWork,recipient, orpayloadisnull
-
getPayload
public abstract io.netty.buffer.ByteBuf getPayload()Returns the payload.- Returns:
- the payload
-
incrementHopCount
Returns this message with incremented hop count.ReferenceCounted.release()ownership ofgetPayload()is transferred to thisPartialReadMessage.- Specified by:
incrementHopCountin interfaceFullReadMessage<ApplicationMessage>- Specified by:
incrementHopCountin 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:
refCntin interfaceio.netty.util.ReferenceCounted
-
retain
public io.netty.util.ReferenceCounted retain()- Specified by:
retainin interfaceio.netty.util.ReferenceCounted
-
retain
public io.netty.util.ReferenceCounted retain(int increment) - Specified by:
retainin interfaceio.netty.util.ReferenceCounted
-
touch
public io.netty.util.ReferenceCounted touch()- Specified by:
touchin interfaceio.netty.util.ReferenceCounted
-
touch
- Specified by:
touchin interfaceio.netty.util.ReferenceCounted
-
release
public boolean release()- Specified by:
releasein interfaceio.netty.util.ReferenceCounted
-
release
public boolean release(int decrement) - Specified by:
releasein interfaceio.netty.util.ReferenceCounted
-
close
Callsrelease().- Specified by:
closein interfaceAutoCloseable- Throws:
Exception
-
arm
public ArmedProtocolMessage arm(io.netty.buffer.ByteBuf byteBuf, Crypto cryptoInstance, SessionPair sessionPair) throws InvalidMessageFormatException Description copied from interface:FullReadMessageReturns an armed version (ArmedProtocolMessage) of this message for sending it through untrustworthy channels.- Specified by:
armin interfaceFullReadMessage<T extends FullReadMessage<?>>- Parameters:
byteBuf- theByteBufto 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:RemoteMessageWrites this message to the bufferout.- Specified by:
writeToin interfaceRemoteMessage- Parameters:
out- writes this envelope to this buffer
-
writePublicHeaderTo
protected void writePublicHeaderTo(io.netty.buffer.ByteBuf out)
-