Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BREAKING CHANGE: remove kubo deps #90

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
fix: use more strict type
Signed-off-by: gfanton <8671905+gfanton@users.noreply.github.com>
gfanton committed Jun 28, 2023
commit 05134ca9fc5d30540982ea44a0dcf9f8103b9e18
2 changes: 1 addition & 1 deletion entry/entry.go
Original file line number Diff line number Diff line change
@@ -501,7 +501,7 @@ func (e *Entry) Equals(b iface.IPFSLogEntry) bool {

func (e *Entry) IsParent(b iface.IPFSLogEntry) bool {
for _, next := range b.GetNext() {
if next.String() == e.Hash.String() {
if next == e.Hash {
return true
}
}
6 changes: 3 additions & 3 deletions entry/entry_io.go
Original file line number Diff line number Diff line change
@@ -4,7 +4,7 @@ import (
"context"

"github.com/ipfs/go-cid"
format "github.com/ipfs/go-ipld-format"
ipld "github.com/ipfs/go-ipld-format"

"berty.tech/go-ipfs-log/iface"
)
@@ -13,13 +13,13 @@ type FetchOptions = iface.FetchOptions

// FetchParallel has the same comportement than FetchAll, we keep it for retrop
// compatibility purpose
func FetchParallel(ctx context.Context, dag format.DAGService, hashes []cid.Cid, options *FetchOptions) []iface.IPFSLogEntry {
func FetchParallel(ctx context.Context, dag ipld.DAGService, hashes []cid.Cid, options *FetchOptions) []iface.IPFSLogEntry {
fetcher := NewFetcher(dag, options)
return fetcher.Fetch(ctx, hashes)
}

// FetchAll gets entries from their CIDs.
func FetchAll(ctx context.Context, dag format.DAGService, hashes []cid.Cid, options *FetchOptions) []iface.IPFSLogEntry {
func FetchAll(ctx context.Context, dag ipld.DAGService, hashes []cid.Cid, options *FetchOptions) []iface.IPFSLogEntry {
fetcher := NewFetcher(dag, options)
return fetcher.Fetch(ctx, hashes)
}
21 changes: 11 additions & 10 deletions entry/entry_map.go
Original file line number Diff line number Diff line change
@@ -4,25 +4,26 @@ import (
"sync"

"berty.tech/go-ipfs-log/iface"
"github.com/ipfs/go-cid"
)

// OrderedMap is an ordered map of entries.
type OrderedMap struct {
lock sync.RWMutex
keys []string
values map[string]iface.IPFSLogEntry
keys []cid.Cid
values map[cid.Cid]iface.IPFSLogEntry
}

func (o *OrderedMap) Copy() iface.IPFSLogOrderedEntries {
o.lock.RLock()
defer o.lock.RUnlock()

values := map[string]iface.IPFSLogEntry{}
values := map[cid.Cid]iface.IPFSLogEntry{}
for k, v := range o.values {
values[k] = v
}

keys := make([]string, len(o.keys))
keys := make([]cid.Cid, len(o.keys))
copy(keys, o.keys)

return &OrderedMap{
@@ -47,7 +48,7 @@ func (o *OrderedMap) Reverse() iface.IPFSLogOrderedEntries {
func NewOrderedMap() iface.IPFSLogOrderedEntries {
return &OrderedMap{
lock: sync.RWMutex{},
values: map[string]iface.IPFSLogEntry{},
values: map[cid.Cid]iface.IPFSLogEntry{},
}
}

@@ -60,7 +61,7 @@ func NewOrderedMapFromEntries(entries []iface.IPFSLogEntry) iface.IPFSLogOrdered
continue
}

orderedMap.Set(e.GetHash().String(), e)
orderedMap.Set(e.GetHash(), e)
}

return orderedMap
@@ -84,7 +85,7 @@ func (o *OrderedMap) Merge(other iface.IPFSLogOrderedEntries) iface.IPFSLogOrder
}

// Get retrieves an Entry using its key.
func (o *OrderedMap) Get(key string) (iface.IPFSLogEntry, bool) {
func (o *OrderedMap) Get(key cid.Cid) (iface.IPFSLogEntry, bool) {
o.lock.RLock()
defer o.lock.RUnlock()

@@ -93,7 +94,7 @@ func (o *OrderedMap) Get(key string) (iface.IPFSLogEntry, bool) {
}

// UnsafeGet retrieves an Entry using its key, returns nil if not found.
func (o *OrderedMap) UnsafeGet(key string) iface.IPFSLogEntry {
func (o *OrderedMap) UnsafeGet(key cid.Cid) iface.IPFSLogEntry {
o.lock.RLock()
defer o.lock.RUnlock()

@@ -103,7 +104,7 @@ func (o *OrderedMap) UnsafeGet(key string) iface.IPFSLogEntry {
}

// Set defines an Entry in the map for a given key.
func (o *OrderedMap) Set(key string, value iface.IPFSLogEntry) {
func (o *OrderedMap) Set(key cid.Cid, value iface.IPFSLogEntry) {
o.lock.Lock()
defer o.lock.Unlock()

@@ -130,7 +131,7 @@ func (o *OrderedMap) Slice() []iface.IPFSLogEntry {
}

// Keys retrieves the ordered list of keys in the map.
func (o *OrderedMap) Keys() []string {
func (o *OrderedMap) Keys() []cid.Cid {
o.lock.RLock()
defer o.lock.RUnlock()

40 changes: 20 additions & 20 deletions entry/sorting/sorting.go
Original file line number Diff line number Diff line change
@@ -105,24 +105,24 @@ func Compare(a, b iface.IPFSLogEntry) (int, error) {
return a.GetClock().Compare(b.GetClock()), nil
}

func Sort(compFunc func(a, b iface.IPFSLogEntry) (int, error), values []iface.IPFSLogEntry, reverse bool) {
if reverse {
sort.SliceStable(values, func(i, j int) bool {
ret, err := compFunc(values[i], values[j])
if err != nil {
fmt.Printf("error while comparing: %v\n", err)
return false
}
return ret > 0
})
} else {
sort.SliceStable(values, func(i, j int) bool {
ret, err := compFunc(values[i], values[j])
if err != nil {
fmt.Printf("error while comparing: %v\n", err)
return false
}
return ret < 0
})
}
func Sort(compFunc iface.EntrySortFn, values []iface.IPFSLogEntry) {
sort.SliceStable(values, func(i, j int) bool {
ret, err := compFunc(values[i], values[j])
if err != nil {
fmt.Printf("error while comparing: %v\n", err)
return false
}
return ret < 0
})
}

func SortReverse(compFunc iface.EntrySortFn, values []iface.IPFSLogEntry) {
sort.SliceStable(values, func(i, j int) bool {
ret, err := compFunc(values[i], values[j])
if err != nil {
fmt.Printf("error while comparing: %v\n", err)
return false
}
return ret > 0
})
}
7 changes: 4 additions & 3 deletions entry/utils.go
Original file line number Diff line number Diff line change
@@ -5,6 +5,7 @@ import (
"sort"

"berty.tech/go-ipfs-log/iface"
"github.com/ipfs/go-cid"
)

// Difference gets the list of values not present in both entries sets.
@@ -96,18 +97,18 @@ func FindHeads(entries iface.IPFSLogOrderedEntries) []iface.IPFSLogEntry {
}

var result []iface.IPFSLogEntry
items := map[string]string{}
items := map[cid.Cid]cid.Cid{}

for _, k := range entries.Keys() {
e := entries.UnsafeGet(k)
for _, n := range e.GetNext() {
items[n.String()] = e.GetHash().String()
items[n] = e.GetHash()
}
}

for _, h := range entries.Keys() {
e, ok := items[h]
if ok || e != "" {
if ok || e != cid.Undef {
continue
}

8 changes: 4 additions & 4 deletions iface/iface.go
Original file line number Diff line number Diff line change
@@ -118,19 +118,19 @@ type IPFSLogOrderedEntries interface {
Copy() IPFSLogOrderedEntries

// Get retrieves an Entry using its key.
Get(key string) (IPFSLogEntry, bool)
Get(key cid.Cid) (IPFSLogEntry, bool)

// UnsafeGet retrieves an Entry using its key, returns nil if not found.
UnsafeGet(key string) IPFSLogEntry
UnsafeGet(key cid.Cid) IPFSLogEntry

// Set defines an Entry in the map for a given key.
Set(key string, value IPFSLogEntry)
Set(key cid.Cid, value IPFSLogEntry)

// Slice returns an ordered slice of the values existing in the map.
Slice() []IPFSLogEntry

// Keys retrieves the ordered list of keys in the map.
Keys() []string
Keys() []cid.Cid

// Len gets the length of the map.
Len() int
Loading