Documentation ¶
Index ¶
Constants ¶
const (
// IDLen is the length of a MessageID.
IDLen = 32
)
Variables ¶
This section is empty.
Functions ¶
func MutateTimestamp ¶
MutateTimestamp is used to modify the timestamps on all messages in a deterministic manner. This is because message ordering is done by timestamp and the timestamps come from the rounds, which means multiple messages can have the same timestamp due to being in the same round. The meaning of conversations can change depending on order, so while no explicit order can be discovered because to do so can leak potential ordering info for the mix, choosing an arbitrary order and having all clients agree will at least ensure that misunderstandings due to disagreements in order cannot occur.
In order to do this, this function mutates the timestamp of the round within +/- 5ms seeded based upon the message ID.
It should be noted that this is only a reasonable assumption when the number of messages in a channel isn't too much. For example, under these conditions the birthday paradox of getting a collision if there are 10 messages for the channel in the same round is ~4*10^-6, but the chance if there are 50 messages is 10^-4, and if the entire round is full of messages for the channel (1000 messages), .0487.
func VetTimestamp ¶
VetTimestamp determines which timestamp to use for a message. It will use the local timestamp provided in the message as long as it is within 25 seconds before the round and 2 second after the round. Otherwise, it will use the round timestamp via mutateTimestamp.
Types ¶
type DirectMessage ¶
type DirectMessage interface { GetRoundID() uint64 GetPayload() []byte GetPayloadType() uint32 GetNickname() string GetNonce() []byte GetLocalTimestamp() int64 }
DirectMessage objects are required to implement this interface.
type ID ¶
ID is the unique identifier of a channel message.
func DeriveChannelMessageID ¶
DeriveChannelMessageID returns the channel message ID for the given serialized message.
Due to the fact that messages contain the round they are sent in, they are replay resistant. This property, when combined with the collision resistance of the hash function, ensures that an adversary will not be able to cause multiple messages to have the same ID.
The MessageID contain the target ID (channel ID or recipient ID) as well to ensure that if a user is, e.g., in two channels that have messages with the same text sent to them in the same round, the message IDs will differ.
The channel message ID is defined as:
H(chID | roundID | message | chIDSalt)
func DeriveDirectMessageID ¶
func DeriveDirectMessageID(receptionID *id.ID, msg DirectMessage) ID
DeriveDirectMessageID hashes the parts relevant to a direct message to create a shared message ID between both parties. Round ID, Pubey, and DMToken is not hashed, so this is not replay resistant from a malicious attacker, but DMs prevent parties without the keys of one half the connection from participating.
func UnmarshalID ¶
UnmarshalMessageID unmarshalls the byte slice into a MessageID.
func (ID) MarshalJSON ¶
MarshalJSON handles the JSON marshaling of the MessageID. This function adheres to the json.Marshaler interface.
func (ID) String ¶
String returns a base64 encoded MessageID for debugging. This function adheres to the fmt.Stringer interface.
func (*ID) UnmarshalJSON ¶
UnmarshalJSON handles the JSON unmarshalling of the MessageID. This function adheres to the json.Unmarshaler interface.