aboutsummaryrefslogtreecommitdiff
path: root/src/gnunet/message/msg_namestore.go
diff options
context:
space:
mode:
Diffstat (limited to 'src/gnunet/message/msg_namestore.go')
-rw-r--r--src/gnunet/message/msg_namestore.go598
1 files changed, 538 insertions, 60 deletions
diff --git a/src/gnunet/message/msg_namestore.go b/src/gnunet/message/msg_namestore.go
index f03ef2c..9241e17 100644
--- a/src/gnunet/message/msg_namestore.go
+++ b/src/gnunet/message/msg_namestore.go
@@ -24,6 +24,8 @@ import (
24 "gnunet/enums" 24 "gnunet/enums"
25 "gnunet/service/dht/blocks" 25 "gnunet/service/dht/blocks"
26 "gnunet/util" 26 "gnunet/util"
27
28 "github.com/bfix/gospel/data"
27) 29)
28 30
29//====================================================================== 31//======================================================================
@@ -37,10 +39,10 @@ type GenericNamestoreMsg struct {
37} 39}
38 40
39// return initialized common message header 41// return initialized common message header
40func newGenericNamestoreMsg(size uint16, mtype enums.MsgType) GenericNamestoreMsg { 42func newGenericNamestoreMsg(id uint32, size uint16, mtype enums.MsgType) GenericNamestoreMsg {
41 return GenericNamestoreMsg{ 43 return GenericNamestoreMsg{
42 MsgHeader: MsgHeader{size, mtype}, 44 MsgHeader: MsgHeader{size, mtype},
43 ID: uint32(util.NextID()), 45 ID: id,
44 } 46 }
45} 47}
46 48
@@ -48,18 +50,28 @@ func newGenericNamestoreMsg(size uint16, mtype enums.MsgType) GenericNamestoreMs
48// MSG_NAMESTORE_ZONE_ITERATION_START 50// MSG_NAMESTORE_ZONE_ITERATION_START
49//---------------------------------------------------------------------- 51//----------------------------------------------------------------------
50 52
51// NamestoreZoneIterStartMsg starts a new iteration over all zones 53// NamestoreZoneIterStartMsg starts a new iteration over all labels in a zones
52type NamestoreZoneIterStartMsg struct { 54type NamestoreZoneIterStartMsg struct {
53 GenericNamestoreMsg 55 GenericNamestoreMsg
54 56
57 Filter uint16 `order:"big"` // filter settings
58 KeyLen uint16 `order:"big"` // length of private key
55 ZoneKey *crypto.ZonePrivate `init:"Init"` // private zone key 59 ZoneKey *crypto.ZonePrivate `init:"Init"` // private zone key
56} 60}
57 61
58// NewNamecacheCacheMsg creates a new default message. 62// NewNamecacheCacheMsg creates a new default message.
59func NewNamestoreZoneIterStartMsg(zone *crypto.ZonePrivate) *NamestoreZoneIterStartMsg { 63func NewNamestoreZoneIterStartMsg(id uint32, filter int, zone *crypto.ZonePrivate) *NamestoreZoneIterStartMsg {
64 var size uint16 = 16
65 var kl uint16 = 0
66 if zone != nil {
67 kl = uint16(zone.KeySize()) + 4
68 size += kl
69 }
60 return &NamestoreZoneIterStartMsg{ 70 return &NamestoreZoneIterStartMsg{
61 GenericNamestoreMsg: newGenericNamestoreMsg(100, enums.MSG_NAMESTORE_ZONE_ITERATION_START), 71 GenericNamestoreMsg: newGenericNamestoreMsg(id, size, enums.MSG_NAMESTORE_ZONE_ITERATION_START),
72 Filter: uint16(filter),
62 ZoneKey: zone, 73 ZoneKey: zone,
74 KeyLen: kl,
63 } 75 }
64} 76}
65 77
@@ -75,14 +87,19 @@ func (m *NamestoreZoneIterStartMsg) String() string {
75// MSG_NAMESTORE_ZONE_ITERATION_NEXT 87// MSG_NAMESTORE_ZONE_ITERATION_NEXT
76//---------------------------------------------------------------------- 88//----------------------------------------------------------------------
77 89
90// NamestoreZoneIterNextMsg returns the next labels
78type NamestoreZoneIterNextMsg struct { 91type NamestoreZoneIterNextMsg struct {
79 GenericNamestoreMsg 92 GenericNamestoreMsg
80 93
81 Limit uint64 `order:"big"` // max. number of records in one go 94 Limit uint64 `order:"big"` // max. number of records in one go
82} 95}
83 96
84func NewNamestoreZoneIterNextMsg() *NamestoreZoneIterNextMsg { 97// NewNamestoreZoneIterNextMsg creates a message with given limit
85 return &NamestoreZoneIterNextMsg{} 98func NewNamestoreZoneIterNextMsg(id uint32, limit int) *NamestoreZoneIterNextMsg {
99 return &NamestoreZoneIterNextMsg{
100 GenericNamestoreMsg: newGenericNamestoreMsg(id, 16, enums.MSG_NAMESTORE_ZONE_ITERATION_NEXT),
101 Limit: uint64(limit),
102 }
86} 103}
87 104
88// Init called after unmarshalling a message to setup internal state 105// Init called after unmarshalling a message to setup internal state
@@ -97,132 +114,593 @@ func (m *NamestoreZoneIterNextMsg) String() string {
97// MSG_NAMESTORE_ZONE_ITERATION_STOP 114// MSG_NAMESTORE_ZONE_ITERATION_STOP
98//---------------------------------------------------------------------- 115//----------------------------------------------------------------------
99 116
117// NamestoreZoneIterStopMsg stops a running iterator
100type NamestoreZoneIterStopMsg struct { 118type NamestoreZoneIterStopMsg struct {
101 GenericNamestoreMsg 119 GenericNamestoreMsg
102} 120}
103 121
122// NewNamestoreZoneIterNextMsg creates a stop message
123func NewNamestoreZoneIterStopMsg(id uint32) *NamestoreZoneIterStopMsg {
124 return &NamestoreZoneIterStopMsg{
125 GenericNamestoreMsg: newGenericNamestoreMsg(id, 8, enums.MSG_NAMESTORE_ZONE_ITERATION_STOP),
126 }
127}
128
129// Init called after unmarshalling a message to setup internal state
130func (m *NamestoreZoneIterStopMsg) Init() error { return nil }
131
132// String returns a human-readable representation of the message.
133func (m *NamestoreZoneIterStopMsg) String() string {
134 return fmt.Sprintf("NamestoreZoneIterStopMsg{id=%d}", m.ID)
135}
136
137//----------------------------------------------------------------------
138// MSG_NAMESTORE_ZONE_ITERATION_END
139//----------------------------------------------------------------------
140
141// NamestoreZoneIterEndMsg stops a running iterator
142type NamestoreZoneIterEndMsg struct {
143 GenericNamestoreMsg
144}
145
146// NewNamestoreZoneIterEndMsg creates a stop message
147func NewNamestoreZoneIterEndMsg(id uint32) *NamestoreZoneIterEndMsg {
148 return &NamestoreZoneIterEndMsg{
149 GenericNamestoreMsg: newGenericNamestoreMsg(id, 8, enums.MSG_NAMESTORE_ZONE_ITERATION_END),
150 }
151}
152
153// Init called after unmarshalling a message to setup internal state
154func (m *NamestoreZoneIterEndMsg) Init() error { return nil }
155
156// String returns a human-readable representation of the message.
157func (m *NamestoreZoneIterEndMsg) String() string {
158 return fmt.Sprintf("NamestoreZoneIterEndMsg{id=%d}", m.ID)
159}
160
104//---------------------------------------------------------------------- 161//----------------------------------------------------------------------
105// MSG_NAMESTORE_RECORD_RESULT 162// MSG_NAMESTORE_RECORD_RESULT
106//---------------------------------------------------------------------- 163//----------------------------------------------------------------------
107 164
165// NamestoreRecordResultMsg returns the records for a label (name)
108type NamestoreRecordResultMsg struct { 166type NamestoreRecordResultMsg struct {
109 GenericNamestoreMsg 167 GenericNamestoreMsg
110 168
111 Expire util.AbsoluteTime `` // expiration date 169 Expire util.AbsoluteTime `` // expiration date
112 NameLen uint16 `order:"big"` // length of name 170 NameLen uint16 `order:"big"` // length of name
113 RdLen uint16 `order:"big"` // size of record data 171 RdLen uint16 `order:"big"` // size of record data
114 RdCount uint16 `order:"big"` // number of records 172 RdCount uint16 `order:"big"` // number of records
115 Reserved uint16 `order:"big"` // alignment 173 KeyLen uint16 `order:"big"` // length of key
116 ZoneKey *crypto.ZonePrivate `init:"Init"` // private zone key 174 ZoneKey *crypto.ZonePrivate `init:"Init"` // private zone key
117 Name []byte `size:"NameLen"` // name string 175 Name []byte `size:"NameLen"` // name string
118 Records []byte `size:"RdLen"` // serialized record data 176 Records []byte `size:"RdLen"` // serialized record data
177
178 // transient state
179 recset *blocks.RecordSet
119} 180}
120 181
121func NewNamestoreRecordResultMsg(zk *crypto.ZonePrivate, label string) *NamestoreRecordResultMsg { 182// NewNamestoreRecordResultMsg returns an initialize record message
183func NewNamestoreRecordResultMsg(id uint32, zk *crypto.ZonePrivate, label string) *NamestoreRecordResultMsg {
184 var kl uint16
185 if zk != nil {
186 kl = uint16(zk.KeySize()) + 4
187 }
188 nl := uint16(len(label) + 1)
189 size := kl + nl + 24
122 return &NamestoreRecordResultMsg{ 190 return &NamestoreRecordResultMsg{
123 Expire: util.AbsoluteTimeNever(), 191 GenericNamestoreMsg: newGenericNamestoreMsg(id, size, enums.MSG_NAMESTORE_RECORD_RESULT),
124 ZoneKey: zk, 192 Expire: util.AbsoluteTimeNever(),
125 NameLen: uint16(len(label)), 193 KeyLen: kl,
126 Name: []byte(label), 194 ZoneKey: zk,
127 RdLen: 0, 195 NameLen: nl,
128 RdCount: 0, 196 Name: util.WriteCString(label),
197 RdLen: 0,
198 RdCount: 0,
129 } 199 }
130} 200}
131 201
132// Init called after unmarshalling a message to setup internal state 202// Init called after unmarshalling a message to setup internal state
133func (m *NamestoreRecordResultMsg) Init() error { return nil } 203func (m *NamestoreRecordResultMsg) Init() error {
204 if m.recset == nil {
205 m.recset = new(blocks.RecordSet)
206 return data.Unmarshal(m.recset, m.Records)
207 }
208 return nil
209}
210
211// AddRecords adds the record data to the message
212func (m *NamestoreRecordResultMsg) AddRecords(rs *blocks.RecordSet) {
213 // make sure the record set is padded correctly
214 rs.SetPadding()
215 // copy recordset to message
216 m.RdCount = uint16(rs.Count)
217 m.Records = rs.RDATA()
218 m.RdLen = uint16(len(m.Records))
219 m.MsgSize += m.RdLen
220 m.recset = rs
221}
222
223// GetRecords returns the record set contained in message
224func (m *NamestoreRecordResultMsg) GetRecords() blocks.RecordSet {
225 return *m.recset
226}
134 227
135// String returns a human-readable representation of the message. 228// String returns a human-readable representation of the message.
136func (m *NamestoreRecordResultMsg) String() string { 229func (m *NamestoreRecordResultMsg) String() string {
137 return fmt.Sprintf("NamestoreRecordResultMsg{id=%d,zone=%s,label='%s'}", m.ID, m.ZoneKey.ID(), string(m.Name)) 230 zone, label := "", ""
231 if !m.ZoneKey.IsNull() {
232 zone = fmt.Sprintf(",zone=%s", m.ZoneKey.ID())
233 }
234 if m.NameLen > 0 {
235 lbl, _ := util.ReadCString(m.Name, 0)
236 label = fmt.Sprintf(",label='%s'", lbl)
237 }
238 return fmt.Sprintf("NamestoreRecordResultMsg{id=%d%s%s,%d records}",
239 m.ID, zone, label, m.RdCount)
138} 240}
139 241
140//---------------------------------------------------------------------- 242//----------------------------------------------------------------------
243// MSG_NAMESTORE_RECORD_STORE
141//---------------------------------------------------------------------- 244//----------------------------------------------------------------------
142 245
246// NamestoreRecordSet for a label
247type NamestoreRecordSet struct {
248 NameLen uint16 `order:"big"` // Length of label
249 RdLen uint16 `order:"big"` // length of record data
250 RdCount uint16 `order:"big"` // number of records
251 Reserved uint16 `order:"big"` // reserved
252 Name []byte `size:"NameLen"` // label name
253 RecData []byte `size:"RdLen"` // record data
254}
255
256// NewNamestoreRecordSet for label and resource records.
257func NewNamestoreRecordSet(label string, rr *blocks.RecordSet) (rs *NamestoreRecordSet, size uint16) {
258 // make sure the record set is padded correctly
259 rr.SetPadding()
260
261 // copy recordset to message
262 rs = new(NamestoreRecordSet)
263 rs.NameLen = uint16(len(label) + 1)
264 rs.Name = util.WriteCString(label)
265 rs.RdCount = uint16(rr.Count)
266 rs.RecData = rr.RDATA()
267 rs.RdLen = uint16(len(rs.RecData))
268 size = rs.RdLen + rs.NameLen + 8
269 return
270}
271
272//----------------------------------------------------------------------
273
274// NamestoreRecordStoreMsg for storing records (multiple labels at a
275// time possible)
143type NamestoreRecordStoreMsg struct { 276type NamestoreRecordStoreMsg struct {
144 GenericNamestoreMsg 277 GenericNamestoreMsg
145 278
146 ZoneKey *crypto.ZonePrivate // private zone key 279 Count uint16 `order:"big"` // number of RecordSets
147 Records *blocks.RecordSet // list of records 280 KeyLen uint16 `order:"big"` // length of zone key
281 ZoneKey *crypto.ZonePrivate `init:"Init"` // private zone key
282 RSets []*NamestoreRecordSet `size:"Count"` // list of label record sets
283}
284
285// NewNamestoreRecordStoreMsg creates an initialized message (without records)
286func NewNamestoreRecordStoreMsg(id uint32, zk *crypto.ZonePrivate) *NamestoreRecordStoreMsg {
287 var kl uint16
288 if zk != nil {
289 kl = uint16(zk.KeySize() + 4)
290 }
291 size := kl + 14
292 return &NamestoreRecordStoreMsg{
293 GenericNamestoreMsg: newGenericNamestoreMsg(id, size, enums.MSG_NAMESTORE_RECORD_STORE),
294 ZoneKey: zk,
295 Count: 0,
296 KeyLen: kl,
297 }
298}
299
300// Init called after unmarshalling a message to setup internal state
301func (m *NamestoreRecordStoreMsg) Init() error {
302 return nil
303}
304
305// AddRecords adds the record data to the message
306func (m *NamestoreRecordStoreMsg) AddRecordSet(label string, rr *blocks.RecordSet) {
307 rs, size := NewNamestoreRecordSet(label, rr)
308 m.RSets = append(m.RSets, rs)
309 m.MsgSize += size
310}
311
312// String returns a human-readable representation of the message.
313func (m *NamestoreRecordStoreMsg) String() string {
314 return fmt.Sprintf("NamestoreRecordStoreMsg{id=%d,zone=%s,%d record sets}",
315 m.ID, m.ZoneKey.ID(), m.Count)
148} 316}
149 317
318//----------------------------------------------------------------------
319// MSG_NAMESTORE_RECORD_STORE_RESP
320//----------------------------------------------------------------------
321
322// NamestoreRecordStoreRespMsg is a response to a record store message
150type NamestoreRecordStoreRespMsg struct { 323type NamestoreRecordStoreRespMsg struct {
151 GenericNamestoreMsg 324 GenericNamestoreMsg
152 325
153 Status int32 `order:"big"` // result status 326 Status uint32 `order:"big"` // result status
154 ErrLen uint16 `order:"big"` // length of error message 327}
155 Reserved uint16 `order:"big"` // alignment 328
156 Error []byte `size:"ErrLen"` // error message 329// NewNamestoreRecordStoreRespMsg creates a new message
330func NewNamestoreRecordStoreRespMsg(id uint32, rc uint32) *NamestoreRecordStoreRespMsg {
331 return &NamestoreRecordStoreRespMsg{
332 GenericNamestoreMsg: newGenericNamestoreMsg(id, 12, enums.MSG_NAMESTORE_RECORD_STORE_RESPONSE),
333 Status: rc,
334 }
157} 335}
158 336
159type NamestoreLabelLookupMsg struct { 337// Init called after unmarshalling a message to setup internal state
338func (m *NamestoreRecordStoreRespMsg) Init() error { return nil }
339
340// String returns a human-readable representation of the message.
341func (m *NamestoreRecordStoreRespMsg) String() string {
342 return fmt.Sprintf("NamestoreRecordStoreRespMsg{id=%d,rc=%d}", m.ID, m.Status)
343}
344
345//----------------------------------------------------------------------
346// MSG_NAMESTORE_RECORD_LOOKUP
347//----------------------------------------------------------------------
348
349// NamestoreRecordLookupMsg looks up a record in the namestore
350type NamestoreRecordLookupMsg struct {
160 GenericNamestoreMsg 351 GenericNamestoreMsg
161 352
162 LblLen uint32 `order:"big"` // length of label 353 LblLen uint16 `order:"big"` // length of label
163 IsEdit uint32 `order:"big"` // lookup corresponds to edit request 354 IsEdit uint16 `order:"big"` // lookup corresponds to edit request
164 ZoneKey *crypto.ZonePrivate // private zone key 355 Filter uint16 `order:"big"` // filter flags
356 KeyLen uint16 `order:"big"` // size of key
357 ZoneKey *crypto.ZonePrivate `init:"Init"` // private zone key
165 Label []byte `size:"LblLen"` // label string 358 Label []byte `size:"LblLen"` // label string
166} 359}
167 360
168type NamestoreLabelLookupRespMsg struct { 361// NewNamestoreRecordLookupMsg creates a new message
362func NewNamestoreRecordLookupMsg(id uint32, zk *crypto.ZonePrivate, label string, isEdit bool) *NamestoreRecordLookupMsg {
363 var flag uint16
364 if isEdit {
365 flag = 1
366 }
367 var kl uint16
368 if zk != nil {
369 kl += uint16(zk.KeySize() + 4)
370 }
371 size := kl + uint16(len(label)) + 16
372 return &NamestoreRecordLookupMsg{
373 GenericNamestoreMsg: newGenericNamestoreMsg(id, size, enums.MSG_NAMESTORE_RECORD_LOOKUP),
374 IsEdit: flag,
375 KeyLen: kl,
376 ZoneKey: zk,
377 LblLen: uint16(len(label)),
378 Label: []byte(label),
379 }
380}
381
382// Init called after unmarshalling a message to setup internal state
383func (m *NamestoreRecordLookupMsg) Init() error { return nil }
384
385// String returns a human-readable representation of the message.
386func (m *NamestoreRecordLookupMsg) String() string {
387 return fmt.Sprintf("NamestoreRecordLookupMsg{id=%d,zk=%s,label=%s,edit=%v}",
388 m.ID, m.ZoneKey.ID(), string(m.Label), m.IsEdit != 0)
389}
390
391//----------------------------------------------------------------------
392// MSG_NAMESTORE_RECORD_LOOKUP_RESPONSE
393//----------------------------------------------------------------------
394
395// NamestoreRecordLookupRespMsg is a lookup response message
396type NamestoreRecordLookupRespMsg struct {
169 GenericNamestoreMsg 397 GenericNamestoreMsg
170 398
171 LblLen uint16 `order:"big"` // Length of label 399 LblLen uint16 `order:"big"` // Length of label
172 RdLen uint16 `order:"big"` // size of record data 400 RdLen uint16 `order:"big"` // size of record data
173 RdCount uint16 `order:"big"` // number of records 401 RdCount uint16 `order:"big"` // number of records
174 Found int16 `order:"big"` // label found? 402 Found int16 `order:"big"` // label found?
175 ZoneKey *crypto.ZonePrivate // private zone key 403 Reserved uint16 `order:"big"` // reserved
176 Label []byte `size:"LblLen"` // label string 404 KeyLen uint16 `order:"big"` // length of key
177 Records []byte `size:"RdLen"` // serialized record data 405 ZoneKey *crypto.ZonePrivate `init:"Init"` // private zone key
406 Label []byte `size:"LblLen"` // label string
407 Records []byte `size:"RdLen"` // serialized record data
408
409 // transient state
410 recset *blocks.RecordSet
178} 411}
179 412
413// NewNamestoreRecordLookupRespMsg creates a new message
414func NewNamestoreRecordLookupRespMsg(id uint32, zk *crypto.ZonePrivate, label string) *NamestoreRecordLookupRespMsg {
415 var kl uint16
416 if zk != nil {
417 kl = uint16(zk.KeySize() + 4)
418 }
419 size := kl + uint16(len(label)) + 20
420 msg := &NamestoreRecordLookupRespMsg{
421 GenericNamestoreMsg: newGenericNamestoreMsg(id, size, enums.MSG_NAMESTORE_RECORD_LOOKUP_RESPONSE),
422 KeyLen: kl,
423 ZoneKey: zk,
424 LblLen: uint16(len(label)),
425 Label: []byte(label),
426 Records: nil,
427 }
428 return msg
429}
430
431// Init called after unmarshalling a message to setup internal state
432func (m *NamestoreRecordLookupRespMsg) Init() error {
433 if m.recset == nil {
434 m.recset = new(blocks.RecordSet)
435 return data.Unmarshal(m.recset, m.Records)
436 }
437 return nil
438}
439
440// AddRecords adds the record data to the message
441func (m *NamestoreRecordLookupRespMsg) AddRecords(rs *blocks.RecordSet) {
442 // make sure the record set is padded correctly
443 rs.SetPadding()
444 // copy recordset to message
445 m.RdCount = uint16(rs.Count)
446 m.Records = rs.RDATA()
447 m.RdLen = uint16(len(m.Records))
448 m.MsgSize += m.RdLen
449 m.recset = rs
450}
451
452// GetRecords returns the record set contained in message
453func (m *NamestoreRecordLookupRespMsg) GetRecords() blocks.RecordSet {
454 return *m.recset
455}
456
457// String returns a human-readable representation of the message.
458func (m *NamestoreRecordLookupRespMsg) String() string {
459 return fmt.Sprintf("NamestoreRecordlLookupRespMsg{id=%d,found=%v,%d records}",
460 m.ID, m.Found == int16(enums.RC_YES), m.RdCount)
461}
462
463//----------------------------------------------------------------------
464// MSG_NAMESTORE_ZONE_TO_NAME
465//----------------------------------------------------------------------
466
467// NamestoreZoneToNameMsg resolves the name for a given key
180type NamestoreZoneToNameMsg struct { 468type NamestoreZoneToNameMsg struct {
181 GenericNamestoreMsg 469 GenericNamestoreMsg
182 470
183 ZoneKey *crypto.ZonePrivate // private zone key 471 KeyLen uint16 `order:"big"` // length of private key
184 ZonePublic *crypto.ZoneKey // public zone key 472 PubLen uint16 `order:"big"` // length of public key
473 ZoneKey *crypto.ZonePrivate `init:"Init"` // private zone key
474 ZonePublic *crypto.ZoneKey `init:"Init"` // public derived zone key
185} 475}
186 476
477// NewNamestoreZoneIterNextMsg creates a new message
478func NewNamestoreZoneToNameMsg(id uint32, zk *crypto.ZonePrivate, pk *crypto.ZoneKey) *NamestoreZoneToNameMsg {
479 var kl, pl uint16
480 if zk != nil {
481 kl = uint16(zk.KeySize() + 4)
482 }
483 if pk != nil {
484 pl = uint16(pk.KeySize() + 4)
485 }
486 size := kl + pl + 12
487 msg := &NamestoreZoneToNameMsg{
488 GenericNamestoreMsg: newGenericNamestoreMsg(id, size, enums.MSG_NAMESTORE_ZONE_TO_NAME),
489 KeyLen: kl,
490 PubLen: pl,
491 ZoneKey: zk,
492 ZonePublic: pk,
493 }
494 return msg
495}
496
497// Init called after unmarshalling a message to setup internal state
498func (m *NamestoreZoneToNameMsg) Init() error { return nil }
499
500// String returns a human-readable representation of the message.
501func (m *NamestoreZoneToNameMsg) String() string {
502 var key string
503 if m.ZoneKey == nil {
504 key = "sec:" + m.ZonePublic.ID()
505 } else {
506 key = "pub:" + m.ZoneKey.Public().ID()
507 }
508 return fmt.Sprintf("NamestoreZoneToNameMsg{id=%d,zk=%s}", m.ID, key)
509}
510
511//----------------------------------------------------------------------
512// MSG_NAMESTORE_ZONE_TO_NAME_RESPONSE
513//----------------------------------------------------------------------
514
515// NamestoreZoneToNameRespMsg is a response to NamestoreZoneToNameMsg
187type NamestoreZoneToNameRespMsg struct { 516type NamestoreZoneToNameRespMsg struct {
188 GenericNamestoreMsg 517 GenericNamestoreMsg
189 518
190 NameLen uint16 `order:"big"` // length of name 519 Status enums.ErrorCode `order:"big"` // result status (error code)
191 RdLen uint16 `order:"big"` // size of record data 520 NameLen uint16 `order:"big"` // length of name
192 RdCount uint16 `order:"big"` // number of records 521 RdLen uint16 `order:"big"` // size of record data
193 Status int16 `order:"big"` // result status 522 RdCount uint16 `order:"big"` // number of records
194 ZoneKey *crypto.ZonePrivate // private zone key 523 KeyLen uint16 `order:"big"` // length of key
524 ZoneKey *crypto.ZonePrivate `init:"Init"` // private zone key
195 Name []byte `size:"NameLen"` // name string 525 Name []byte `size:"NameLen"` // name string
196 Records []byte `size:"RdLen"` // serialized record data 526 Records []byte `size:"RdLen"` // serialized record data
527
528 // transient state
529 recset *blocks.RecordSet
530}
531
532// NewNamestoreNamestoreZoneToNameRespMsgMsg creates a new message
533func NewNamestoreZoneToNameRespMsg(id uint32, zk *crypto.ZonePrivate, label string, status enums.ErrorCode) *NamestoreZoneToNameRespMsg {
534 var kl uint16
535 if zk != nil {
536 kl = uint16(zk.KeySize() + 4)
537 }
538 nl := uint16(len(label) + 1)
539 size := kl + nl + 12
540 return &NamestoreZoneToNameRespMsg{
541 GenericNamestoreMsg: newGenericNamestoreMsg(id, size, enums.MSG_NAMESTORE_ZONE_TO_NAME_RESPONSE),
542 Status: status,
543 NameLen: nl,
544 Name: util.WriteCString(label),
545 KeyLen: kl,
546 ZoneKey: zk,
547 }
548}
549
550// Init called after unmarshalling a message to setup internal state
551func (m *NamestoreZoneToNameRespMsg) Init() error {
552 if m.recset == nil {
553 m.recset = new(blocks.RecordSet)
554 return data.Unmarshal(m.recset, m.Records)
555 }
556 return nil
197} 557}
198 558
559// AddRecords adds the record data to the message
560func (m *NamestoreZoneToNameRespMsg) AddRecords(rs *blocks.RecordSet) {
561 // make sure the record set is padded correctly
562 rs.SetPadding()
563 // copy recordset to message
564 m.RdCount = uint16(rs.Count)
565 m.Records = rs.RDATA()
566 m.RdLen = uint16(len(m.Records))
567 m.MsgSize += m.RdLen
568 m.recset = rs
569}
570
571// GetRecords returns the record set contained in message
572func (m *NamestoreZoneToNameRespMsg) GetRecords() blocks.RecordSet {
573 return *m.recset
574}
575
576// String returns a human-readable representation of the message.
577func (m *NamestoreZoneToNameRespMsg) String() string {
578 return fmt.Sprintf("NamestoreZoneToNameRespMsg{id=%d,zone=%s,label='%s',%d records}",
579 m.ID, m.ZoneKey.ID(), string(m.Name), m.RdCount)
580}
581
582//----------------------------------------------------------------------
583// MSG_NAMESTORE_TX_CONTROL
584//----------------------------------------------------------------------
585
586// NamestoreTxControlMsg to initiate a Tx control
199type NamestoreTxControlMsg struct { 587type NamestoreTxControlMsg struct {
200 GenericNamestoreMsg 588 GenericNamestoreMsg
201 589
202 Control uint16 `order:"big"` // type of control message 590 Reserved uint16 `order:"big"` // reserved
203 Reserved uint16 `order:"big"` // alignment 591 Control uint16 `order:"big"` // type of control message to send
204} 592}
205 593
594// NewNamestoreTxControlMsg creates a new message
595func NewNamestoreTxControlMsg(id uint32, ctrl uint16) *NamestoreTxControlMsg {
596 return &NamestoreTxControlMsg{
597 GenericNamestoreMsg: newGenericNamestoreMsg(id, 12, enums.MSG_NAMESTORE_TX_CONTROL),
598 Control: ctrl,
599 }
600}
601
602// Init called after unmarshalling a message to setup internal state
603func (m *NamestoreTxControlMsg) Init() error {
604 return nil
605}
606
607// String returns a human-readable representation of the message.
608func (m *NamestoreTxControlMsg) String() string {
609 return fmt.Sprintf("NamestoreTxControlMsg{id=%d,ctrl=%d}", m.ID, m.Control)
610}
611
612//----------------------------------------------------------------------
613// MSG_NAMESTORE_TX_CONTROL_RESULT
614//----------------------------------------------------------------------
615
616// NamestoreTxControlResultMsg is a response to a Tx control message
206type NamestoreTxControlResultMsg struct { 617type NamestoreTxControlResultMsg struct {
207 GenericNamestoreMsg 618 GenericNamestoreMsg
208 619
209 Control uint16 `order:"big"` // type of control message 620 Result enums.ErrorCode `order:"big"` // error code
210 Status uint16 `order:"big"` // result status
211 Error []byte `size:"*"` // error message (on status != OK)
212} 621}
213 622
214type NamestoreZoneMonStartMsg struct { 623// NewNamestoreTxControlResultMsg creates a new message
624func NewNamestoreTxControlResultMsg(id uint32, ec enums.ErrorCode) *NamestoreTxControlResultMsg {
625 return &NamestoreTxControlResultMsg{
626 GenericNamestoreMsg: newGenericNamestoreMsg(id, 12, enums.MSG_NAMESTORE_TX_CONTROL_RESULT),
627 Result: ec,
628 }
629}
630
631// Init called after unmarshalling a message to setup internal state
632func (m *NamestoreTxControlResultMsg) Init() error {
633 return nil
634}
635
636// String returns a human-readable representation of the message.
637func (m *NamestoreTxControlResultMsg) String() string {
638 return fmt.Sprintf("NamestoreTxControlResultMsg{id=%d,result=%s}", m.ID, m.Result)
639}
640
641//----------------------------------------------------------------------
642// MSG_NAMESTORE_MONITOR_START
643//----------------------------------------------------------------------
644
645// NamestoreMonitorStartMsg starts a monitor session
646type NamestoreMonitorStartMsg struct {
215 GenericNamestoreMsg 647 GenericNamestoreMsg
216 648
217 Iterate uint32 `order:"big"` // iterate over all records 649 Iterate enums.ResultCode `order:"big"` // iterate over all records
218 Filter uint16 `order:"big"` // filter flags 650 Filter uint16 `order:"big"` // filter flags
219 Reserved uint16 `order:"big"` // alignment 651 KeyLen uint16 `order:"big"` // length of key
220 ZoneKey *crypto.ZonePrivate // private zone key 652 ZoneKey *crypto.ZonePrivate `init:"Init"` // private zone key
653}
654
655// NewNamestoreMonitorStartMsg creates a new message
656func NewNamestoreMonitorStartMsg(id uint32, zk *crypto.ZonePrivate, iter enums.ResultCode, filter int) *NamestoreMonitorStartMsg {
657 var kl uint16
658 if zk != nil {
659 kl = uint16(zk.KeySize() + 4)
660 }
661 size := kl + 16
662 return &NamestoreMonitorStartMsg{
663 GenericNamestoreMsg: newGenericNamestoreMsg(id, size, enums.MSG_NAMESTORE_MONITOR_START),
664 Iterate: iter,
665 Filter: uint16(filter),
666 KeyLen: kl,
667 ZoneKey: zk,
668 }
669}
670
671// Init called after unmarshalling a message to setup internal state
672func (m *NamestoreMonitorStartMsg) Init() error { return nil }
673
674// String returns a human-readable representation of the message.
675func (m *NamestoreMonitorStartMsg) String() string {
676 return fmt.Sprintf("NamestoreMonitorStartMsg{id=%d,zone=%s,iter=%v,filter=%d}",
677 m.ID, m.ZoneKey.ID(), m.Iterate == enums.RC_OK, m.Filter)
221} 678}
222 679
223type NamestoreZoneMonNextMsg struct { 680//----------------------------------------------------------------------
681// MSG_NAMESTORE_MONITOR_NEXT
682//----------------------------------------------------------------------
683
684// NamestoreMonitorNextMsg to retrieve next set of results
685type NamestoreMonitorNextMsg struct {
224 GenericNamestoreMsg 686 GenericNamestoreMsg
225 687
226 Reserved uint32 `order:"big"` // alignment =0 688 Reserved uint32 `order:"big"` // alignment =0
227 Limit uint64 `order:"big"` // max. number of records in one go 689 Limit uint64 `order:"big"` // max. number of records in one go
228} 690}
691
692// NewNamestoreMonitorNextMsg creates a new message
693func NewNamestoreMonitorNextMsg(id uint32, limit uint64) *NamestoreMonitorNextMsg {
694 return &NamestoreMonitorNextMsg{
695 GenericNamestoreMsg: newGenericNamestoreMsg(id, 20, enums.MSG_NAMESTORE_MONITOR_NEXT),
696 Limit: limit,
697 }
698}
699
700// Init called after unmarshalling a message to setup internal state
701func (m *NamestoreMonitorNextMsg) Init() error { return nil }
702
703// String returns a human-readable representation of the message.
704func (m *NamestoreMonitorNextMsg) String() string {
705 return fmt.Sprintf("NamestoreMonitorNextMsg{id=%d,limit=%d}", m.ID, m.Limit)
706}