Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
10
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Open sidebar
p2p
go-p2p-pubsub-router
Commits
1b619f8d
Unverified
Commit
1b619f8d
authored
May 26, 2019
by
Raúl Kripalani
Committed by
GitHub
May 26, 2019
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
migrate to consolidated types. (#31)
parent
ec1a03c2
Changes
4
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
88 additions
and
131 deletions
+88
-131
go.mod
go.mod
+7
-10
go.sum
go.sum
+60
-101
pubsub.go
pubsub.go
+15
-15
pubsub_test.go
pubsub_test.go
+6
-5
No files found.
go.mod
View file @
1b619f8d
...
@@ -2,17 +2,14 @@ module github.com/libp2p/go-libp2p-pubsub-router
...
@@ -2,17 +2,14 @@ module github.com/libp2p/go-libp2p-pubsub-router
require (
require (
github.com/ipfs/go-cid
v0.0.2
github.com/ipfs/go-cid
v0.0.2
github.com/ipfs/go-datastore
v0.0.
1
github.com/ipfs/go-datastore
v0.0.
5
github.com/ipfs/go-ipfs-ds-help
v0.0.1
github.com/ipfs/go-ipfs-ds-help
v0.0.1
github.com/ipfs/go-ipfs-util
v0.0.1
github.com/ipfs/go-ipfs-util
v0.0.1
github.com/ipfs/go-log
v0.0.1
github.com/ipfs/go-log
v0.0.1
github.com/libp2p/go-libp2p-blankhost
v0.0.1
github.com/libp2p/go-libp2p-blankhost
v0.1.1
github.com/libp2p/go-libp2p-host
v0.0.3
github.com/libp2p/go-libp2p-core
v0.0.1
github.com/libp2p/go-libp2p-peer
v0.1.1
github.com/libp2p/go-libp2p-pubsub
v0.1.0
github.com/libp2p/go-libp2p-peerstore
v0.0.6
github.com/libp2p/go-libp2p-record
v0.1.0
github.com/libp2p/go-libp2p-pubsub
v0.0.5
github.com/libp2p/go-libp2p-routing-helpers
v0.1.0
github.com/libp2p/go-libp2p-record
v0.0.1
github.com/libp2p/go-libp2p-swarm
v0.1.0
github.com/libp2p/go-libp2p-routing
v0.0.1
github.com/libp2p/go-libp2p-routing-helpers
v0.0.2
github.com/libp2p/go-libp2p-swarm
v0.0.6
)
)
go.sum
View file @
1b619f8d
This diff is collapsed.
Click to expand it.
pubsub.go
View file @
1b619f8d
...
@@ -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
p2p
host
.
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
p2p
host
.
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
...
ro
pts
.
Option
)
error
{
func
(
p
*
PubsubValueStore
)
PutValue
(
ctx
context
.
Context
,
key
string
,
value
[]
byte
,
opts
...
ro
uting
.
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
...
ro
pts
.
Option
)
([]
byte
,
error
)
{
func
(
p
*
PubsubValueStore
)
GetValue
(
ctx
context
.
Context
,
key
string
,
opts
...
ro
uting
.
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
...
ro
pts
.
Option
)
(
<-
chan
[]
byte
,
error
)
{
func
(
p
*
PubsubValueStore
)
SearchValue
(
ctx
context
.
Context
,
key
string
,
opts
...
ro
uting
.
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
p2p
host
.
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
p
store
.
Pee
rInfo
)
{
go
func
(
pi
p
eer
.
Add
rInfo
)
{
defer
wg
.
Done
()
defer
wg
.
Done
()
ctx
,
cancel
:=
context
.
WithTimeout
(
ctx
,
time
.
Second
*
10
)
ctx
,
cancel
:=
context
.
WithTimeout
(
ctx
,
time
.
Second
*
10
)
...
...
pubsub_test.go
View file @
1b619f8d
...
@@ -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
)
p2p
host
.
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
)
[]
p2p
host
.
Host
{
func
newNetHosts
(
ctx
context
.
Context
,
t
*
testing
.
T
,
n
int
)
[]
host
.
Host
{
var
out
[]
p2p
host
.
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
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment