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
e213e17c
Commit
e213e17c
authored
May 31, 2017
by
zramsay
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
apply the megacheck tool to improve code quality
License: MIT Signed-off-by:
Zach Ramsay
<
zach.ramsay@gmail.com
>
parent
379ef866
Changes
7
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
10 additions
and
38 deletions
+10
-38
mock/centralized_server.go
mock/centralized_server.go
+1
-1
mock/centralized_test.go
mock/centralized_test.go
+3
-3
none/none_client.go
none/none_client.go
+0
-3
offline/offline.go
offline/offline.go
+0
-3
offline/offline_test.go
offline/offline_test.go
+4
-2
supernode/proxy/standard.go
supernode/proxy/standard.go
+1
-4
supernode/server.go
supernode/server.go
+1
-22
No files found.
mock/centralized_server.go
View file @
e213e17c
...
...
@@ -66,7 +66,7 @@ func (rs *s) Providers(c *cid.Cid) []pstore.PeerInfo {
return
ret
}
for
_
,
r
:=
range
records
{
if
time
.
Now
()
.
Sub
(
r
.
Created
)
>
rs
.
delayConf
.
ValueVisibility
.
Get
()
{
if
time
.
Since
(
r
.
Created
)
>
rs
.
delayConf
.
ValueVisibility
.
Get
()
{
ret
=
append
(
ret
,
r
.
Peer
)
}
}
...
...
mock/centralized_test.go
View file @
e213e17c
...
...
@@ -45,7 +45,7 @@ func TestClientFindProviders(t *testing.T) {
providersFromClient
:=
client
.
FindProvidersAsync
(
context
.
Background
(),
k
,
max
)
isInClient
:=
false
for
pi
:=
range
providersFromClient
{
if
pi
.
ID
==
pi
.
ID
{
if
pi
.
ID
==
pi
.
ID
{
// <-- typo?
isInClient
=
true
}
}
...
...
@@ -72,7 +72,7 @@ func TestClientOverMax(t *testing.T) {
providersFromClient
:=
client
.
FindProvidersAsync
(
context
.
Background
(),
k
,
max
)
i
:=
0
for
_
=
range
providersFromClient
{
for
range
providersFromClient
{
i
++
}
if
i
!=
max
{
...
...
@@ -128,7 +128,7 @@ func TestCanceledContext(t *testing.T) {
providers
:=
client
.
FindProvidersAsync
(
ctx
,
k
,
max
)
numProvidersReturned
:=
0
for
_
=
range
providers
{
for
range
providers
{
numProvidersReturned
++
}
t
.
Log
(
numProvidersReturned
)
...
...
none/none_client.go
View file @
e213e17c
...
...
@@ -7,15 +7,12 @@ import (
repo
"github.com/ipfs/go-ipfs/repo"
routing
"gx/ipfs/QmNdaQ8itUU9jEZUwTsG4gHMaPmRfi6FEe89QjQAFbep3M/go-libp2p-routing"
logging
"gx/ipfs/QmSpJByNKFX1sCsHBEp3R73FL4NF6FnQTEGyNAXHm2GS52/go-log"
p2phost
"gx/ipfs/QmUywuGNZoUKV8B9iyvup9bPkLiMrhTsyVMkeSXW5VxAfC/go-libp2p-host"
pstore
"gx/ipfs/QmXZSd1qR5BxZkPyuwfT5jpqQFScZccoZvDneXsKzCNHWX/go-libp2p-peerstore"
cid
"gx/ipfs/QmYhQaCYEcaPPjxJX7YcPcVKkQfRy6sJ7B3XmGFk82XYdQ/go-cid"
peer
"gx/ipfs/QmdS9KpbDyPrieswibZhkod1oXqRwZJrUPzxCofAMWpFGq/go-libp2p-peer"
)
var
log
=
logging
.
Logger
(
"mockrouter"
)
type
nilclient
struct
{
}
...
...
offline/offline.go
View file @
e213e17c
...
...
@@ -10,7 +10,6 @@ import (
routing
"gx/ipfs/QmNdaQ8itUU9jEZUwTsG4gHMaPmRfi6FEe89QjQAFbep3M/go-libp2p-routing"
ci
"gx/ipfs/QmP1DfoUjiWH2ZBo1PBH6FupdBucbDepx3HpWmEY6JMUpY/go-libp2p-crypto"
ds
"gx/ipfs/QmRWDav6mzWseLWeYfVd5fvUKiVe9xNH29YfMF438fG364/go-datastore"
logging
"gx/ipfs/QmSpJByNKFX1sCsHBEp3R73FL4NF6FnQTEGyNAXHm2GS52/go-log"
record
"gx/ipfs/QmWYCqr6UDqqD1bfRybaAPtbAqcN3TSJpveaBXMwbQ3ePZ/go-libp2p-record"
pb
"gx/ipfs/QmWYCqr6UDqqD1bfRybaAPtbAqcN3TSJpveaBXMwbQ3ePZ/go-libp2p-record/pb"
pstore
"gx/ipfs/QmXZSd1qR5BxZkPyuwfT5jpqQFScZccoZvDneXsKzCNHWX/go-libp2p-peerstore"
...
...
@@ -19,8 +18,6 @@ import (
"gx/ipfs/QmdS9KpbDyPrieswibZhkod1oXqRwZJrUPzxCofAMWpFGq/go-libp2p-peer"
)
var
log
=
logging
.
Logger
(
"offlinerouting"
)
var
ErrOffline
=
errors
.
New
(
"routing system in offline mode"
)
func
NewOfflineRouter
(
dstore
ds
.
Datastore
,
privkey
ci
.
PrivKey
)
routing
.
IpfsRouting
{
...
...
offline/offline_test.go
View file @
e213e17c
...
...
@@ -15,12 +15,14 @@ func TestOfflineRouterStorage(t *testing.T) {
privkey
,
_
,
_
:=
testutil
.
RandTestKeyPair
(
128
)
offline
:=
NewOfflineRouter
(
nds
,
privkey
)
err
:=
offline
.
PutValue
(
ctx
,
"key"
,
[]
byte
(
"testing 1 2 3"
))
if
err
!=
nil
{
if
err
:=
offline
.
PutValue
(
ctx
,
"key"
,
[]
byte
(
"testing 1 2 3"
));
err
!=
nil
{
t
.
Fatal
(
err
)
}
val
,
err
:=
offline
.
GetValue
(
ctx
,
"key"
)
if
err
!=
nil
{
t
.
Fatal
(
err
)
}
if
!
bytes
.
Equal
([]
byte
(
"testing 1 2 3"
),
val
)
{
t
.
Fatal
(
"OfflineRouter does not properly store"
)
}
...
...
supernode/proxy/standard.go
View file @
e213e17c
...
...
@@ -104,10 +104,7 @@ func (px *standard) sendMessage(ctx context.Context, m *dhtpb.Message, remote pe
}
defer
s
.
Close
()
pbw
:=
ggio
.
NewDelimitedWriter
(
s
)
if
err
:=
pbw
.
WriteMsg
(
m
);
err
!=
nil
{
return
err
}
return
nil
return
pbw
.
WriteMsg
(
m
)
}
// SendRequest sends the request to each remote sequentially (randomized order),
...
...
supernode/server.go
View file @
e213e17c
...
...
@@ -10,7 +10,6 @@ import (
datastore
"gx/ipfs/QmRWDav6mzWseLWeYfVd5fvUKiVe9xNH29YfMF438fG364/go-datastore"
dhtpb
"gx/ipfs/QmRmroYSdievxnjiuy99C8BzShNstdEWcEF3LQHF7fUbez/go-libp2p-kad-dht/pb"
record
"gx/ipfs/QmWYCqr6UDqqD1bfRybaAPtbAqcN3TSJpveaBXMwbQ3ePZ/go-libp2p-record"
pb
"gx/ipfs/QmWYCqr6UDqqD1bfRybaAPtbAqcN3TSJpveaBXMwbQ3ePZ/go-libp2p-record/pb"
pstore
"gx/ipfs/QmXZSd1qR5BxZkPyuwfT5jpqQFScZccoZvDneXsKzCNHWX/go-libp2p-peerstore"
proto
"gx/ipfs/QmZ4Qi3GaRbjcx28Sme5eMH7RQjGkt8wHxt2a65oLaeFEV/gogo-protobuf/proto"
...
...
@@ -140,10 +139,7 @@ func putRoutingRecord(ds datastore.Datastore, k string, value *pb.Record) error
}
dskey
:=
dshelp
.
NewKeyFromBinary
([]
byte
(
k
))
// TODO namespace
if
err
:=
ds
.
Put
(
dskey
,
data
);
err
!=
nil
{
return
err
}
return
nil
return
ds
.
Put
(
dskey
,
data
)
}
func
putRoutingProviders
(
ds
datastore
.
Datastore
,
k
string
,
newRecords
[]
*
dhtpb
.
Message_Peer
)
error
{
...
...
@@ -204,20 +200,3 @@ func getRoutingProviders(ds datastore.Datastore, k string) ([]*dhtpb.Message_Pee
func
providerKey
(
k
string
)
datastore
.
Key
{
return
datastore
.
KeyWithNamespaces
([]
string
{
"routing"
,
"providers"
,
k
})
}
func
verify
(
ps
pstore
.
Peerstore
,
r
*
pb
.
Record
)
error
{
v
:=
make
(
record
.
Validator
)
v
[
"pk"
]
=
record
.
PublicKeyValidator
p
:=
peer
.
ID
(
r
.
GetAuthor
())
pk
:=
ps
.
PubKey
(
p
)
if
pk
==
nil
{
return
fmt
.
Errorf
(
"do not have public key for %s"
,
p
)
}
if
err
:=
record
.
CheckRecordSig
(
r
,
pk
);
err
!=
nil
{
return
err
}
if
err
:=
v
.
VerifyRecord
(
r
);
err
!=
nil
{
return
err
}
return
nil
}
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