Skip to content

Commit

Permalink
feat(routing): allow-offline with routing put
Browse files Browse the repository at this point in the history
  • Loading branch information
laurentsenta committed Apr 12, 2023
1 parent a12deee commit d5dc6ee
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 1 deletion.
35 changes: 35 additions & 0 deletions coreiface/options/routing.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package options

type RoutingPutSettings struct {
AllowOffline bool
}

type RoutingPutOption func(*RoutingPutSettings) error

func RoutingPutOptions(opts ...RoutingPutOption) (*RoutingPutSettings, error) {
options := &RoutingPutSettings{
AllowOffline: false,
}

for _, opt := range opts {
err := opt(options)
if err != nil {
return nil, err
}
}

return options, nil
}

type putOpts struct{}

var Put putOpts

// AllowOffline is an option for Routing.Put which specifies whether to allow
// publishing when the node is offline. Default value is false
func (putOpts) AllowOffline(allow bool) RoutingPutOption {
return func(settings *RoutingPutSettings) error {
settings.AllowOffline = allow
return nil
}
}
4 changes: 3 additions & 1 deletion coreiface/routing.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ package iface

import (
"context"

"github.com/ipfs/boxo/coreiface/options"
)

// RoutingAPI specifies the interface to the routing layer.
Expand All @@ -10,5 +12,5 @@ type RoutingAPI interface {
Get(context.Context, string) ([]byte, error)

// Put sets a value for a given key
Put(ctx context.Context, key string, value []byte) error
Put(ctx context.Context, key string, value []byte, opts ...options.RoutingPutOption) error
}

0 comments on commit d5dc6ee

Please sign in to comment.