-
Notifications
You must be signed in to change notification settings - Fork 76
Expand file tree
/
Copy pathp2p.go
More file actions
530 lines (441 loc) · 17.8 KB
/
Copy pathp2p.go
File metadata and controls
530 lines (441 loc) · 17.8 KB
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
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
// Copyright 2026 Democratized Data Foundation
//
// Use of this software is governed by the Business Source License
// included in the file licenses/BSL.txt.
//
// As of the Change Date specified in that file, in accordance with
// the Business Source License, use of this software will be governed
// by the Apache License, Version 2.0, included in the file
// licenses/APL.txt.
package options
import (
"time"
"github.com/sourcenetwork/immutable"
"github.com/sourcenetwork/defradb/acp/identity"
)
// ActivePeersOptions contains options for ActivePeers operation.
type ActivePeersOptions struct {
// Identity is the identity of the actor performing the operation.
Identity immutable.Option[identity.Identity]
}
// GetIdentity returns the identity for the operation.
func (o *ActivePeersOptions) GetIdentity() immutable.Option[identity.Identity] {
return o.Identity
}
// ActivePeersOptionsBuilder is a builder for ActivePeersOptions.
type ActivePeersOptionsBuilder struct {
enumerableBuilder[ActivePeersOptions]
}
// ActivePeers creates a new ActivePeersOptionsBuilder instance.
func ActivePeers() *ActivePeersOptionsBuilder {
return &ActivePeersOptionsBuilder{}
}
// SetIdentity sets the identity for the operation.
func (b *ActivePeersOptionsBuilder) SetIdentity(id identity.Identity) *ActivePeersOptionsBuilder {
b.append(func(opts *ActivePeersOptions) {
opts.Identity = immutable.Some(id)
})
return b
}
// ConnectOptions contains options for Connect operation.
type ConnectOptions struct {
// Identity is the identity of the actor performing the operation.
Identity immutable.Option[identity.Identity]
}
// GetIdentity returns the identity for the operation.
func (o *ConnectOptions) GetIdentity() immutable.Option[identity.Identity] {
return o.Identity
}
// ConnectOptionsBuilder is a builder for ConnectOptions.
type ConnectOptionsBuilder struct {
enumerableBuilder[ConnectOptions]
}
// Connect creates a new ConnectOptionsBuilder instance.
func Connect() *ConnectOptionsBuilder {
return &ConnectOptionsBuilder{}
}
// SetIdentity sets the identity for the operation.
func (b *ConnectOptionsBuilder) SetIdentity(id identity.Identity) *ConnectOptionsBuilder {
b.append(func(opts *ConnectOptions) {
opts.Identity = immutable.Some(id)
})
return b
}
// DisconnectOptions contains options for Disconnect operation.
type DisconnectOptions struct {
// Identity is the identity of the actor performing the operation.
Identity immutable.Option[identity.Identity]
}
// GetIdentity returns the identity for the operation.
func (o *DisconnectOptions) GetIdentity() immutable.Option[identity.Identity] {
return o.Identity
}
// DisconnectOptionsBuilder is a builder for DisconnectOptions.
type DisconnectOptionsBuilder struct {
enumerableBuilder[DisconnectOptions]
}
// Disconnect creates a new DisconnectOptionsBuilder instance.
func Disconnect() *DisconnectOptionsBuilder {
return &DisconnectOptionsBuilder{}
}
// SetIdentity sets the identity for the operation.
func (b *DisconnectOptionsBuilder) SetIdentity(id identity.Identity) *DisconnectOptionsBuilder {
b.append(func(opts *DisconnectOptions) {
opts.Identity = immutable.Some(id)
})
return b
}
type PeerInfoOptions struct {
// Identity is the identity of the actor performing the operation.
Identity immutable.Option[identity.Identity]
}
// GetIdentity returns the identity for the operation.
func (o *PeerInfoOptions) GetIdentity() immutable.Option[identity.Identity] {
return o.Identity
}
// PeerInfoOptionsBuilder is a builder for PeerInfoOptions.
type PeerInfoOptionsBuilder struct {
enumerableBuilder[PeerInfoOptions]
}
// AddReplicator creates a new AddReplicatorOptionsBuilder instance.
func PeerInfo() *PeerInfoOptionsBuilder {
return &PeerInfoOptionsBuilder{}
}
// SetIdentity sets the identity for the operation.
func (b *PeerInfoOptionsBuilder) SetIdentity(id identity.Identity) *PeerInfoOptionsBuilder {
b.append(func(opts *PeerInfoOptions) {
opts.Identity = immutable.Some(id)
})
return b
}
// AddReplicatorOptions contains options for AddReplicator operation.
type AddReplicatorOptions struct {
// Identity is the identity of the actor performing the operation.
Identity immutable.Option[identity.Identity]
// CollectionNames is the list of collection names to replicate.
CollectionNames []string
}
// GetIdentity returns the identity for the operation.
func (o *AddReplicatorOptions) GetIdentity() immutable.Option[identity.Identity] {
return o.Identity
}
// AddReplicatorOptionsBuilder is a builder for AddReplicatorOptions.
type AddReplicatorOptionsBuilder struct {
enumerableBuilder[AddReplicatorOptions]
}
// AddReplicator creates a new AddReplicatorOptionsBuilder instance.
func AddReplicator() *AddReplicatorOptionsBuilder {
return &AddReplicatorOptionsBuilder{}
}
// SetIdentity sets the identity for the operation.
func (b *AddReplicatorOptionsBuilder) SetIdentity(id identity.Identity) *AddReplicatorOptionsBuilder {
b.append(func(opts *AddReplicatorOptions) {
opts.Identity = immutable.Some(id)
})
return b
}
// SetCollectionNames sets the collection names to replicate.
func (b *AddReplicatorOptionsBuilder) SetCollectionNames(names []string) *AddReplicatorOptionsBuilder {
b.append(func(opts *AddReplicatorOptions) {
if names != nil {
opts.CollectionNames = make([]string, len(names))
copy(opts.CollectionNames, names)
}
})
return b
}
// DeleteReplicatorOptions contains options for DeleteReplicator operation.
type DeleteReplicatorOptions struct {
// Identity is the identity of the actor performing the operation.
Identity immutable.Option[identity.Identity]
// CollectionNames is the list of collection names to stop replicating.
CollectionNames []string
}
// GetIdentity returns the identity for the operation.
func (o *DeleteReplicatorOptions) GetIdentity() immutable.Option[identity.Identity] {
return o.Identity
}
// DeleteReplicatorOptionsBuilder is a builder for DeleteReplicatorOptions.
type DeleteReplicatorOptionsBuilder struct {
enumerableBuilder[DeleteReplicatorOptions]
}
// DeleteReplicator creates a new DeleteReplicatorOptionsBuilder instance.
func DeleteReplicator() *DeleteReplicatorOptionsBuilder {
return &DeleteReplicatorOptionsBuilder{}
}
// SetIdentity sets the identity for the operation.
func (b *DeleteReplicatorOptionsBuilder) SetIdentity(id identity.Identity) *DeleteReplicatorOptionsBuilder {
b.append(func(opts *DeleteReplicatorOptions) {
opts.Identity = immutable.Some(id)
})
return b
}
// SetCollectionNames sets the collection names to stop replicating.
func (b *DeleteReplicatorOptionsBuilder) SetCollectionNames(names []string) *DeleteReplicatorOptionsBuilder {
b.append(func(opts *DeleteReplicatorOptions) {
if names != nil {
opts.CollectionNames = make([]string, len(names))
copy(opts.CollectionNames, names)
}
})
return b
}
// ListReplicatorsOptions contains options for GetAllReplicators operation.
type ListReplicatorsOptions struct {
// Identity is the identity of the actor performing the operation.
Identity immutable.Option[identity.Identity]
}
// GetIdentity returns the identity for the operation.
func (o *ListReplicatorsOptions) GetIdentity() immutable.Option[identity.Identity] {
return o.Identity
}
// ListReplicatorsOptionsBuilder is a builder for GetAllReplicatorsOptions.
type ListReplicatorsOptionsBuilder struct {
enumerableBuilder[ListReplicatorsOptions]
}
// ListReplicators creates a new GetAllReplicatorsOptionsBuilder instance.
func ListReplicators() *ListReplicatorsOptionsBuilder {
return &ListReplicatorsOptionsBuilder{}
}
// SetIdentity sets the identity for the operation.
func (b *ListReplicatorsOptionsBuilder) SetIdentity(id identity.Identity) *ListReplicatorsOptionsBuilder {
b.append(func(opts *ListReplicatorsOptions) {
opts.Identity = immutable.Some(id)
})
return b
}
// AddP2PCollectionsOptions contains options for AddP2PCollections operation.
type AddP2PCollectionsOptions struct {
// Identity is the identity of the actor performing the operation.
Identity immutable.Option[identity.Identity]
}
// GetIdentity returns the identity for the operation.
func (o *AddP2PCollectionsOptions) GetIdentity() immutable.Option[identity.Identity] {
return o.Identity
}
// AddP2PCollectionsOptionsBuilder is a builder for AddP2PCollectionsOptions.
type AddP2PCollectionsOptionsBuilder struct {
enumerableBuilder[AddP2PCollectionsOptions]
}
// AddP2PCollections creates a new AddP2PCollectionsOptionsBuilder instance.
func AddP2PCollections() *AddP2PCollectionsOptionsBuilder {
return &AddP2PCollectionsOptionsBuilder{}
}
// SetIdentity sets the identity for the operation.
func (b *AddP2PCollectionsOptionsBuilder) SetIdentity(id identity.Identity) *AddP2PCollectionsOptionsBuilder {
b.append(func(opts *AddP2PCollectionsOptions) {
opts.Identity = immutable.Some(id)
})
return b
}
// DeleteP2PCollectionsOptions contains options for RemoveP2PCollections operation.
type DeleteP2PCollectionsOptions struct {
// Identity is the identity of the actor performing the operation.
Identity immutable.Option[identity.Identity]
}
// GetIdentity returns the identity for the operation.
func (o *DeleteP2PCollectionsOptions) GetIdentity() immutable.Option[identity.Identity] {
return o.Identity
}
// DeleteP2PCollectionsOptionsBuilder is a builder for DeleteP2PCollectionsOptions.
type DeleteP2PCollectionsOptionsBuilder struct {
enumerableBuilder[DeleteP2PCollectionsOptions]
}
// DeleteP2PCollections creates a new RemoveP2PCollectionsOptionsBuilder instance.
func DeleteP2PCollections() *DeleteP2PCollectionsOptionsBuilder {
return &DeleteP2PCollectionsOptionsBuilder{}
}
// SetIdentity sets the identity for the operation.
func (b *DeleteP2PCollectionsOptionsBuilder) SetIdentity(id identity.Identity) *DeleteP2PCollectionsOptionsBuilder {
b.append(func(opts *DeleteP2PCollectionsOptions) {
opts.Identity = immutable.Some(id)
})
return b
}
// ListP2PCollectionsOptions contains options for GetAllP2PCollections operation.
type ListP2PCollectionsOptions struct {
// Identity is the identity of the actor performing the operation.
Identity immutable.Option[identity.Identity]
}
// GetIdentity returns the identity for the operation.
func (o *ListP2PCollectionsOptions) GetIdentity() immutable.Option[identity.Identity] {
return o.Identity
}
// ListP2PCollectionsOptionsBuilder is a builder for ListP2PCollectionsOptions.
type ListP2PCollectionsOptionsBuilder struct {
enumerableBuilder[ListP2PCollectionsOptions]
}
// ListP2PCollections creates a new GetAllP2PCollectionsOptionsBuilder instance.
func ListP2PCollections() *ListP2PCollectionsOptionsBuilder {
return &ListP2PCollectionsOptionsBuilder{}
}
// SetIdentity sets the identity for the operation.
func (b *ListP2PCollectionsOptionsBuilder) SetIdentity(id identity.Identity) *ListP2PCollectionsOptionsBuilder {
b.append(func(opts *ListP2PCollectionsOptions) {
opts.Identity = immutable.Some(id)
})
return b
}
// AddP2PDocumentsOptions contains options for AddP2PDocuments operation.
type AddP2PDocumentsOptions struct {
// Identity is the identity of the actor performing the operation.
Identity immutable.Option[identity.Identity]
}
// GetIdentity returns the identity for the operation.
func (o *AddP2PDocumentsOptions) GetIdentity() immutable.Option[identity.Identity] {
return o.Identity
}
// AddP2PDocumentsOptionsBuilder is a builder for AddP2PDocumentsOptions.
type AddP2PDocumentsOptionsBuilder struct {
enumerableBuilder[AddP2PDocumentsOptions]
}
// AddP2PDocuments creates a new AddP2PDocumentsOptionsBuilder instance.
func AddP2PDocuments() *AddP2PDocumentsOptionsBuilder {
return &AddP2PDocumentsOptionsBuilder{}
}
// SetIdentity sets the identity for the operation.
func (b *AddP2PDocumentsOptionsBuilder) SetIdentity(id identity.Identity) *AddP2PDocumentsOptionsBuilder {
b.append(func(opts *AddP2PDocumentsOptions) {
opts.Identity = immutable.Some(id)
})
return b
}
// SyncCollectionVersionsOptions contains options for SyncCollectionVersions operation.
type SyncCollectionVersionsOptions struct {
// Identity is the identity of the actor performing the operation.
Identity immutable.Option[identity.Identity]
}
// GetIdentity returns the identity for the operation.
func (o *SyncCollectionVersionsOptions) GetIdentity() immutable.Option[identity.Identity] {
return o.Identity
}
// SyncCollectionVersionsOptionsBuilder is a builder for SyncCollectionVersionsOptions.
type SyncCollectionVersionsOptionsBuilder struct {
enumerableBuilder[SyncCollectionVersionsOptions]
}
// SyncCollectionVersions creates a new SyncCollectionVersionsOptionsBuilder instance.
func SyncCollectionVersions() *SyncCollectionVersionsOptionsBuilder {
return &SyncCollectionVersionsOptionsBuilder{}
}
// SetIdentity sets the identity for the operation.
func (b *SyncCollectionVersionsOptionsBuilder) SetIdentity(id identity.Identity) *SyncCollectionVersionsOptionsBuilder {
b.append(func(opts *SyncCollectionVersionsOptions) {
opts.Identity = immutable.Some(id)
})
return b
}
// SyncBranchableCollectionOptions contains options for SyncBranchableCollection operation.
type SyncBranchableCollectionOptions struct {
// Identity is the identity of the actor performing the operation.
Identity immutable.Option[identity.Identity]
}
// GetIdentity returns the identity for the operation.
func (o *SyncBranchableCollectionOptions) GetIdentity() immutable.Option[identity.Identity] {
return o.Identity
}
// SyncBranchableCollectionOptionsBuilder is a builder for SyncBranchableCollectionOptions.
type SyncBranchableCollectionOptionsBuilder struct {
enumerableBuilder[SyncBranchableCollectionOptions]
}
// SyncBranchableCollection creates a new SyncBranchableCollectionOptionsBuilder instance.
func SyncBranchableCollection() *SyncBranchableCollectionOptionsBuilder {
return &SyncBranchableCollectionOptionsBuilder{}
}
// SetIdentity sets the identity for the operation.
func (b *SyncBranchableCollectionOptionsBuilder) SetIdentity(
id identity.Identity,
) *SyncBranchableCollectionOptionsBuilder {
b.append(func(opts *SyncBranchableCollectionOptions) {
opts.Identity = immutable.Some(id)
})
return b
}
// DeleteP2PDocumentsOptions contains options for RemoveP2PDocuments operation.
type DeleteP2PDocumentsOptions struct {
// Identity is the identity of the actor performing the operation.
Identity immutable.Option[identity.Identity]
}
// GetIdentity returns the identity for the operation.
func (o *DeleteP2PDocumentsOptions) GetIdentity() immutable.Option[identity.Identity] {
return o.Identity
}
// DeleteP2PDocumentsOptionsBuilder is a builder for DeleteP2PDocumentsOptions.
type DeleteP2PDocumentsOptionsBuilder struct {
enumerableBuilder[DeleteP2PDocumentsOptions]
}
// DeleteP2PDocuments creates a new RemoveP2PDocumentsOptionsBuilder instance.
func DeleteP2PDocuments() *DeleteP2PDocumentsOptionsBuilder {
return &DeleteP2PDocumentsOptionsBuilder{}
}
// SetIdentity sets the identity for the operation.
func (b *DeleteP2PDocumentsOptionsBuilder) SetIdentity(id identity.Identity) *DeleteP2PDocumentsOptionsBuilder {
b.append(func(opts *DeleteP2PDocumentsOptions) {
opts.Identity = immutable.Some(id)
})
return b
}
// ListP2PDocumentsOptions contains options for GetAllP2PDocuments operation.
type ListP2PDocumentsOptions struct {
// Identity is the identity of the actor performing the operation.
Identity immutable.Option[identity.Identity]
}
// GetIdentity returns the identity for the operation.
func (o *ListP2PDocumentsOptions) GetIdentity() immutable.Option[identity.Identity] {
return o.Identity
}
// ListP2PDocumentsOptionsBuilder is a builder for ListP2PDocumentsOptions.
type ListP2PDocumentsOptionsBuilder struct {
enumerableBuilder[ListP2PDocumentsOptions]
}
// ListP2PDocuments creates a new GetAllP2PDocumentsOptionsBuilder instance.
func ListP2PDocuments() *ListP2PDocumentsOptionsBuilder {
return &ListP2PDocumentsOptionsBuilder{}
}
// SetIdentity sets the identity for the operation.
func (b *ListP2PDocumentsOptionsBuilder) SetIdentity(id identity.Identity) *ListP2PDocumentsOptionsBuilder {
b.append(func(opts *ListP2PDocumentsOptions) {
opts.Identity = immutable.Some(id)
})
return b
}
// SyncDocumentsOptions contains options for SyncDocuments operation.
type SyncDocumentsOptions struct {
// Identity is the identity of the actor performing the operation.
Identity immutable.Option[identity.Identity]
// BlockSyncTimeout, when set, overrides the node's default per-block fetch timeout for this
// sync only. It bounds how long the node waits for each linked block to arrive from a peer;
// a peer that is slow to authorize or serve a block past this budget causes the sync to fail
// with a block-sync timeout. It does not bound the overall operation — use a context deadline
// for that.
BlockSyncTimeout immutable.Option[time.Duration]
}
// GetIdentity returns the identity for the operation.
func (o *SyncDocumentsOptions) GetIdentity() immutable.Option[identity.Identity] {
return o.Identity
}
// GetBlockSyncTimeout returns the per-block fetch timeout override for the operation, if set.
func (o *SyncDocumentsOptions) GetBlockSyncTimeout() immutable.Option[time.Duration] {
return o.BlockSyncTimeout
}
// SyncDocumentsOptionsBuilder is a builder for SyncDocumentsOptions.
type SyncDocumentsOptionsBuilder struct {
enumerableBuilder[SyncDocumentsOptions]
}
// SyncDocuments creates a new SyncDocumentsOptionsBuilder instance.
func SyncDocuments() *SyncDocumentsOptionsBuilder {
return &SyncDocumentsOptionsBuilder{}
}
// SetIdentity sets the identity for the operation.
func (b *SyncDocumentsOptionsBuilder) SetIdentity(id identity.Identity) *SyncDocumentsOptionsBuilder {
b.append(func(opts *SyncDocumentsOptions) {
opts.Identity = immutable.Some(id)
})
return b
}
// SetBlockSyncTimeout overrides the node's default per-block fetch timeout for this sync.
func (b *SyncDocumentsOptionsBuilder) SetBlockSyncTimeout(timeout time.Duration) *SyncDocumentsOptionsBuilder {
b.append(func(opts *SyncDocumentsOptions) {
opts.BlockSyncTimeout = immutable.Some(timeout)
})
return b
}