Class HelloMessage
- java.lang.Object
-
- org.drasyl.handler.remote.protocol.HelloMessage
-
- All Implemented Interfaces:
FullReadMessage<HelloMessage>
,RemoteMessage
public abstract class HelloMessage extends Object
Describes a message that is used to announce this node to peers or to join a super node. The message's body is structured as follows:- Time: The sender's current time in milliseconds stored in 8 bytes.
- ChildrenTime: Specifies how many seconds (8 bytes) the sender wants to join the receiving super peer. If the value is 0, the message is an announcement and not a join.
- Signature: 64 byte signature. Only present if ChildrenTime is > 0.
This is an immutable object.
-
-
Field Summary
Fields Modifier and Type Field Description static int
SIGNED_LENGTH
static int
UNSIGNED_LENGTH
-
Fields inherited from interface org.drasyl.handler.remote.protocol.RemoteMessage
MAGIC_NUMBER
-
-
Constructor Summary
Constructors Constructor Description HelloMessage()
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description ArmedProtocolMessage
arm(io.netty.buffer.ByteBuf byteBuf, Crypto cryptoInstance, SessionPair sessionPair)
Returns an armed version (ArmedProtocolMessage
) of this message for sending it through untrustworthy channels.abstract long
getChildrenTime()
If the value is greater than0
, it indicates that this node wants to join the receiver as a child.abstract DrasylAddress
getRecipient()
Returns theIdentityPublicKey
of the message recipient.abstract ImmutableByteArray
getSignature()
abstract long
getTime()
Returns the time this message has been sent.HelloMessage
incrementHopCount()
Returns this message with incremented hop count.boolean
isSigned()
Returnstrue
if message is signed.static HelloMessage
of(int networkId, DrasylAddress recipient, IdentityPublicKey sender, ProofOfWork proofOfWork)
Creates a newHelloMessage
message.static HelloMessage
of(int networkId, DrasylAddress recipient, IdentityPublicKey sender, ProofOfWork proofOfWork, long time, long childrenTime, IdentitySecretKey secretKey)
Creates a newHelloMessage
message.static HelloMessage
of(int networkId, DrasylAddress recipient, IdentityPublicKey sender, ProofOfWork proofOfWork, long childrenTime, IdentitySecretKey secretKey)
Creates a newHelloMessage
message.static HelloMessage
of(int networkId, IdentityPublicKey sender, ProofOfWork proofOfWork)
Creates a new multicastHelloMessage
message (sent byLocalNetworkDiscovery
}.static HelloMessage
of(HopCount hopCount, boolean isArmed, int networkId, Nonce nonce, DrasylAddress recipient, DrasylAddress sender, ProofOfWork proofOfWork, long time, long childrenTime, IdentitySecretKey secretKey)
Creates new application message.static HelloMessage
of(HopCount hopCount, boolean isArmed, int networkId, Nonce nonce, DrasylAddress recipient, DrasylAddress sender, ProofOfWork proofOfWork, long time, long childrenTime, ImmutableByteArray signature)
Creates new application message.boolean
verifySignature()
Returnstrue
if message is signed and the signature is valid.protected void
writeBodyTo(io.netty.buffer.ByteBuf out)
protected void
writePrivateHeaderTo(io.netty.buffer.ByteBuf out)
protected void
writePublicHeaderTo(io.netty.buffer.ByteBuf out)
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.RemoteMessage
getArmed, getHopCount, getNetworkId, getNonce, getProofOfWork, getSender
-
-
-
-
Field Detail
-
UNSIGNED_LENGTH
public static final int UNSIGNED_LENGTH
- See Also:
- Constant Field Values
-
SIGNED_LENGTH
public static final int SIGNED_LENGTH
- See Also:
- Constant Field Values
-
-
Method Detail
-
of
public static HelloMessage of(HopCount hopCount, boolean isArmed, int networkId, Nonce nonce, DrasylAddress recipient, DrasylAddress sender, ProofOfWork proofOfWork, long time, long childrenTime, ImmutableByteArray signature)
Creates new application message.- 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
time
-childrenTime
- the join timesignature
-- Throws:
NullPointerException
- ifnonce
,sender
,proofOfWork
,recipient
, orhopCount
isnull
-
of
public static HelloMessage of(HopCount hopCount, boolean isArmed, int networkId, Nonce nonce, DrasylAddress recipient, DrasylAddress sender, ProofOfWork proofOfWork, long time, long childrenTime, IdentitySecretKey secretKey)
Creates new application message.- 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
time
-childrenTime
- the join timesignature
-- Throws:
NullPointerException
- ifnonce
,sender
,proofOfWork
,recipient
, orhopCount
isnull
-
of
public static HelloMessage of(int networkId, DrasylAddress recipient, IdentityPublicKey sender, ProofOfWork proofOfWork, long time, long childrenTime, IdentitySecretKey secretKey)
Creates a newHelloMessage
message.- Parameters:
networkId
- the network of the joining noderecipient
- the public key of the node to joinsender
- the public key of the joining nodeproofOfWork
- the proof of worktime
- time in millis when this message was sentchildrenTime
- if0
greater then 0, node will join a children.secretKey
- the secret key used to sign this message- Throws:
NullPointerException
- ifsender
,proofOfWork
, orrecipient
isnull
-
of
public static HelloMessage of(int networkId, DrasylAddress recipient, IdentityPublicKey sender, ProofOfWork proofOfWork, long childrenTime, IdentitySecretKey secretKey)
Creates a newHelloMessage
message.- Parameters:
networkId
- the network of the joining noderecipient
- the public key of the node to joinsender
- the public key of the joining nodeproofOfWork
- the proof of workchildrenTime
- if0
greater then 0, node will join a children.secretKey
- the secret key used to sign this message- Throws:
NullPointerException
- ifsender
,proofOfWork
, orrecipient
isnull
-
of
public static HelloMessage of(int networkId, DrasylAddress recipient, IdentityPublicKey sender, ProofOfWork proofOfWork)
Creates a newHelloMessage
message.- Parameters:
networkId
- the network of the joining noderecipient
- the public key of the node to joinsender
- the public key of the joining nodeproofOfWork
- the proof of work- Throws:
NullPointerException
- ifsender
,proofOfWork
, orrecipient
isnull
-
of
public static HelloMessage of(int networkId, IdentityPublicKey sender, ProofOfWork proofOfWork)
Creates a new multicastHelloMessage
message (sent byLocalNetworkDiscovery
}.- Parameters:
networkId
- the network of the joining nodesender
- the public key of the joining nodeproofOfWork
- the proof of work- Throws:
NullPointerException
- ifsender
, orproofOfWork
isnull
-
getRecipient
@Nullable public abstract DrasylAddress getRecipient()
Returns theIdentityPublicKey
of the message recipient. If the message has no recipient (e.g. because it is a multicast message)null
is returned.- Returns:
-
getTime
public abstract long getTime()
Returns the time this message has been sent.
-
getChildrenTime
public abstract long getChildrenTime()
If the value is greater than0
, it indicates that this node wants to join the receiver as a child. For this, the receiver must be configured as a super node. In all other cases, the message is used to announce this node's presence to the recipient.
-
getSignature
public abstract ImmutableByteArray getSignature()
-
incrementHopCount
public HelloMessage incrementHopCount()
Description copied from interface:FullReadMessage
Returns this message with incremented hop count.- Returns:
- this message with incremented hop count.
-
isSigned
public boolean isSigned()
Returnstrue
if message is signed. This message will not verifiy the signature! UseverifySignature()
to check if supplied signature is valid.- Returns:
true
if message is signed
-
verifySignature
public boolean verifySignature()
Returnstrue
if message is signed and the signature is valid. UseisSigned()
to check whether a message is signed.- Returns:
true
if message is signed and the signature is valid
-
writePrivateHeaderTo
protected void writePrivateHeaderTo(io.netty.buffer.ByteBuf out)
-
writeBodyTo
protected void writeBodyTo(io.netty.buffer.ByteBuf out)
-
arm
public ArmedProtocolMessage arm(io.netty.buffer.ByteBuf byteBuf, 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<?>>
- Parameters:
byteBuf
- theByteBuf
to write throughcryptoInstance
- 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
-
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
-
writePublicHeaderTo
protected void writePublicHeaderTo(io.netty.buffer.ByteBuf out)
-
-