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).
-
Field Summary
Fields inherited from interface org.drasyl.handler.remote.protocol.RemoteMessage
MAGIC_NUMBER, MAGIC_NUMBER_LEN
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionarm
(io.netty.buffer.ByteBufAllocator alloc, Crypto cryptoInstance, SessionPair sessionPair) Returns an armed version (ArmedProtocolMessage
) of this message for sending it through untrustworthy channels.void
close()
Callsrelease()
.io.netty.buffer.ByteBuf
encodeMessage
(io.netty.buffer.ByteBufAllocator alloc) Writes this message to a buffer created byalloc
.int
abstract io.netty.buffer.ByteBuf
Returns the payload.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
protected void
writeBodyTo
(io.netty.buffer.ByteBuf out) protected void
writePrivateHeaderTo
(io.netty.buffer.ByteBuf out) protected void
writePublicHeaderTo
(io.netty.buffer.ByteBuf out) 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
-
Field Details
-
HOP_COUNT
-
-
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 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
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) -
getLength
public int getLength()- Specified by:
getLength
in interfaceRemoteMessage
-
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
- 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
Callsrelease()
.- Specified by:
close
in interfaceAutoCloseable
- Throws:
Exception
-
arm
public ArmedProtocolMessage arm(io.netty.buffer.ByteBufAllocator alloc, 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<?>>
cryptoInstance
- 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
-
encodeMessage
public io.netty.buffer.ByteBuf encodeMessage(io.netty.buffer.ByteBufAllocator alloc) Description copied from interface:RemoteMessage
Writes this message to a buffer created byalloc
.- Specified by:
encodeMessage
in interfaceRemoteMessage
- Returns:
- the buffer written to
-
writePublicHeaderTo
protected void writePublicHeaderTo(io.netty.buffer.ByteBuf out)
-