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
FieldsFields inherited from interface org.drasyl.handler.remote.protocol.RemoteMessage
MAGIC_NUMBER -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidclose()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.Returns a copy of this message with incrementedRemoteMessage.getHopCount().static ArmedProtocolMessageof(Nonce nonce, HopCount hopCount, int networkId, DrasylAddress recipient, DrasylAddress sender, ProofOfWork proofOfWork, io.netty.buffer.ByteBuf bytes) Creates an armed message.intrefCnt()booleanrelease()booleanrelease(int decrement) io.netty.util.ReferenceCountedretain()io.netty.util.ReferenceCountedretain(int increment) io.netty.util.ReferenceCountedtouch()io.netty.util.ReferenceCountedvoidwriteTo(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.PartialReadMessage
getBytesMethods 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
-
close
public void close()Description copied from interface:PartialReadMessageCallsReferenceCounted.release().- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfacePartialReadMessage
-
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
-
incrementHopCount
Returns a copy of this message with incrementedRemoteMessage.getHopCount().ReferenceCounted.release()ownership ofgetBytes()is transferred to thisPartialReadMessage.- Specified by:
incrementHopCountin 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- theSessionPairto 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- theSessionPairto 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:RemoteMessageWrites this message to the bufferout.- Specified by:
writeToin 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 ofbytesis transferred to thisPartialReadMessage.Modifying the content of
bytesor 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 ofsenderbytes- the message's remaining armed bytes- Throws:
NullPointerException- ifnonce,sender,proofOfWork,recipient,hopCount,agreementId, orbytesisnull
-