Class UnarmedProtocolMessage
java.lang.Object
org.drasyl.handler.remote.protocol.UnarmedProtocolMessage
- All Implemented Interfaces:
io.netty.util.ReferenceCounted,AutoCloseable,PartialReadMessage,RemoteMessage
Describes an unencrypted protocol message whose only public header has been read so far.
read() can be used to read the message's remainder.
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.ByteBufAllocator alloc, Crypto cryptoInstance, SessionPair sessionPair) Returns an armed version (ArmedProtocolMessage) of this message.armAndRelease(io.netty.buffer.ByteBufAllocator alloc, Crypto cryptoInstance, SessionPair sessionPair) Returns an armed version (ArmedProtocolMessage) of this message and then releases this message.voidclose()CallsReferenceCounted.release().abstract DrasylAddressReturns a copy of this message with incrementedRemoteMessage.getHopCount().static UnarmedProtocolMessageof(HopCount hopCount, boolean isArmed, int networkId, Nonce nonce, DrasylAddress recipient, DrasylAddress sender, ProofOfWork proofOfWork, io.netty.buffer.ByteBuf bytes) Creates an unarmed message.read()Read the remainder of this message and returns the resultedFullReadMessage.intrefCnt()booleanrelease()booleanrelease(int decrement) retain()retain(int increment) touch()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.PartialReadMessage
getBytesMethods inherited from interface org.drasyl.handler.remote.protocol.RemoteMessage
getArmed, getHopCount, getNetworkId, getNonce, getProofOfWork, getSender
-
Constructor Details
-
UnarmedProtocolMessage
public UnarmedProtocolMessage()
-
-
Method Details
-
getRecipient
- Specified by:
getRecipientin interfaceRemoteMessage
-
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
- Specified by:
retainin interfaceio.netty.util.ReferenceCounted
-
retain
- Specified by:
retainin interfaceio.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
-
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
-
read
Read the remainder of this message and returns the resultedFullReadMessage.getBytes()will be consumed and released by this method.- Returns:
- the fully read message
- Throws:
InvalidMessageFormatException- if message could not be read
-
arm
public ArmedProtocolMessage arm(io.netty.buffer.ByteBufAllocator alloc, Crypto cryptoInstance, SessionPair sessionPair) throws InvalidMessageFormatException Returns an armed version (ArmedProtocolMessage) of this message.- Parameters:
alloc-cryptoInstance- the crypto instance that should be usedsessionPair- will be used for encryption- Returns:
- the armed version (
ArmedProtocolMessage) of this message - Throws:
InvalidMessageFormatException- if arming was not possible
-
armAndRelease
public ArmedProtocolMessage armAndRelease(io.netty.buffer.ByteBufAllocator alloc, Crypto cryptoInstance, SessionPair sessionPair) throws InvalidMessageFormatException Returns an armed version (ArmedProtocolMessage) of this message and then releases this message.- Parameters:
alloc-cryptoInstance- the crypto instance that should be usedsessionPair- will be used for encryption- Returns:
- the armed version (
ArmedProtocolMessage) of this message - Throws:
InvalidMessageFormatException- if arming was not possible
-
of
public static UnarmedProtocolMessage of(HopCount hopCount, boolean isArmed, int networkId, Nonce nonce, DrasylAddress recipient, DrasylAddress sender, ProofOfWork proofOfWork, io.netty.buffer.ByteBuf bytes) Creates an unarmed 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:
hopCount- the hop countisArmed- if this 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 ofsenderbytes- message's remainder as bytes (may be armed).ReferenceCounted.release()ownership is transferred to thisPartialReadMessage.- Returns:
- an
PartialReadMessage - Throws:
NullPointerException- ifnonce,sender,proofOfWork, orrecipientisnull
-