diff --git a/routing/http/client/client.go b/routing/http/client/client.go index 0e3fb4931..07bb19cea 100644 --- a/routing/http/client/client.go +++ b/routing/http/client/client.go @@ -236,6 +236,9 @@ func (c *Client) FindProviders(ctx context.Context, key cid.Cid) (providers iter return &measuringIter[iter.Result[types.Record]]{Iter: it, ctx: ctx, m: m}, nil } +// Provide publishes an [types.AnnouncementRecord] to the server, signed by you. +// This [Client] must be configured with [WithIdentity] and [WithProviderInfo] +// in order to be able to provide. func (c *Client) Provide(ctx context.Context, announcements ...types.AnnouncementRequest) (iter.ResultIter[*types.AnnouncementRecord], error) { if err := c.canProvide(); err != nil { return nil, err @@ -282,7 +285,27 @@ func (c *Client) Provide(ctx context.Context, announcements ...types.Announcemen req := jsontypes.AnnounceProvidersRequest{ Providers: records, } + return c.provide(ctx, url, req) +} + +// ProvideRecords publishes [types.AnnouncementRecord] to the server with already +// signed records. This can be useful if you've gotten an announcement from somewhere +// else and you wish to spread it through the network. +// +// If the records aren't valid, an error will be returned. +func (c *Client) ProvideRecords(ctx context.Context, records ...*types.AnnouncementRecord) (iter.ResultIter[*types.AnnouncementRecord], error) { + providerRecords := make([]types.Record, len(records)) + for i, record := range records { + if err := record.Verify(); err != nil { + return nil, err + } + providerRecords[i] = records[i] + } + url := c.baseURL + "/routing/v1/providers" + req := jsontypes.AnnounceProvidersRequest{ + Providers: providerRecords, + } return c.provide(ctx, url, req) } @@ -429,7 +452,9 @@ func (c *Client) FindPeers(ctx context.Context, pid peer.ID) (peers iter.ResultI return &measuringIter[iter.Result[*types.PeerRecord]]{Iter: it, ctx: ctx, m: m}, nil } -// ProvidePeer provides information regarding your own peer, setup with [WithProviderInfo]. +// ProvidePeer publishes an [types.AnnouncementRecord] to the server with information +// regarding your own peer. This [Client] must be configured with [WithIdentity] +// and [WithProviderInfo] in order to be able to provide. func (c *Client) ProvidePeer(ctx context.Context, ttl time.Duration, metadata []byte) (iter.ResultIter[*types.AnnouncementRecord], error) { if err := c.canProvide(); err != nil { return nil, err @@ -472,6 +497,27 @@ func (c *Client) ProvidePeer(ctx context.Context, ttl time.Duration, metadata [] return c.provide(ctx, url, req) } +// ProvidePeerRecords publishes [types.AnnouncementRecord] to the server with already +// signed records. This can be useful if you've gotten an announcement from somewhere +// else and you wish to spread it through the network. +// +// If the records aren't valid, an error will be returned. +func (c *Client) ProvidePeerRecords(ctx context.Context, records ...*types.AnnouncementRecord) (iter.ResultIter[*types.AnnouncementRecord], error) { + providerRecords := make([]types.Record, len(records)) + for i, record := range records { + if err := record.Verify(); err != nil { + return nil, err + } + providerRecords[i] = records[i] + } + + url := c.baseURL + "/routing/v1/peers" + req := jsontypes.AnnouncePeersRequest{ + Peers: providerRecords, + } + return c.provide(ctx, url, req) +} + // GetIPNS tries to retrieve the [ipns.Record] for the given [ipns.Name]. The record is // validated against the given name. If validation fails, an error is returned, but no // record.