Skip to content
This repository was archived by the owner on Jun 20, 2023. It is now read-only.

WIP: Changes to reflect the fact that Provide/FindProviders use multihashes. #15

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
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
8 changes: 4 additions & 4 deletions mock/centralized_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@ import (
"context"
"time"

cid "github.com/ipfs/go-cid"
logging "github.com/ipfs/go-log"
peer "github.com/libp2p/go-libp2p-peer"
pstore "github.com/libp2p/go-libp2p-peerstore"
routing "github.com/libp2p/go-libp2p-routing"
ropts "github.com/libp2p/go-libp2p-routing/options"
"github.com/libp2p/go-testutil"
ma "github.com/multiformats/go-multiaddr"
mh "github.com/multiformats/go-multihash"
)

var log = logging.Logger("mockrouter")
Expand All @@ -34,7 +34,7 @@ func (c *client) GetValue(ctx context.Context, key string, opts ...ropts.Option)
return c.vs.GetValue(ctx, key, opts...)
}

func (c *client) FindProviders(ctx context.Context, key cid.Cid) ([]pstore.PeerInfo, error) {
func (c *client) FindProviders(ctx context.Context, key mh.Multihash) ([]pstore.PeerInfo, error) {
return c.server.Providers(key), nil
}

Expand All @@ -43,7 +43,7 @@ func (c *client) FindPeer(ctx context.Context, pid peer.ID) (pstore.PeerInfo, er
return pstore.PeerInfo{}, nil
}

func (c *client) FindProvidersAsync(ctx context.Context, k cid.Cid, max int) <-chan pstore.PeerInfo {
func (c *client) FindProvidersAsync(ctx context.Context, k mh.Multihash, max int) <-chan pstore.PeerInfo {
out := make(chan pstore.PeerInfo)
go func() {
defer close(out)
Expand All @@ -63,7 +63,7 @@ func (c *client) FindProvidersAsync(ctx context.Context, k cid.Cid, max int) <-c

// Provide returns once the message is on the network. Value is not necessarily
// visible yet.
func (c *client) Provide(_ context.Context, key cid.Cid, brd bool) error {
func (c *client) Provide(_ context.Context, key mh.Multihash, brd bool) error {
if !brd {
return nil
}
Expand Down
14 changes: 7 additions & 7 deletions mock/centralized_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,20 @@ import (
"sync"
"time"

cid "github.com/ipfs/go-cid"
ds "github.com/ipfs/go-datastore"
dssync "github.com/ipfs/go-datastore/sync"
peer "github.com/libp2p/go-libp2p-peer"
pstore "github.com/libp2p/go-libp2p-peerstore"
"github.com/libp2p/go-testutil"
mh "github.com/multiformats/go-multihash"

offline "github.com/ipfs/go-ipfs-routing/offline"
)

// server is the mockrouting.Client's private interface to the routing server
type server interface {
Announce(pstore.PeerInfo, cid.Cid) error
Providers(cid.Cid) []pstore.PeerInfo
Announce(pstore.PeerInfo, mh.Multihash) error
Providers(mh.Multihash) []pstore.PeerInfo

Server
}
Expand All @@ -37,11 +37,11 @@ type providerRecord struct {
Created time.Time
}

func (rs *s) Announce(p pstore.PeerInfo, c cid.Cid) error {
func (rs *s) Announce(p pstore.PeerInfo, c mh.Multihash) error {
rs.lock.Lock()
defer rs.lock.Unlock()

k := c.KeyString()
k := string(c)

_, ok := rs.providers[k]
if !ok {
Expand All @@ -54,12 +54,12 @@ func (rs *s) Announce(p pstore.PeerInfo, c cid.Cid) error {
return nil
}

func (rs *s) Providers(c cid.Cid) []pstore.PeerInfo {
func (rs *s) Providers(c mh.Multihash) []pstore.PeerInfo {
rs.delayConf.Query.Wait() // before locking

rs.lock.RLock()
defer rs.lock.RUnlock()
k := c.KeyString()
k := string(c)

var ret []pstore.PeerInfo
records, ok := rs.providers[k]
Expand Down
6 changes: 3 additions & 3 deletions none/none_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@ import (
"context"
"errors"

cid "github.com/ipfs/go-cid"
ds "github.com/ipfs/go-datastore"
p2phost "github.com/libp2p/go-libp2p-host"
peer "github.com/libp2p/go-libp2p-peer"
pstore "github.com/libp2p/go-libp2p-peerstore"
record "github.com/libp2p/go-libp2p-record"
routing "github.com/libp2p/go-libp2p-routing"
ropts "github.com/libp2p/go-libp2p-routing/options"
mh "github.com/multiformats/go-multihash"
)

type nilclient struct {
Expand All @@ -30,13 +30,13 @@ func (c *nilclient) FindPeer(_ context.Context, _ peer.ID) (pstore.PeerInfo, err
return pstore.PeerInfo{}, nil
}

func (c *nilclient) FindProvidersAsync(_ context.Context, _ cid.Cid, _ int) <-chan pstore.PeerInfo {
func (c *nilclient) FindProvidersAsync(_ context.Context, _ mh.Multihash, _ int) <-chan pstore.PeerInfo {
out := make(chan pstore.PeerInfo)
defer close(out)
return out
}

func (c *nilclient) Provide(_ context.Context, _ cid.Cid, _ bool) error {
func (c *nilclient) Provide(_ context.Context, _ mh.Multihash, _ bool) error {
return nil
}

Expand Down
6 changes: 3 additions & 3 deletions offline/offline.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import (
"time"

proto "github.com/gogo/protobuf/proto"
cid "github.com/ipfs/go-cid"
ds "github.com/ipfs/go-datastore"
dshelp "github.com/ipfs/go-ipfs-ds-help"
"github.com/libp2p/go-libp2p-peer"
Expand All @@ -18,6 +17,7 @@ import (
pb "github.com/libp2p/go-libp2p-record/pb"
routing "github.com/libp2p/go-libp2p-routing"
ropts "github.com/libp2p/go-libp2p-routing/options"
mh "github.com/multiformats/go-multihash"
)

// ErrOffline is returned when trying to perform operations that
Expand Down Expand Up @@ -94,13 +94,13 @@ func (c *offlineRouting) FindPeer(ctx context.Context, pid peer.ID) (pstore.Peer
return pstore.PeerInfo{}, ErrOffline
}

func (c *offlineRouting) FindProvidersAsync(ctx context.Context, k cid.Cid, max int) <-chan pstore.PeerInfo {
func (c *offlineRouting) FindProvidersAsync(ctx context.Context, k mh.Multihash, max int) <-chan pstore.PeerInfo {
out := make(chan pstore.PeerInfo)
close(out)
return out
}

func (c *offlineRouting) Provide(_ context.Context, k cid.Cid, _ bool) error {
func (c *offlineRouting) Provide(_ context.Context, k mh.Multihash, _ bool) error {
return ErrOffline
}

Expand Down