Skip to content

Commit

Permalink
net: unprotect net.AddRecord (#405)
Browse files Browse the repository at this point in the history
Signed-off-by: Sander Pick <sanderpick@gmail.com>
  • Loading branch information
sanderpick authored Jul 16, 2020
1 parent 00faa63 commit 1e5555d
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 5 deletions.
2 changes: 1 addition & 1 deletion core/net/net.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ type API interface {

// Token is used to restrict network APIs to a single app.App.
// In other words, a net token protects against writes and deletes
// external to an app.
// which are external to an app.
type Token []byte

func (t Token) Equal(b Token) bool {
Expand Down
2 changes: 1 addition & 1 deletion core/net/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ func WithThreadToken(t thread.Token) ThreadOption {
// WithAPIToken provides additional authorization for interacting
// with a thread as an application.
// For example, this is used by a db.DB to ensure that only it can
// create/add records or delete the underlying thread.
// create records or delete the underlying thread.
func WithAPIToken(t Token) ThreadOption {
return func(args *ThreadOptions) {
args.APIToken = t
Expand Down
6 changes: 3 additions & 3 deletions net/net.go
Original file line number Diff line number Diff line change
Expand Up @@ -721,9 +721,6 @@ func (n *net) AddRecord(ctx context.Context, id thread.ID, lid peer.ID, rec core
if _, err := args.Token.Validate(n.getPrivKey()); err != nil {
return err
}
if !n.validateAPIToken(id, args.APIToken) {
return fmt.Errorf("cannot add record: %w", app.ErrThreadInUse)
}

logpk, err := n.store.PubKey(id, lid)
if err != nil {
Expand Down Expand Up @@ -872,6 +869,9 @@ func (n *net) ConnectApp(a app.App, id thread.ID) (*app.Connector, error) {
return con, nil
}

// validateAPIToken checks if the thread is backing an app,
// and if so, returns whether or not the token matches the app
// connector's token.
func (n *net) validateAPIToken(id thread.ID, token core.Token) bool {
t, ok := n.apps[id]
if !ok {
Expand Down

0 comments on commit 1e5555d

Please sign in to comment.