Skip to content

Commit

Permalink
Remove dockey.peerId and unused functions
Browse files Browse the repository at this point in the history
  • Loading branch information
AndrewSisley committed Mar 7, 2022
1 parent cddea90 commit 798143b
Showing 1 changed file with 0 additions and 47 deletions.
47 changes: 0 additions & 47 deletions document/key/dockey.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ package key
import (
// "github.com/google/uuid"
"bytes"
"context"
"encoding/binary"
"errors"
"strings"
Expand Down Expand Up @@ -51,7 +50,6 @@ type DocKey struct {
version uint16
uuid uuid.UUID
cid cid.Cid
peerID string
Key core.DataStoreKey
}

Expand Down Expand Up @@ -122,48 +120,3 @@ func (key DocKey) Bytes() []byte {
binary.PutUvarint(buf, uint64(key.version))
return append(buf, key.uuid.Bytes()...)
}

// Verify ensures that the given DocKey is valid as per the DefraDB spec
// to prevent against collions from both honest and dishonest validators
// TODO: Check into better utilizing or dropping context, since we don't recurse
// down
func (key DocKey) Verify(ctx context.Context, data cid.Cid, peerID string) bool {
parent, ok := ctx.Value("parent").(uuid.UUID)
// if we have a parent then assume were operating on a sub key
// otherwise were the root DocKey
var comparedUUID uuid.UUID
if ok {
comparedUUID = uuid.NewV5(parent, data.String())
} else {
comparedUUID = uuid.NewV5(NamespaceSDNDocKeyV0, data.String())
}

return comparedUUID.String() == key.uuid.String()
}

// Sub returns a sub DocKey, which is a UUIDv5 generated
// using the parent UUID as the namespace, and the provided
// name
func (key DocKey) Sub(subname string) DocKey {
subParts := strings.Split(subname, "/")
return key.subrec(subParts)
}

// recursive Sub call
// prerequisite, subparts needs to be at least 1 element long
func (key DocKey) subrec(subparts []string) DocKey {
if len(subparts) > 1 {
subkey := DocKey{
uuid: uuid.NewV5(key.uuid, subparts[0]),
cid: key.cid,
peerID: key.peerID,
}
return subkey.subrec(subparts[1:])
}
// else
return DocKey{
uuid: uuid.NewV5(key.uuid, subparts[0]),
cid: key.cid,
peerID: key.peerID,
}
}

0 comments on commit 798143b

Please sign in to comment.