This repository has been archived by the owner on Oct 29, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathevents.go
118 lines (98 loc) · 3.94 KB
/
events.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
// events.go - mixnet client session events
// Copyright (C) 2018, 2019 Yawning Angel and David Stainton.
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as
// published by the Free Software Foundation, either version 3 of the
// License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
package client
import (
"encoding/hex"
"fmt"
"time"
cConstants "github.com/katzenpost/client/constants"
"github.com/katzenpost/core/pki"
)
// Event is the generic event sent over the event listener channel.
type Event interface {
// String returns a string representation of the Event.
String() string
}
// ConnectionStatusEvent is the event sent when an account's connection status
// changes.
type ConnectionStatusEvent struct {
// IsConnected is true iff the account is connected to the provider.
IsConnected bool
// Err is the error encountered when connecting or by the connection if any.
Err error
}
// String returns a string representation of the ConnectionStatusEvent.
func (e *ConnectionStatusEvent) String() string {
if !e.IsConnected {
return fmt.Sprintf("ConnectionStatus: %v (%v)", e.IsConnected, e.Err)
}
return fmt.Sprintf("ConnectionStatus: %v", e.IsConnected)
}
// MessageReplyEvent is the event sent when a new message is received.
type MessageReplyEvent struct {
// MessageID is the unique identifier for the request associated with the
// reply.
MessageID *[cConstants.MessageIDLength]byte
// Payload is the reply payload if any.
Payload []byte
// Err is the error encountered when servicing the request if any.
Err error
}
// String returns a string representation of the MessageReplyEvent.
func (e *MessageReplyEvent) String() string {
if e.Err != nil {
return fmt.Sprintf("MessageReply: %v failed: %v", hex.EncodeToString(e.MessageID[:]), e.Err)
}
return fmt.Sprintf("KaetzchenReply: %v (%v bytes)", hex.EncodeToString(e.MessageID[:]), len(e.Payload))
}
// MessageSentEvent is the event sent when a message has been fully transmitted.
type MessageSentEvent struct {
// MessageID is the local unique identifier for the message, generated
// when the message was enqueued.
MessageID *[cConstants.MessageIDLength]byte
// SentAt contains the time the message was sent.
SentAt time.Time
// ReplyETA is the expected round trip time to receive a response.
ReplyETA time.Duration
// Err is the error encountered when sending the message if any.
Err error
}
// String returns a string representation of a MessageSentEvent.
func (e *MessageSentEvent) String() string {
if e.Err != nil {
return fmt.Sprintf("MessageSent: %v failed: %v", hex.EncodeToString(e.MessageID[:]), e.Err)
}
return fmt.Sprintf("MessageSent: %v", hex.EncodeToString(e.MessageID[:]))
}
// MessageIDGarbageCollected is the event used to signal when a given
// message ID has been garbage collected.
type MessageIDGarbageCollected struct {
// MessageID is the local unique identifier for the message.
MessageID *[cConstants.MessageIDLength]byte
}
// String returns a string representation of a MessageIDGarbageCollected.
func (e *MessageIDGarbageCollected) String() string {
return fmt.Sprintf("MessageIDGarbageCollected: %v", hex.EncodeToString(e.MessageID[:]))
}
// NewDocumentEvent is the new document event, signaling that
// we have received a new document from the PKI.
type NewDocumentEvent struct {
Document *pki.Document
}
// String returns a string representation of a NewDocumentEvent.
func (e *NewDocumentEvent) String() string {
return fmt.Sprintf("PKI Document for epoch %d", e.Document.Epoch)
}