add options to utility interface
@@ -11,10 +11,10 @@ import (
var log = logging.Logger("discovery")
// FindPeers is a utility function that synchonously collects peers from a Discoverer
-func FindPeers(ctx context.Context, d Discoverer, ns string, limit int) ([]pstore.PeerInfo, error) {
- res := make([]pstore.PeerInfo, 0, limit)
+func FindPeers(ctx context.Context, d Discoverer, ns string, opts ...Option) ([]pstore.PeerInfo, error) {
+ var res []pstore.PeerInfo
- ch, err := d.FindPeers(ctx, ns, Limit(limit))
+ ch, err := d.FindPeers(ctx, ns, opts...)
if err != nil {
return nil, err
}
@@ -27,10 +27,10 @@ func FindPeers(ctx context.Context, d Discoverer, ns string, limit int) ([]pstor
}
// Advertise is a utility function that persistently advertises a service through an Advertiser
-func Advertise(ctx context.Context, a Advertiser, ns string) {
+func Advertise(ctx context.Context, a Advertiser, ns string, opts ...Option) {
go func() {
for {
- ttl, err := a.Advertise(ctx, ns)
+ ttl, err := a.Advertise(ctx, ns, opts...)
if err != nil {
log.Debugf("Error advertising %s: %s", ns, err.Error())
if ctx.Err() != nil {
