message

package
v0.0.9 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 6, 2023 License: BSD-2-Clause Imports: 9 Imported by: 12

Documentation

Index

Constants

View Source
const (
	// IDLen is the length of a MessageID.
	IDLen = 32
)

Variables

This section is empty.

Functions

func MutateTimestamp

func MutateTimestamp(ts time.Time, msgID ID) time.Time

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

func VetTimestamp(localTS, ts time.Time, msgID ID) time.Time

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

type ID [IDLen]byte

ID is the unique identifier of a channel message.

func DeriveChannelMessageID

func DeriveChannelMessageID(chID *id.ID, roundID uint64,
	message []byte) ID

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

func UnmarshalID(data []byte) (ID, error)

UnmarshalMessageID unmarshalls the byte slice into a MessageID.

func (ID) Bytes

func (mid ID) Bytes() []byte

Bytes returns a copy of the bytes in the message.

func (ID) DeepCopy

func (mid ID) DeepCopy() ID

DeepCopy returns a copy Message ID

func (ID) Equals

func (mid ID) Equals(mid2 ID) bool

Equals checks if two message IDs are the same.

Not constant time.

func (ID) Marshal

func (mid ID) Marshal() []byte

Marshal marshals the MessageID into a byte slice.

func (ID) MarshalJSON

func (mid ID) MarshalJSON() ([]byte, error)

MarshalJSON handles the JSON marshaling of the MessageID. This function adheres to the json.Marshaler interface.

func (ID) String

func (mid ID) String() string

String returns a base64 encoded MessageID for debugging. This function adheres to the fmt.Stringer interface.

func (*ID) UnmarshalJSON

func (mid *ID) UnmarshalJSON(b []byte) error

UnmarshalJSON handles the JSON unmarshalling of the MessageID. This function adheres to the json.Unmarshaler interface.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL