forked from keybase/client
-
Notifications
You must be signed in to change notification settings - Fork 0
/
block.go
472 lines (423 loc) · 13.5 KB
/
block.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
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
// Auto-generated by avdl-compiler v1.3.25 (https://github.com/keybase/node-avdl-compiler)
// Input file: avdl/keybase1/block.avdl
package keybase1
import (
"github.com/keybase/go-framed-msgpack-rpc/rpc"
context "golang.org/x/net/context"
)
type BlockStatus int
const (
BlockStatus_UNKNOWN BlockStatus = 0
BlockStatus_LIVE BlockStatus = 1
BlockStatus_ARCHIVED BlockStatus = 2
)
func (o BlockStatus) DeepCopy() BlockStatus { return o }
var BlockStatusMap = map[string]BlockStatus{
"UNKNOWN": 0,
"LIVE": 1,
"ARCHIVED": 2,
}
var BlockStatusRevMap = map[BlockStatus]string{
0: "UNKNOWN",
1: "LIVE",
2: "ARCHIVED",
}
func (e BlockStatus) String() string {
if v, ok := BlockStatusRevMap[e]; ok {
return v
}
return ""
}
type GetBlockRes struct {
BlockKey string `codec:"blockKey" json:"blockKey"`
Buf []byte `codec:"buf" json:"buf"`
Size int `codec:"size" json:"size"`
Status BlockStatus `codec:"status" json:"status"`
}
func (o GetBlockRes) DeepCopy() GetBlockRes {
return GetBlockRes{
BlockKey: o.BlockKey,
Buf: (func(x []byte) []byte {
if x == nil {
return nil
}
return append([]byte{}, x...)
})(o.Buf),
Size: o.Size,
Status: o.Status.DeepCopy(),
}
}
type BlockRefNonce [8]byte
func (o BlockRefNonce) DeepCopy() BlockRefNonce {
var ret BlockRefNonce
copy(ret[:], o[:])
return ret
}
type BlockReference struct {
Bid BlockIdCombo `codec:"bid" json:"bid"`
Nonce BlockRefNonce `codec:"nonce" json:"nonce"`
ChargedTo UserOrTeamID `codec:"chargedTo" json:"chargedTo"`
}
func (o BlockReference) DeepCopy() BlockReference {
return BlockReference{
Bid: o.Bid.DeepCopy(),
Nonce: o.Nonce.DeepCopy(),
ChargedTo: o.ChargedTo.DeepCopy(),
}
}
type BlockReferenceCount struct {
Ref BlockReference `codec:"ref" json:"ref"`
LiveCount int `codec:"liveCount" json:"liveCount"`
}
func (o BlockReferenceCount) DeepCopy() BlockReferenceCount {
return BlockReferenceCount{
Ref: o.Ref.DeepCopy(),
LiveCount: o.LiveCount,
}
}
type DowngradeReferenceRes struct {
Completed []BlockReferenceCount `codec:"completed" json:"completed"`
Failed BlockReference `codec:"failed" json:"failed"`
}
func (o DowngradeReferenceRes) DeepCopy() DowngradeReferenceRes {
return DowngradeReferenceRes{
Completed: (func(x []BlockReferenceCount) []BlockReferenceCount {
if x == nil {
return nil
}
ret := make([]BlockReferenceCount, len(x))
for i, v := range x {
vCopy := v.DeepCopy()
ret[i] = vCopy
}
return ret
})(o.Completed),
Failed: o.Failed.DeepCopy(),
}
}
type BlockPingResponse struct {
}
func (o BlockPingResponse) DeepCopy() BlockPingResponse {
return BlockPingResponse{}
}
type GetSessionChallengeArg struct {
}
type AuthenticateSessionArg struct {
Signature string `codec:"signature" json:"signature"`
}
type PutBlockArg struct {
Bid BlockIdCombo `codec:"bid" json:"bid"`
Folder string `codec:"folder" json:"folder"`
BlockKey string `codec:"blockKey" json:"blockKey"`
Buf []byte `codec:"buf" json:"buf"`
}
type PutBlockAgainArg struct {
Folder string `codec:"folder" json:"folder"`
Ref BlockReference `codec:"ref" json:"ref"`
BlockKey string `codec:"blockKey" json:"blockKey"`
Buf []byte `codec:"buf" json:"buf"`
}
type GetBlockArg struct {
Bid BlockIdCombo `codec:"bid" json:"bid"`
Folder string `codec:"folder" json:"folder"`
SizeOnly bool `codec:"sizeOnly" json:"sizeOnly"`
}
type AddReferenceArg struct {
Folder string `codec:"folder" json:"folder"`
Ref BlockReference `codec:"ref" json:"ref"`
}
type DelReferenceArg struct {
Folder string `codec:"folder" json:"folder"`
Ref BlockReference `codec:"ref" json:"ref"`
}
type ArchiveReferenceArg struct {
Folder string `codec:"folder" json:"folder"`
Refs []BlockReference `codec:"refs" json:"refs"`
}
type DelReferenceWithCountArg struct {
Folder string `codec:"folder" json:"folder"`
Refs []BlockReference `codec:"refs" json:"refs"`
}
type ArchiveReferenceWithCountArg struct {
Folder string `codec:"folder" json:"folder"`
Refs []BlockReference `codec:"refs" json:"refs"`
}
type GetUserQuotaInfoArg struct {
}
type GetTeamQuotaInfoArg struct {
Tid TeamID `codec:"tid" json:"tid"`
}
type BlockPingArg struct {
}
type BlockInterface interface {
GetSessionChallenge(context.Context) (ChallengeInfo, error)
AuthenticateSession(context.Context, string) error
PutBlock(context.Context, PutBlockArg) error
PutBlockAgain(context.Context, PutBlockAgainArg) error
GetBlock(context.Context, GetBlockArg) (GetBlockRes, error)
AddReference(context.Context, AddReferenceArg) error
DelReference(context.Context, DelReferenceArg) error
ArchiveReference(context.Context, ArchiveReferenceArg) ([]BlockReference, error)
DelReferenceWithCount(context.Context, DelReferenceWithCountArg) (DowngradeReferenceRes, error)
ArchiveReferenceWithCount(context.Context, ArchiveReferenceWithCountArg) (DowngradeReferenceRes, error)
GetUserQuotaInfo(context.Context) ([]byte, error)
GetTeamQuotaInfo(context.Context, TeamID) ([]byte, error)
BlockPing(context.Context) (BlockPingResponse, error)
}
func BlockProtocol(i BlockInterface) rpc.Protocol {
return rpc.Protocol{
Name: "keybase.1.block",
Methods: map[string]rpc.ServeHandlerDescription{
"getSessionChallenge": {
MakeArg: func() interface{} {
var ret [1]GetSessionChallengeArg
return &ret
},
Handler: func(ctx context.Context, args interface{}) (ret interface{}, err error) {
ret, err = i.GetSessionChallenge(ctx)
return
},
MethodType: rpc.MethodCall,
},
"authenticateSession": {
MakeArg: func() interface{} {
var ret [1]AuthenticateSessionArg
return &ret
},
Handler: func(ctx context.Context, args interface{}) (ret interface{}, err error) {
typedArgs, ok := args.(*[1]AuthenticateSessionArg)
if !ok {
err = rpc.NewTypeError((*[1]AuthenticateSessionArg)(nil), args)
return
}
err = i.AuthenticateSession(ctx, typedArgs[0].Signature)
return
},
MethodType: rpc.MethodCall,
},
"putBlock": {
MakeArg: func() interface{} {
var ret [1]PutBlockArg
return &ret
},
Handler: func(ctx context.Context, args interface{}) (ret interface{}, err error) {
typedArgs, ok := args.(*[1]PutBlockArg)
if !ok {
err = rpc.NewTypeError((*[1]PutBlockArg)(nil), args)
return
}
err = i.PutBlock(ctx, typedArgs[0])
return
},
MethodType: rpc.MethodCall,
},
"putBlockAgain": {
MakeArg: func() interface{} {
var ret [1]PutBlockAgainArg
return &ret
},
Handler: func(ctx context.Context, args interface{}) (ret interface{}, err error) {
typedArgs, ok := args.(*[1]PutBlockAgainArg)
if !ok {
err = rpc.NewTypeError((*[1]PutBlockAgainArg)(nil), args)
return
}
err = i.PutBlockAgain(ctx, typedArgs[0])
return
},
MethodType: rpc.MethodCall,
},
"getBlock": {
MakeArg: func() interface{} {
var ret [1]GetBlockArg
return &ret
},
Handler: func(ctx context.Context, args interface{}) (ret interface{}, err error) {
typedArgs, ok := args.(*[1]GetBlockArg)
if !ok {
err = rpc.NewTypeError((*[1]GetBlockArg)(nil), args)
return
}
ret, err = i.GetBlock(ctx, typedArgs[0])
return
},
MethodType: rpc.MethodCall,
},
"addReference": {
MakeArg: func() interface{} {
var ret [1]AddReferenceArg
return &ret
},
Handler: func(ctx context.Context, args interface{}) (ret interface{}, err error) {
typedArgs, ok := args.(*[1]AddReferenceArg)
if !ok {
err = rpc.NewTypeError((*[1]AddReferenceArg)(nil), args)
return
}
err = i.AddReference(ctx, typedArgs[0])
return
},
MethodType: rpc.MethodCall,
},
"delReference": {
MakeArg: func() interface{} {
var ret [1]DelReferenceArg
return &ret
},
Handler: func(ctx context.Context, args interface{}) (ret interface{}, err error) {
typedArgs, ok := args.(*[1]DelReferenceArg)
if !ok {
err = rpc.NewTypeError((*[1]DelReferenceArg)(nil), args)
return
}
err = i.DelReference(ctx, typedArgs[0])
return
},
MethodType: rpc.MethodCall,
},
"archiveReference": {
MakeArg: func() interface{} {
var ret [1]ArchiveReferenceArg
return &ret
},
Handler: func(ctx context.Context, args interface{}) (ret interface{}, err error) {
typedArgs, ok := args.(*[1]ArchiveReferenceArg)
if !ok {
err = rpc.NewTypeError((*[1]ArchiveReferenceArg)(nil), args)
return
}
ret, err = i.ArchiveReference(ctx, typedArgs[0])
return
},
MethodType: rpc.MethodCall,
},
"delReferenceWithCount": {
MakeArg: func() interface{} {
var ret [1]DelReferenceWithCountArg
return &ret
},
Handler: func(ctx context.Context, args interface{}) (ret interface{}, err error) {
typedArgs, ok := args.(*[1]DelReferenceWithCountArg)
if !ok {
err = rpc.NewTypeError((*[1]DelReferenceWithCountArg)(nil), args)
return
}
ret, err = i.DelReferenceWithCount(ctx, typedArgs[0])
return
},
MethodType: rpc.MethodCall,
},
"archiveReferenceWithCount": {
MakeArg: func() interface{} {
var ret [1]ArchiveReferenceWithCountArg
return &ret
},
Handler: func(ctx context.Context, args interface{}) (ret interface{}, err error) {
typedArgs, ok := args.(*[1]ArchiveReferenceWithCountArg)
if !ok {
err = rpc.NewTypeError((*[1]ArchiveReferenceWithCountArg)(nil), args)
return
}
ret, err = i.ArchiveReferenceWithCount(ctx, typedArgs[0])
return
},
MethodType: rpc.MethodCall,
},
"getUserQuotaInfo": {
MakeArg: func() interface{} {
var ret [1]GetUserQuotaInfoArg
return &ret
},
Handler: func(ctx context.Context, args interface{}) (ret interface{}, err error) {
ret, err = i.GetUserQuotaInfo(ctx)
return
},
MethodType: rpc.MethodCall,
},
"getTeamQuotaInfo": {
MakeArg: func() interface{} {
var ret [1]GetTeamQuotaInfoArg
return &ret
},
Handler: func(ctx context.Context, args interface{}) (ret interface{}, err error) {
typedArgs, ok := args.(*[1]GetTeamQuotaInfoArg)
if !ok {
err = rpc.NewTypeError((*[1]GetTeamQuotaInfoArg)(nil), args)
return
}
ret, err = i.GetTeamQuotaInfo(ctx, typedArgs[0].Tid)
return
},
MethodType: rpc.MethodCall,
},
"blockPing": {
MakeArg: func() interface{} {
var ret [1]BlockPingArg
return &ret
},
Handler: func(ctx context.Context, args interface{}) (ret interface{}, err error) {
ret, err = i.BlockPing(ctx)
return
},
MethodType: rpc.MethodCall,
},
},
}
}
type BlockClient struct {
Cli rpc.GenericClient
}
func (c BlockClient) GetSessionChallenge(ctx context.Context) (res ChallengeInfo, err error) {
err = c.Cli.Call(ctx, "keybase.1.block.getSessionChallenge", []interface{}{GetSessionChallengeArg{}}, &res)
return
}
func (c BlockClient) AuthenticateSession(ctx context.Context, signature string) (err error) {
__arg := AuthenticateSessionArg{Signature: signature}
err = c.Cli.Call(ctx, "keybase.1.block.authenticateSession", []interface{}{__arg}, nil)
return
}
func (c BlockClient) PutBlock(ctx context.Context, __arg PutBlockArg) (err error) {
err = c.Cli.Call(ctx, "keybase.1.block.putBlock", []interface{}{__arg}, nil)
return
}
func (c BlockClient) PutBlockAgain(ctx context.Context, __arg PutBlockAgainArg) (err error) {
err = c.Cli.Call(ctx, "keybase.1.block.putBlockAgain", []interface{}{__arg}, nil)
return
}
func (c BlockClient) GetBlock(ctx context.Context, __arg GetBlockArg) (res GetBlockRes, err error) {
err = c.Cli.Call(ctx, "keybase.1.block.getBlock", []interface{}{__arg}, &res)
return
}
func (c BlockClient) AddReference(ctx context.Context, __arg AddReferenceArg) (err error) {
err = c.Cli.Call(ctx, "keybase.1.block.addReference", []interface{}{__arg}, nil)
return
}
func (c BlockClient) DelReference(ctx context.Context, __arg DelReferenceArg) (err error) {
err = c.Cli.Call(ctx, "keybase.1.block.delReference", []interface{}{__arg}, nil)
return
}
func (c BlockClient) ArchiveReference(ctx context.Context, __arg ArchiveReferenceArg) (res []BlockReference, err error) {
err = c.Cli.Call(ctx, "keybase.1.block.archiveReference", []interface{}{__arg}, &res)
return
}
func (c BlockClient) DelReferenceWithCount(ctx context.Context, __arg DelReferenceWithCountArg) (res DowngradeReferenceRes, err error) {
err = c.Cli.Call(ctx, "keybase.1.block.delReferenceWithCount", []interface{}{__arg}, &res)
return
}
func (c BlockClient) ArchiveReferenceWithCount(ctx context.Context, __arg ArchiveReferenceWithCountArg) (res DowngradeReferenceRes, err error) {
err = c.Cli.Call(ctx, "keybase.1.block.archiveReferenceWithCount", []interface{}{__arg}, &res)
return
}
func (c BlockClient) GetUserQuotaInfo(ctx context.Context) (res []byte, err error) {
err = c.Cli.Call(ctx, "keybase.1.block.getUserQuotaInfo", []interface{}{GetUserQuotaInfoArg{}}, &res)
return
}
func (c BlockClient) GetTeamQuotaInfo(ctx context.Context, tid TeamID) (res []byte, err error) {
__arg := GetTeamQuotaInfoArg{Tid: tid}
err = c.Cli.Call(ctx, "keybase.1.block.getTeamQuotaInfo", []interface{}{__arg}, &res)
return
}
func (c BlockClient) BlockPing(ctx context.Context) (res BlockPingResponse, err error) {
err = c.Cli.Call(ctx, "keybase.1.block.blockPing", []interface{}{BlockPingArg{}}, &res)
return
}