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
dms3
go-dms3-routing
Commits
cc777593
Commit
cc777593
authored
May 03, 2018
by
Steven Allen
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
update for routing interface changes
Specifically, remove GetValues
parent
462015cf
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
18 additions
and
49 deletions
+18
-49
mock/centralized_client.go
mock/centralized_client.go
+3
-12
none/none_client.go
none/none_client.go
+5
-7
offline/offline.go
offline/offline.go
+3
-23
offline/offline_test.go
offline/offline_test.go
+3
-3
package.json
package.json
+4
-4
No files found.
mock/centralized_client.go
View file @
cc777593
...
@@ -15,6 +15,7 @@ import (
...
@@ -15,6 +15,7 @@ import (
pstore
"github.com/libp2p/go-libp2p-peerstore"
pstore
"github.com/libp2p/go-libp2p-peerstore"
dhtpb
"github.com/libp2p/go-libp2p-record/pb"
dhtpb
"github.com/libp2p/go-libp2p-record/pb"
routing
"github.com/libp2p/go-libp2p-routing"
routing
"github.com/libp2p/go-libp2p-routing"
ropts
"github.com/libp2p/go-libp2p-routing/options"
"github.com/libp2p/go-testutil"
"github.com/libp2p/go-testutil"
ma
"github.com/multiformats/go-multiaddr"
ma
"github.com/multiformats/go-multiaddr"
)
)
...
@@ -28,7 +29,7 @@ type client struct {
...
@@ -28,7 +29,7 @@ type client struct {
}
}
// FIXME(brian): is this method meant to simulate putting a value into the network?
// FIXME(brian): is this method meant to simulate putting a value into the network?
func
(
c
*
client
)
PutValue
(
ctx
context
.
Context
,
key
string
,
val
[]
byte
)
error
{
func
(
c
*
client
)
PutValue
(
ctx
context
.
Context
,
key
string
,
val
[]
byte
,
opts
...
ropts
.
Option
)
error
{
log
.
Debugf
(
"PutValue: %s"
,
key
)
log
.
Debugf
(
"PutValue: %s"
,
key
)
rec
:=
new
(
dhtpb
.
Record
)
rec
:=
new
(
dhtpb
.
Record
)
rec
.
Value
=
val
rec
.
Value
=
val
...
@@ -43,7 +44,7 @@ func (c *client) PutValue(ctx context.Context, key string, val []byte) error {
...
@@ -43,7 +44,7 @@ func (c *client) PutValue(ctx context.Context, key string, val []byte) error {
}
}
// FIXME(brian): is this method meant to simulate getting a value from the network?
// FIXME(brian): is this method meant to simulate getting a value from the network?
func
(
c
*
client
)
GetValue
(
ctx
context
.
Context
,
key
string
)
([]
byte
,
error
)
{
func
(
c
*
client
)
GetValue
(
ctx
context
.
Context
,
key
string
,
opts
...
ropts
.
Option
)
([]
byte
,
error
)
{
log
.
Debugf
(
"GetValue: %s"
,
key
)
log
.
Debugf
(
"GetValue: %s"
,
key
)
v
,
err
:=
c
.
datastore
.
Get
(
dshelp
.
NewKeyFromBinary
([]
byte
(
key
)))
v
,
err
:=
c
.
datastore
.
Get
(
dshelp
.
NewKeyFromBinary
([]
byte
(
key
)))
if
err
!=
nil
{
if
err
!=
nil
{
...
@@ -64,16 +65,6 @@ func (c *client) GetValue(ctx context.Context, key string) ([]byte, error) {
...
@@ -64,16 +65,6 @@ func (c *client) GetValue(ctx context.Context, key string) ([]byte, error) {
return
rec
.
GetValue
(),
nil
return
rec
.
GetValue
(),
nil
}
}
func
(
c
*
client
)
GetValues
(
ctx
context
.
Context
,
key
string
,
count
int
)
([]
routing
.
RecvdVal
,
error
)
{
log
.
Debugf
(
"GetValues: %s"
,
key
)
data
,
err
:=
c
.
GetValue
(
ctx
,
key
)
if
err
!=
nil
{
return
nil
,
err
}
return
[]
routing
.
RecvdVal
{{
Val
:
data
,
From
:
c
.
peer
.
ID
()}},
nil
}
func
(
c
*
client
)
FindProviders
(
ctx
context
.
Context
,
key
*
cid
.
Cid
)
([]
pstore
.
PeerInfo
,
error
)
{
func
(
c
*
client
)
FindProviders
(
ctx
context
.
Context
,
key
*
cid
.
Cid
)
([]
pstore
.
PeerInfo
,
error
)
{
return
c
.
server
.
Providers
(
key
),
nil
return
c
.
server
.
Providers
(
key
),
nil
}
}
...
...
none/none_client.go
View file @
cc777593
...
@@ -10,24 +10,22 @@ import (
...
@@ -10,24 +10,22 @@ import (
p2phost
"github.com/libp2p/go-libp2p-host"
p2phost
"github.com/libp2p/go-libp2p-host"
peer
"github.com/libp2p/go-libp2p-peer"
peer
"github.com/libp2p/go-libp2p-peer"
pstore
"github.com/libp2p/go-libp2p-peerstore"
pstore
"github.com/libp2p/go-libp2p-peerstore"
record
"github.com/libp2p/go-libp2p-record"
routing
"github.com/libp2p/go-libp2p-routing"
routing
"github.com/libp2p/go-libp2p-routing"
ropts
"github.com/libp2p/go-libp2p-routing/options"
)
)
type
nilclient
struct
{
type
nilclient
struct
{
}
}
func
(
c
*
nilclient
)
PutValue
(
_
context
.
Context
,
_
string
,
_
[]
byte
)
error
{
func
(
c
*
nilclient
)
PutValue
(
_
context
.
Context
,
_
string
,
_
[]
byte
,
_
...
ropts
.
Option
)
error
{
return
nil
return
nil
}
}
func
(
c
*
nilclient
)
GetValue
(
_
context
.
Context
,
_
string
)
([]
byte
,
error
)
{
func
(
c
*
nilclient
)
GetValue
(
_
context
.
Context
,
_
string
,
_
...
ropts
.
Option
)
([]
byte
,
error
)
{
return
nil
,
errors
.
New
(
"tried GetValue from nil routing"
)
return
nil
,
errors
.
New
(
"tried GetValue from nil routing"
)
}
}
func
(
c
*
nilclient
)
GetValues
(
_
context
.
Context
,
_
string
,
_
int
)
([]
routing
.
RecvdVal
,
error
)
{
return
nil
,
errors
.
New
(
"tried GetValues from nil routing"
)
}
func
(
c
*
nilclient
)
FindPeer
(
_
context
.
Context
,
_
peer
.
ID
)
(
pstore
.
PeerInfo
,
error
)
{
func
(
c
*
nilclient
)
FindPeer
(
_
context
.
Context
,
_
peer
.
ID
)
(
pstore
.
PeerInfo
,
error
)
{
return
pstore
.
PeerInfo
{},
nil
return
pstore
.
PeerInfo
{},
nil
}
}
...
@@ -47,7 +45,7 @@ func (c *nilclient) Bootstrap(_ context.Context) error {
...
@@ -47,7 +45,7 @@ func (c *nilclient) Bootstrap(_ context.Context) error {
}
}
// ConstructNilRouting creates an IpfsRouting client which does nothing.
// ConstructNilRouting creates an IpfsRouting client which does nothing.
func
ConstructNilRouting
(
_
context
.
Context
,
_
p2phost
.
Host
,
_
ds
.
Batching
)
(
routing
.
IpfsRouting
,
error
)
{
func
ConstructNilRouting
(
_
context
.
Context
,
_
p2phost
.
Host
,
_
ds
.
Batching
,
_
record
.
Validator
)
(
routing
.
IpfsRouting
,
error
)
{
return
&
nilclient
{},
nil
return
&
nilclient
{},
nil
}
}
...
...
offline/offline.go
View file @
cc777593
...
@@ -17,6 +17,7 @@ import (
...
@@ -17,6 +17,7 @@ import (
record
"github.com/libp2p/go-libp2p-record"
record
"github.com/libp2p/go-libp2p-record"
pb
"github.com/libp2p/go-libp2p-record/pb"
pb
"github.com/libp2p/go-libp2p-record/pb"
routing
"github.com/libp2p/go-libp2p-routing"
routing
"github.com/libp2p/go-libp2p-routing"
ropts
"github.com/libp2p/go-libp2p-routing/options"
)
)
// ErrOffline is returned when trying to perform operations that
// ErrOffline is returned when trying to perform operations that
...
@@ -41,7 +42,7 @@ type offlineRouting struct {
...
@@ -41,7 +42,7 @@ type offlineRouting struct {
sk
ci
.
PrivKey
sk
ci
.
PrivKey
}
}
func
(
c
*
offlineRouting
)
PutValue
(
ctx
context
.
Context
,
key
string
,
val
[]
byte
)
error
{
func
(
c
*
offlineRouting
)
PutValue
(
ctx
context
.
Context
,
key
string
,
val
[]
byte
,
_
...
ropts
.
Option
)
error
{
rec
:=
record
.
MakePutRecord
(
key
,
val
)
rec
:=
record
.
MakePutRecord
(
key
,
val
)
data
,
err
:=
proto
.
Marshal
(
rec
)
data
,
err
:=
proto
.
Marshal
(
rec
)
if
err
!=
nil
{
if
err
!=
nil
{
...
@@ -51,7 +52,7 @@ func (c *offlineRouting) PutValue(ctx context.Context, key string, val []byte) e
...
@@ -51,7 +52,7 @@ func (c *offlineRouting) PutValue(ctx context.Context, key string, val []byte) e
return
c
.
datastore
.
Put
(
dshelp
.
NewKeyFromBinary
([]
byte
(
key
)),
data
)
return
c
.
datastore
.
Put
(
dshelp
.
NewKeyFromBinary
([]
byte
(
key
)),
data
)
}
}
func
(
c
*
offlineRouting
)
GetValue
(
ctx
context
.
Context
,
key
string
)
([]
byte
,
error
)
{
func
(
c
*
offlineRouting
)
GetValue
(
ctx
context
.
Context
,
key
string
,
_
...
ropts
.
Option
)
([]
byte
,
error
)
{
v
,
err
:=
c
.
datastore
.
Get
(
dshelp
.
NewKeyFromBinary
([]
byte
(
key
)))
v
,
err
:=
c
.
datastore
.
Get
(
dshelp
.
NewKeyFromBinary
([]
byte
(
key
)))
if
err
!=
nil
{
if
err
!=
nil
{
return
nil
,
err
return
nil
,
err
...
@@ -70,27 +71,6 @@ func (c *offlineRouting) GetValue(ctx context.Context, key string) ([]byte, erro
...
@@ -70,27 +71,6 @@ func (c *offlineRouting) GetValue(ctx context.Context, key string) ([]byte, erro
return
rec
.
GetValue
(),
nil
return
rec
.
GetValue
(),
nil
}
}
func
(
c
*
offlineRouting
)
GetValues
(
ctx
context
.
Context
,
key
string
,
_
int
)
([]
routing
.
RecvdVal
,
error
)
{
v
,
err
:=
c
.
datastore
.
Get
(
dshelp
.
NewKeyFromBinary
([]
byte
(
key
)))
if
err
!=
nil
{
return
nil
,
err
}
byt
,
ok
:=
v
.
([]
byte
)
if
!
ok
{
return
nil
,
errors
.
New
(
"value stored in datastore not []byte"
)
}
rec
:=
new
(
pb
.
Record
)
err
=
proto
.
Unmarshal
(
byt
,
rec
)
if
err
!=
nil
{
return
nil
,
err
}
return
[]
routing
.
RecvdVal
{
{
Val
:
rec
.
GetValue
()},
},
nil
}
func
(
c
*
offlineRouting
)
FindPeer
(
ctx
context
.
Context
,
pid
peer
.
ID
)
(
pstore
.
PeerInfo
,
error
)
{
func
(
c
*
offlineRouting
)
FindPeer
(
ctx
context
.
Context
,
pid
peer
.
ID
)
(
pstore
.
PeerInfo
,
error
)
{
return
pstore
.
PeerInfo
{},
ErrOffline
return
pstore
.
PeerInfo
{},
ErrOffline
}
}
...
...
offline/offline_test.go
View file @
cc777593
...
@@ -7,6 +7,7 @@ import (
...
@@ -7,6 +7,7 @@ import (
cid
"github.com/ipfs/go-cid"
cid
"github.com/ipfs/go-cid"
ds
"github.com/ipfs/go-datastore"
ds
"github.com/ipfs/go-datastore"
ropt
"github.com/libp2p/go-libp2p-routing/options"
testutil
"github.com/libp2p/go-testutil"
testutil
"github.com/libp2p/go-testutil"
mh
"github.com/multiformats/go-multihash"
mh
"github.com/multiformats/go-multihash"
)
)
...
@@ -35,17 +36,16 @@ func TestOfflineRouterStorage(t *testing.T) {
...
@@ -35,17 +36,16 @@ func TestOfflineRouterStorage(t *testing.T) {
t
.
Fatal
(
"Router should throw errors for unfound records"
)
t
.
Fatal
(
"Router should throw errors for unfound records"
)
}
}
recV
al
,
err
:=
offline
.
GetValue
s
(
ctx
,
"key"
,
0
)
loc
al
,
err
:=
offline
.
GetValue
(
ctx
,
"key"
,
ropt
.
Offline
)
if
err
!=
nil
{
if
err
!=
nil
{
t
.
Fatal
(
err
)
t
.
Fatal
(
err
)
}
}
_
,
err
=
offline
.
GetValue
s
(
ctx
,
"notHere"
,
0
)
_
,
err
=
offline
.
GetValue
(
ctx
,
"notHere"
,
ropt
.
Offline
)
if
err
==
nil
{
if
err
==
nil
{
t
.
Fatal
(
"Router should throw errors for unfound records"
)
t
.
Fatal
(
"Router should throw errors for unfound records"
)
}
}
local
:=
recVal
[
0
]
.
Val
if
!
bytes
.
Equal
([]
byte
(
"testing 1 2 3"
),
local
)
{
if
!
bytes
.
Equal
([]
byte
(
"testing 1 2 3"
),
local
)
{
t
.
Fatal
(
"OfflineRouter does not properly store"
)
t
.
Fatal
(
"OfflineRouter does not properly store"
)
}
}
...
...
package.json
View file @
cc777593
...
@@ -14,9 +14,9 @@
...
@@ -14,9 +14,9 @@
"version"
:
"2.1.7"
"version"
:
"2.1.7"
},
},
{
{
"hash"
:
"Qm
Zix3EdeAdc4wnRksRXWEQ6kbqiFAP16h3Sq9JnEiP71N
"
,
"hash"
:
"Qm
UHRKTeaoASDvDj7cTAXsmjAY7KQ13ErtzkQHZQq6uFUz
"
,
"name"
:
"go-libp2p-routing"
,
"name"
:
"go-libp2p-routing"
,
"version"
:
"2.
2.22
"
"version"
:
"2.
3.0
"
},
},
{
{
"author"
:
"whyrusleeping"
,
"author"
:
"whyrusleeping"
,
...
@@ -55,9 +55,9 @@
...
@@ -55,9 +55,9 @@
"version"
:
"1.2.1"
"version"
:
"1.2.1"
},
},
{
{
"hash"
:
"Qm
Z9V14gpwKsTUG7y5mHZDnHSF4Fa4rKsXNx7jSTEQ4JWs
"
,
"hash"
:
"Qm
TUyK82BVPA6LmSzEJpfEunk9uBaQzWtMsNP917tVj4sT
"
,
"name"
:
"go-libp2p-record"
,
"name"
:
"go-libp2p-record"
,
"version"
:
"4.
0.1
"
"version"
:
"4.
1.0
"
},
},
{
{
"author"
:
"hsanjuan"
,
"author"
:
"hsanjuan"
,
...
...
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