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
-
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.void
close()
CallsReferenceCounted.release()
.abstract DrasylAddress
Returns a copy of this message with incrementedRemoteMessage.getHopCount()
.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.read()
Read the remainder of this message and returns the resultedFullReadMessage
.int
refCnt()
boolean
release()
boolean
release
(int decrement) retain()
retain
(int increment) touch()
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, getSender
-
Constructor Details
-
UnarmedProtocolMessage
public UnarmedProtocolMessage()
-
-
Method Details
-
getRecipient
- Specified by:
getRecipient
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
- Specified by:
retain
in interfaceio.netty.util.ReferenceCounted
-
retain
- Specified by:
retain
in interfaceio.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
-
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
-
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 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:
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 ofsender
bytes
- message's remainder as bytes (may be armed).ReferenceCounted.release()
ownership is transferred to thisPartialReadMessage
.- Returns:
- an
PartialReadMessage
- Throws:
NullPointerException
- ifnonce
,sender
,proofOfWork
, orrecipient
isnull
-