@@ -236,6 +236,9 @@ func (c *Client) FindProviders(ctx context.Context, key cid.Cid) (providers iter
236
236
return & measuringIter [iter.Result [types.Record ]]{Iter : it , ctx : ctx , m : m }, nil
237
237
}
238
238
239
+ // Provide publishes an [types.AnnouncementRecord] to the server, signed by you.
240
+ // This [Client] must be configured with [WithIdentity] and [WithProviderInfo]
241
+ // in order to be able to provide.
239
242
func (c * Client ) Provide (ctx context.Context , announcements ... types.AnnouncementRequest ) (iter.ResultIter [* types.AnnouncementRecord ], error ) {
240
243
if err := c .canProvide (); err != nil {
241
244
return nil , err
@@ -282,7 +285,27 @@ func (c *Client) Provide(ctx context.Context, announcements ...types.Announcemen
282
285
req := jsontypes.AnnounceProvidersRequest {
283
286
Providers : records ,
284
287
}
288
+ return c .provide (ctx , url , req )
289
+ }
290
+
291
+ // ProvideRecords publishes [types.AnnouncementRecord] to the server with already
292
+ // signed records. This can be useful if you've gotten an announcement from somewhere
293
+ // else and you wish to spread it through the network.
294
+ //
295
+ // If the records aren't valid, an error will be returned.
296
+ func (c * Client ) ProvideRecords (ctx context.Context , records ... * types.AnnouncementRecord ) (iter.ResultIter [* types.AnnouncementRecord ], error ) {
297
+ providerRecords := make ([]types.Record , len (records ))
298
+ for i , record := range records {
299
+ if err := record .Verify (); err != nil {
300
+ return nil , err
301
+ }
302
+ providerRecords [i ] = records [i ]
303
+ }
285
304
305
+ url := c .baseURL + "/routing/v1/providers"
306
+ req := jsontypes.AnnounceProvidersRequest {
307
+ Providers : providerRecords ,
308
+ }
286
309
return c .provide (ctx , url , req )
287
310
}
288
311
@@ -429,7 +452,9 @@ func (c *Client) FindPeers(ctx context.Context, pid peer.ID) (peers iter.ResultI
429
452
return & measuringIter [iter.Result [* types.PeerRecord ]]{Iter : it , ctx : ctx , m : m }, nil
430
453
}
431
454
432
- // ProvidePeer provides information regarding your own peer, setup with [WithProviderInfo].
455
+ // ProvidePeer publishes an [types.AnnouncementRecord] to the server with information
456
+ // regarding your own peer. This [Client] must be configured with [WithIdentity]
457
+ // and [WithProviderInfo] in order to be able to provide.
433
458
func (c * Client ) ProvidePeer (ctx context.Context , ttl time.Duration , metadata []byte ) (iter.ResultIter [* types.AnnouncementRecord ], error ) {
434
459
if err := c .canProvide (); err != nil {
435
460
return nil , err
@@ -472,6 +497,27 @@ func (c *Client) ProvidePeer(ctx context.Context, ttl time.Duration, metadata []
472
497
return c .provide (ctx , url , req )
473
498
}
474
499
500
+ // ProvidePeerRecords publishes [types.AnnouncementRecord] to the server with already
501
+ // signed records. This can be useful if you've gotten an announcement from somewhere
502
+ // else and you wish to spread it through the network.
503
+ //
504
+ // If the records aren't valid, an error will be returned.
505
+ func (c * Client ) ProvidePeerRecords (ctx context.Context , records ... * types.AnnouncementRecord ) (iter.ResultIter [* types.AnnouncementRecord ], error ) {
506
+ providerRecords := make ([]types.Record , len (records ))
507
+ for i , record := range records {
508
+ if err := record .Verify (); err != nil {
509
+ return nil , err
510
+ }
511
+ providerRecords [i ] = records [i ]
512
+ }
513
+
514
+ url := c .baseURL + "/routing/v1/peers"
515
+ req := jsontypes.AnnouncePeersRequest {
516
+ Peers : providerRecords ,
517
+ }
518
+ return c .provide (ctx , url , req )
519
+ }
520
+
475
521
// GetIPNS tries to retrieve the [ipns.Record] for the given [ipns.Name]. The record is
476
522
// validated against the given name. If validation fails, an error is returned, but no
477
523
// record.
0 commit comments