Unverified Commit 1b619f8d authored by Raúl Kripalani's avatar Raúl Kripalani Committed by GitHub

migrate to consolidated types. (#31)

parent ec1a03c2
This diff is collapsed.
...@@ -8,19 +8,19 @@ import ( ...@@ -8,19 +8,19 @@ import (
"sync" "sync"
"time" "time"
cid "github.com/ipfs/go-cid" "github.com/libp2p/go-libp2p-core/host"
"github.com/libp2p/go-libp2p-core/peer"
"github.com/libp2p/go-libp2p-core/routing"
pubsub "github.com/libp2p/go-libp2p-pubsub"
record "github.com/libp2p/go-libp2p-record"
"github.com/ipfs/go-cid"
ds "github.com/ipfs/go-datastore" ds "github.com/ipfs/go-datastore"
dssync "github.com/ipfs/go-datastore/sync" dssync "github.com/ipfs/go-datastore/sync"
dshelp "github.com/ipfs/go-ipfs-ds-help" dshelp "github.com/ipfs/go-ipfs-ds-help"
u "github.com/ipfs/go-ipfs-util" u "github.com/ipfs/go-ipfs-util"
logging "github.com/ipfs/go-log" logging "github.com/ipfs/go-log"
p2phost "github.com/libp2p/go-libp2p-host"
peer "github.com/libp2p/go-libp2p-peer"
pstore "github.com/libp2p/go-libp2p-peerstore"
pubsub "github.com/libp2p/go-libp2p-pubsub"
record "github.com/libp2p/go-libp2p-record"
routing "github.com/libp2p/go-libp2p-routing"
ropts "github.com/libp2p/go-libp2p-routing/options"
) )
var log = logging.Logger("pubsub-valuestore") var log = logging.Logger("pubsub-valuestore")
...@@ -33,7 +33,7 @@ type watchGroup struct { ...@@ -33,7 +33,7 @@ type watchGroup struct {
type PubsubValueStore struct { type PubsubValueStore struct {
ctx context.Context ctx context.Context
ds ds.Datastore ds ds.Datastore
host p2phost.Host host host.Host
cr routing.ContentRouting cr routing.ContentRouting
ps *pubsub.PubSub ps *pubsub.PubSub
...@@ -60,7 +60,7 @@ func KeyToTopic(key string) string { ...@@ -60,7 +60,7 @@ func KeyToTopic(key string) string {
// NewPubsubPublisher constructs a new Publisher that publishes IPNS records through pubsub. // NewPubsubPublisher constructs a new Publisher that publishes IPNS records through pubsub.
// The constructor interface is complicated by the need to bootstrap the pubsub topic. // The constructor interface is complicated by the need to bootstrap the pubsub topic.
// This could be greatly simplified if the pubsub implementation handled bootstrap itself // This could be greatly simplified if the pubsub implementation handled bootstrap itself
func NewPubsubValueStore(ctx context.Context, host p2phost.Host, cr routing.ContentRouting, ps *pubsub.PubSub, validator record.Validator) *PubsubValueStore { func NewPubsubValueStore(ctx context.Context, host host.Host, cr routing.ContentRouting, ps *pubsub.PubSub, validator record.Validator) *PubsubValueStore {
return &PubsubValueStore{ return &PubsubValueStore{
ctx: ctx, ctx: ctx,
...@@ -77,7 +77,7 @@ func NewPubsubValueStore(ctx context.Context, host p2phost.Host, cr routing.Cont ...@@ -77,7 +77,7 @@ func NewPubsubValueStore(ctx context.Context, host p2phost.Host, cr routing.Cont
} }
// Publish publishes an IPNS record through pubsub with default TTL // Publish publishes an IPNS record through pubsub with default TTL
func (p *PubsubValueStore) PutValue(ctx context.Context, key string, value []byte, opts ...ropts.Option) error { func (p *PubsubValueStore) PutValue(ctx context.Context, key string, value []byte, opts ...routing.Option) error {
// Record-store keys are arbitrary binary. However, pubsub requires UTF-8 string topic IDs. // Record-store keys are arbitrary binary. However, pubsub requires UTF-8 string topic IDs.
// Encode to "/record/base64url(key)" // Encode to "/record/base64url(key)"
topic := KeyToTopic(key) topic := KeyToTopic(key)
...@@ -175,7 +175,7 @@ func (p *PubsubValueStore) getLocal(key string) ([]byte, error) { ...@@ -175,7 +175,7 @@ func (p *PubsubValueStore) getLocal(key string) ([]byte, error) {
return val, nil return val, nil
} }
func (p *PubsubValueStore) GetValue(ctx context.Context, key string, opts ...ropts.Option) ([]byte, error) { func (p *PubsubValueStore) GetValue(ctx context.Context, key string, opts ...routing.Option) ([]byte, error) {
if err := p.Subscribe(key); err != nil { if err := p.Subscribe(key); err != nil {
return nil, err return nil, err
} }
...@@ -183,7 +183,7 @@ func (p *PubsubValueStore) GetValue(ctx context.Context, key string, opts ...rop ...@@ -183,7 +183,7 @@ func (p *PubsubValueStore) GetValue(ctx context.Context, key string, opts ...rop
return p.getLocal(key) return p.getLocal(key)
} }
func (p *PubsubValueStore) SearchValue(ctx context.Context, key string, opts ...ropts.Option) (<-chan []byte, error) { func (p *PubsubValueStore) SearchValue(ctx context.Context, key string, opts ...routing.Option) (<-chan []byte, error) {
if err := p.Subscribe(key); err != nil { if err := p.Subscribe(key); err != nil {
return nil, err return nil, err
} }
...@@ -328,7 +328,7 @@ func (p *PubsubValueStore) notifyWatchers(key string, data []byte) { ...@@ -328,7 +328,7 @@ func (p *PubsubValueStore) notifyWatchers(key string, data []byte) {
// rendezvous with peers in the name topic through provider records // rendezvous with peers in the name topic through provider records
// Note: rendezvous/boostrap should really be handled by the pubsub implementation itself! // Note: rendezvous/boostrap should really be handled by the pubsub implementation itself!
func bootstrapPubsub(ctx context.Context, cr routing.ContentRouting, host p2phost.Host, name string) { func bootstrapPubsub(ctx context.Context, cr routing.ContentRouting, host host.Host, name string) {
// TODO: consider changing this to `pubsub:...` // TODO: consider changing this to `pubsub:...`
topic := "floodsub:" + name topic := "floodsub:" + name
hash := u.Hash([]byte(topic)) hash := u.Hash([]byte(topic))
...@@ -362,7 +362,7 @@ func bootstrapPubsub(ctx context.Context, cr routing.ContentRouting, host p2phos ...@@ -362,7 +362,7 @@ func bootstrapPubsub(ctx context.Context, cr routing.ContentRouting, host p2phos
continue continue
} }
wg.Add(1) wg.Add(1)
go func(pi pstore.PeerInfo) { go func(pi peer.AddrInfo) {
defer wg.Done() defer wg.Done()
ctx, cancel := context.WithTimeout(ctx, time.Second*10) ctx, cancel := context.WithTimeout(ctx, time.Second*10)
......
...@@ -6,22 +6,23 @@ import ( ...@@ -6,22 +6,23 @@ import (
"testing" "testing"
"time" "time"
"github.com/libp2p/go-libp2p-core/host"
"github.com/libp2p/go-libp2p-core/routing"
bhost "github.com/libp2p/go-libp2p-blankhost" bhost "github.com/libp2p/go-libp2p-blankhost"
p2phost "github.com/libp2p/go-libp2p-host"
pubsub "github.com/libp2p/go-libp2p-pubsub" pubsub "github.com/libp2p/go-libp2p-pubsub"
record "github.com/libp2p/go-libp2p-record" record "github.com/libp2p/go-libp2p-record"
routing "github.com/libp2p/go-libp2p-routing"
rhelper "github.com/libp2p/go-libp2p-routing-helpers" rhelper "github.com/libp2p/go-libp2p-routing-helpers"
swarmt "github.com/libp2p/go-libp2p-swarm/testing" swarmt "github.com/libp2p/go-libp2p-swarm/testing"
) )
func newNetHost(ctx context.Context, t *testing.T) p2phost.Host { func newNetHost(ctx context.Context, t *testing.T) host.Host {
netw := swarmt.GenSwarm(t, ctx) netw := swarmt.GenSwarm(t, ctx)
return bhost.NewBlankHost(netw) return bhost.NewBlankHost(netw)
} }
func newNetHosts(ctx context.Context, t *testing.T, n int) []p2phost.Host { func newNetHosts(ctx context.Context, t *testing.T, n int) []host.Host {
var out []p2phost.Host var out []host.Host
for i := 0; i < n; i++ { for i := 0; i < n; i++ {
h := newNetHost(ctx, t) h := newNetHost(ctx, t)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment