-
Notifications
You must be signed in to change notification settings - Fork 2
/
struct.go
198 lines (166 loc) · 4.58 KB
/
struct.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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
package passtor
import (
"github.com/rivo/tview"
"log"
"net"
"sync"
)
// NodeAddr node address entry in the k-bucket, node udp ip and port, and nodeID
type NodeAddr struct {
Addr net.UDPAddr // udp address (ip + port) of the node
NodeID Hash // nodeID of that node
}
// MessageCounter structure containing message indexing tools
type MessageCounter struct {
Mutex *sync.Mutex // mutex of the structure
IDCounter *uint64 // current message ID
PendingMsg map[uint64]*chan Message // list of current pending messages
}
// Printer of the passtor, handles all prints to console
type Printer struct {
Verbose int
Printer *log.Logger
ErrPrinter *log.Logger
}
// Passtor instance
type Passtor struct {
Name string // name of the passtor instance
NodeID Hash // hash of the name of the passtor, node identifier
PConn *net.UDPConn // udp socket to communicate with other passtors
ClientAddr *net.TCPAddr // tcp address to communicate with clients
Messages *MessageCounter // handles message id and pending messages
Addr NodeAddr // address used to communicate with passtors
Buckets map[uint16]*Bucket // k-buckets used in the DHT
Printer Printer // passtor console printer
Accounts Accounts
}
// Message structure defining messages exchanged between passtors
type Message struct {
ID uint64 // message ID
Reply bool // message is a reply
Sender *NodeAddr // sender identity
Ping *bool // non nil if message is a ping message
LookupReq *Hash // value to lookup
LookupRep *[]NodeAddr // lookup response
AllocationReq *AccountMessage
AllocationRep *string
FetchReq *Hash
FetchRep *AccountMessage
}
// Bucket structure representing Kademlia k-buckets
type Bucket struct {
Mutex *sync.Mutex
Head *BucketElement
Tail *BucketElement
Size uint
}
// BucketElement represent individual elements of the k-buckets
type BucketElement struct {
NodeAddr *NodeAddr
Next *BucketElement
Prev *BucketElement
}
// LookupStatus type used by the lookup RPC
type LookupStatus struct {
NodeAddr NodeAddr
Tested bool
Failed bool
}
// LoginMetaData for the Login structure.
type LoginMetaData struct {
ServiceNonce Nonce
UsernameNonce Nonce
PasswordNonce Nonce
}
// Credentials for a given service.
type Credentials struct {
Username EncryptedData
Password EncryptedData
}
// LoginClient used to display restricted plaintext info about a login
type LoginClient struct {
Service string
Username string
}
// Login is a tuple of credentials and corresponding metadata to ensure validity.
type Login struct {
ID Hash
Service EncryptedData
Credentials Credentials
MetaData LoginMetaData
}
// KeysClient used only client side to store the keys used to sign or en/de-crypt data.
type KeysClient struct {
PublicKey PublicKey
PrivateKey PrivateKey
SymmetricKey SymmetricKey
}
// Keys used to encrypt, or sign data.
type Keys struct {
PublicKey PublicKey
PrivateKeySeed EncryptedData
SymmetricKey EncryptedData
}
// AccountMetaData for the Account structure.
type AccountMetaData struct {
SecretSalt Salt
PrivateKeySeedNonce Nonce
SymmetricKeyNonce Nonce
}
// Account used only client side to store info about the current user.
type AccountClient struct {
ID string
Keys KeysClient
}
// Account groups everything that has been stored by a single user.
type Account struct {
ID Hash
Keys Keys
Version uint32
Data map[Hash]Login
MetaData AccountMetaData
Signature Signature
}
// AccountNetwork used to be able to encode to be sent over the network
type AccountNetwork struct {
ID Hash
Keys Keys
Version uint32
Data []Login
MetaData AccountMetaData
Signature Signature
}
type AccountInfo struct {
Account Account
Repl uint32
Mutex *sync.Mutex
}
// Accounts is the collection of all created accounts.
type Accounts map[Hash]*AccountInfo
// ClientMessage represents a message than can be sent from a client to a node
type ClientMessage struct {
Push *AccountNetwork
Pull *Hash
}
// ServerResponse represents a response from a node to a client
type ServerResponse struct {
Status string
Debug *string
Data *AccountNetwork
}
// AccountMessage message requesting a node to allocate a file or fetching an
// account info
type AccountMessage struct {
Account AccountNetwork
Repl uint32
}
type accountCountPair struct {
Account Account
Count int
}
type Client struct {
App *tview.Application
Node string
AccountClient AccountClient
Account Account
}