Class ArmedProtocolMessage
- All Implemented Interfaces:
io.netty.util.ReferenceCounted
,AutoCloseable
,PartialReadMessage
,RemoteMessage
Only the message recipient can decrypt and authenticate the message by calling
disarm(ByteBufAllocator, Crypto, SessionPair)
.
This is an immutable object.
-
Field Summary
Fields inherited from interface org.drasyl.handler.remote.protocol.RemoteMessage
MAGIC_NUMBER, MAGIC_NUMBER_LEN
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionvoid
close()
CallsReferenceCounted.release()
.disarm
(io.netty.buffer.ByteBufAllocator alloc, Crypto cryptoInstance, SessionPair sessionPair) Returns a disarmed version (FullReadMessage
) of this message.disarmAndRelease
(io.netty.buffer.ByteBufAllocator alloc, Crypto cryptoInstance, SessionPair sessionPair) Returns a disarmed version (FullReadMessage
) of this message and then releases this message.int
Returns a copy of this message with incrementedRemoteMessage.getHopCount()
.static ArmedProtocolMessage
of
(Nonce nonce, HopCount hopCount, int networkId, DrasylAddress recipient, DrasylAddress sender, ProofOfWork proofOfWork, io.netty.buffer.ByteBuf bytes) Creates an armed 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
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.PartialReadMessage
getBytes
Methods inherited from interface org.drasyl.handler.remote.protocol.RemoteMessage
getArmed, getHopCount, getNetworkId, getNonce, getProofOfWork, getRecipient, getSender
-
Field Details
-
ARMED_HEADER_LENGTH
public static final int ARMED_HEADER_LENGTH- See Also:
-
-
Constructor Details
-
ArmedProtocolMessage
public ArmedProtocolMessage()
-
-
Method Details
-
getLength
public int getLength()- Specified by:
getLength
in interfaceRemoteMessage
-
close
public void close()Description copied from interface:PartialReadMessage
CallsReferenceCounted.release()
.- Specified by:
close
in interfaceAutoCloseable
- Specified by:
close
in interfacePartialReadMessage
-
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
-
incrementHopCount
Returns a copy of this message with incrementedRemoteMessage.getHopCount()
.ReferenceCounted.release()
ownership ofgetBytes()
is transferred to thisPartialReadMessage
.- Specified by:
incrementHopCount
in interfaceRemoteMessage
- Returns:
- message with incremented hop count
-
disarm
public FullReadMessage<?> disarm(io.netty.buffer.ByteBufAllocator alloc, Crypto cryptoInstance, SessionPair sessionPair) throws InvalidMessageFormatException Returns a disarmed version (FullReadMessage
) of this message.Disarming will authenticate the nonce, network id, sender, sender's proof of work, recipient, agreement id, and decrypt all remaining bytes.
- Parameters:
alloc
-cryptoInstance
- the crypto instance that should be usedsessionPair
- theSessionPair
to decrypt this message- Returns:
- the disarmed version of this message
- Throws:
InvalidMessageFormatException
- if disarming was not possible
-
disarmAndRelease
public FullReadMessage<?> disarmAndRelease(io.netty.buffer.ByteBufAllocator alloc, Crypto cryptoInstance, SessionPair sessionPair) throws InvalidMessageFormatException Returns a disarmed version (FullReadMessage
) of this message and then releases this message.Disarming will authenticate the nonce, network id, sender, sender's proof of work, recipient, agreement id, and decrypt all remaining bytes.
- Parameters:
alloc
-cryptoInstance
- the crypto instance that should be usedsessionPair
- theSessionPair
to decrypt this message- Returns:
- the disarmed version of this message
- Throws:
InvalidMessageFormatException
- if disarming 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
-
of
public static ArmedProtocolMessage of(Nonce nonce, HopCount hopCount, int networkId, DrasylAddress recipient, DrasylAddress sender, ProofOfWork proofOfWork, io.netty.buffer.ByteBuf bytes) Creates an armed message.ReferenceCounted.release()
ownership ofbytes
is transferred to thisPartialReadMessage
.Modifying the content of
bytes
or the returned message's buffer affects each other's content while they maintain separate indexes and marks.- Parameters:
nonce
- the noncehopCount
- the hop countnetworkId
- the network idrecipient
- the public key of the recipientsender
- the public key of the senderproofOfWork
- the proof of work ofsender
bytes
- the message's remaining armed bytes- Throws:
NullPointerException
- ifnonce
,sender
,proofOfWork
,recipient
,hopCount
,agreementId
, orbytes
isnull
-