session-ios/SessionSnodeKit/Message.swift

36 lines
1 KiB
Swift
Raw Normal View History

2020-11-05 02:07:21 +01:00
import PromiseKit
2020-11-06 01:57:34 +01:00
import SessionUtilities
2020-11-05 02:07:21 +01:00
2020-11-06 03:46:06 +01:00
public struct SnodeMessage {
2020-11-05 02:07:21 +01:00
/// The hex encoded public key of the recipient.
2020-11-06 03:46:06 +01:00
let recipient: String
2020-11-05 02:07:21 +01:00
/// The content of the message.
let data: LosslessStringConvertible
/// The time to live for the message in milliseconds.
let ttl: UInt64
/// When the proof of work was calculated.
///
/// - Note: Expressed as milliseconds since 00:00:00 UTC on 1 January 1970.
2020-11-06 03:46:06 +01:00
let timestamp: UInt64
2020-11-05 02:07:21 +01:00
/// The base 64 encoded proof of work.
2020-11-06 03:46:06 +01:00
let nonce: String
public init(recipient: String, data: LosslessStringConvertible, ttl: UInt64, timestamp: UInt64, nonce: String) {
self.recipient = recipient
self.data = data
self.ttl = ttl
self.timestamp = timestamp
self.nonce = nonce
}
2020-11-05 02:07:21 +01:00
public func toJSON() -> JSON {
2020-11-06 03:46:06 +01:00
return [
"pubKey" : recipient,
"data" : data.description,
"ttl" : String(ttl),
"timestamp" : String(timestamp),
"nonce" : nonce
]
2020-11-05 02:07:21 +01:00
}
}