2018-05-03 07:35:58 +00:00
|
|
|
package signal
|
|
|
|
|
2018-06-15 15:12:31 +00:00
|
|
|
import (
|
|
|
|
"github.com/ethereum/go-ethereum/common"
|
|
|
|
)
|
2018-05-03 07:35:58 +00:00
|
|
|
|
|
|
|
const (
|
|
|
|
// EventEnvelopeSent is triggered when envelope was sent at least to a one peer.
|
|
|
|
EventEnvelopeSent = "envelope.sent"
|
|
|
|
|
|
|
|
// EventEnvelopeExpired is triggered when envelop was dropped by a whisper without being sent
|
|
|
|
// to any peer
|
|
|
|
EventEnvelopeExpired = "envelope.expired"
|
2018-06-15 15:12:31 +00:00
|
|
|
|
|
|
|
// EventMailServerRequestCompleted is triggered when whisper receives a message ack from the mailserver
|
|
|
|
EventMailServerRequestCompleted = "mailserver.request.completed"
|
|
|
|
|
|
|
|
// EventMailServerRequestExpired is triggered when request TTL ends
|
|
|
|
EventMailServerRequestExpired = "mailserver.request.expired"
|
2018-07-16 07:40:40 +00:00
|
|
|
|
|
|
|
// EventEnodeDiscovered is tiggered when enode has been discovered.
|
|
|
|
EventEnodeDiscovered = "enode.discovered"
|
2018-09-24 18:07:34 +00:00
|
|
|
|
|
|
|
// EventDecryptMessageFailed is triggered when we receive a message from a bundle we don't have
|
|
|
|
EventDecryptMessageFailed = "messages.decrypt.failed"
|
2018-10-16 10:31:05 +00:00
|
|
|
|
|
|
|
// EventBundleAdded is triggered when we receive a bundle
|
|
|
|
EventBundleAdded = "bundles.added"
|
2018-05-03 07:35:58 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
// EnvelopeSignal includes hash of the envelope.
|
|
|
|
type EnvelopeSignal struct {
|
|
|
|
Hash common.Hash `json:"hash"`
|
|
|
|
}
|
|
|
|
|
2018-07-02 07:38:10 +00:00
|
|
|
// MailServerResponseSignal holds the data received in the response from the mailserver.
|
|
|
|
type MailServerResponseSignal struct {
|
|
|
|
RequestID common.Hash `json:"requestID"`
|
|
|
|
LastEnvelopeHash common.Hash `json:"lastEnvelopeHash"`
|
|
|
|
Cursor string `json:"cursor"`
|
|
|
|
}
|
|
|
|
|
2018-09-24 18:07:34 +00:00
|
|
|
// DecryptMessageFailedSignal holds the sender of the message that could not be decrypted
|
|
|
|
type DecryptMessageFailedSignal struct {
|
|
|
|
Sender string `json:"sender"`
|
|
|
|
}
|
|
|
|
|
2018-10-16 10:31:05 +00:00
|
|
|
// BundleAddedSignal holds the identity and installation id of the user
|
|
|
|
type BundleAddedSignal struct {
|
|
|
|
Identity string `json:"identity"`
|
|
|
|
InstallationID string `json:"installationID"`
|
|
|
|
}
|
|
|
|
|
2018-05-03 07:35:58 +00:00
|
|
|
// SendEnvelopeSent triggered when envelope delivered at least to 1 peer.
|
|
|
|
func SendEnvelopeSent(hash common.Hash) {
|
|
|
|
send(EventEnvelopeSent, EnvelopeSignal{hash})
|
|
|
|
}
|
|
|
|
|
|
|
|
// SendEnvelopeExpired triggered when envelope delivered at least to 1 peer.
|
|
|
|
func SendEnvelopeExpired(hash common.Hash) {
|
|
|
|
send(EventEnvelopeExpired, EnvelopeSignal{hash})
|
|
|
|
}
|
2018-06-15 15:12:31 +00:00
|
|
|
|
|
|
|
// SendMailServerRequestCompleted triggered when mail server response has been received
|
2018-07-02 07:38:10 +00:00
|
|
|
func SendMailServerRequestCompleted(requestID common.Hash, lastEnvelopeHash common.Hash, cursor []byte) {
|
|
|
|
sig := MailServerResponseSignal{
|
|
|
|
RequestID: requestID,
|
|
|
|
LastEnvelopeHash: lastEnvelopeHash,
|
|
|
|
Cursor: string(cursor),
|
|
|
|
}
|
|
|
|
send(EventMailServerRequestCompleted, sig)
|
2018-06-15 15:12:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// SendMailServerRequestExpired triggered when mail server request expires
|
|
|
|
func SendMailServerRequestExpired(hash common.Hash) {
|
|
|
|
send(EventMailServerRequestExpired, EnvelopeSignal{hash})
|
|
|
|
}
|
2018-07-16 07:40:40 +00:00
|
|
|
|
|
|
|
// EnodeDiscoveredSignal includes enode address and topic
|
|
|
|
type EnodeDiscoveredSignal struct {
|
|
|
|
Enode string `json:"enode"`
|
|
|
|
Topic string `json:"topic"`
|
|
|
|
}
|
|
|
|
|
|
|
|
// SendEnodeDiscovered tiggered when an enode is discovered.
|
|
|
|
// finds a new enode.
|
|
|
|
func SendEnodeDiscovered(enode, topic string) {
|
|
|
|
send(EventEnodeDiscovered, EnodeDiscoveredSignal{
|
|
|
|
Enode: enode,
|
|
|
|
Topic: topic,
|
|
|
|
})
|
|
|
|
}
|
2018-09-24 18:07:34 +00:00
|
|
|
|
|
|
|
func SendDecryptMessageFailed(sender string) {
|
|
|
|
send(EventDecryptMessageFailed, DecryptMessageFailedSignal{sender})
|
|
|
|
}
|
2018-10-16 10:31:05 +00:00
|
|
|
|
|
|
|
func SendBundleAdded(identity string, installationID string) {
|
|
|
|
send(EventBundleAdded, BundleAddedSignal{Identity: identity, InstallationID: installationID})
|
|
|
|
}
|