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-bitswap
Commits
01625e32
Commit
01625e32
authored
Sep 19, 2014
by
Brian Tiger Chow
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
refac(bitswap:testnet) give testnet its own package
parent
c67d48d9
Changes
7
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
31 additions
and
28 deletions
+31
-28
bitswap.go
bitswap.go
+2
-11
bitswap_test.go
bitswap_test.go
+8
-7
network/interface.go
network/interface.go
+10
-0
testnet/network.go
testnet/network.go
+1
-1
testnet/network_test.go
testnet/network_test.go
+2
-2
testnet/routing.go
testnet/routing.go
+4
-3
testnet/routing_test.go
testnet/routing_test.go
+4
-4
No files found.
bitswap.go
View file @
01625e32
...
...
@@ -17,18 +17,9 @@ import (
u
"github.com/jbenet/go-ipfs/util"
)
// TODO rename -> Router?
type
Routing
interface
{
// FindProvidersAsync returns a channel of providers for the given key
FindProvidersAsync
(
context
.
Context
,
u
.
Key
,
int
)
<-
chan
*
peer
.
Peer
// Provide provides the key to the network
Provide
(
key
u
.
Key
)
error
}
// NetMessageSession initializes a BitSwap session that communicates over the
// provided NetMessage service
func
NetMessageSession
(
parent
context
.
Context
,
s
bsnet
.
NetMessageService
,
p
*
peer
.
Peer
,
d
ds
.
Datastore
,
directory
Routing
)
exchange
.
Interface
{
func
NetMessageSession
(
parent
context
.
Context
,
s
bsnet
.
NetMessageService
,
p
*
peer
.
Peer
,
d
ds
.
Datastore
,
directory
bsnet
.
Routing
)
exchange
.
Interface
{
networkAdapter
:=
bsnet
.
NetMessageAdapter
(
s
,
nil
)
bs
:=
&
bitswap
{
...
...
@@ -54,7 +45,7 @@ type bitswap struct {
blockstore
blockstore
.
Blockstore
// routing interface for communication
routing
Routing
routing
bsnet
.
Routing
notifications
notifications
.
PubSub
...
...
bitswap_test.go
View file @
01625e32
...
...
@@ -11,14 +11,15 @@ import (
exchange
"github.com/jbenet/go-ipfs/exchange"
notifications
"github.com/jbenet/go-ipfs/exchange/bitswap/notifications"
strategy
"github.com/jbenet/go-ipfs/exchange/bitswap/strategy"
testnet
"github.com/jbenet/go-ipfs/exchange/bitswap/testnet"
peer
"github.com/jbenet/go-ipfs/peer"
testutil
"github.com/jbenet/go-ipfs/util/testutil"
)
func
TestGetBlockTimeout
(
t
*
testing
.
T
)
{
net
:=
Loc
alNetwork
()
rs
:=
new
RoutingServer
()
net
:=
testnet
.
Virtu
alNetwork
()
rs
:=
testnet
.
Virtual
RoutingServer
()
ipfs
:=
session
(
net
,
rs
,
[]
byte
(
"peer id"
))
ctx
,
_
:=
context
.
WithTimeout
(
context
.
Background
(),
time
.
Nanosecond
)
block
:=
testutil
.
NewBlockOrFail
(
t
,
"block"
)
...
...
@@ -31,8 +32,8 @@ func TestGetBlockTimeout(t *testing.T) {
func
TestProviderForKeyButNetworkCannotFind
(
t
*
testing
.
T
)
{
net
:=
Loc
alNetwork
()
rs
:=
new
RoutingServer
()
net
:=
testnet
.
Virtu
alNetwork
()
rs
:=
testnet
.
Virtual
RoutingServer
()
block
:=
testutil
.
NewBlockOrFail
(
t
,
"block"
)
rs
.
Announce
(
&
peer
.
Peer
{},
block
.
Key
())
// but not on network
...
...
@@ -52,8 +53,8 @@ func TestProviderForKeyButNetworkCannotFind(t *testing.T) {
func
TestGetBlockFromPeerAfterPeerAnnounces
(
t
*
testing
.
T
)
{
t
.
Skip
(
"Failing. Work in progress"
)
net
:=
Loc
alNetwork
()
rs
:=
new
RoutingServer
()
net
:=
testnet
.
Virtu
alNetwork
()
rs
:=
testnet
.
Virtual
RoutingServer
()
block
:=
testutil
.
NewBlockOrFail
(
t
,
"block"
)
hasBlock
:=
session
(
net
,
rs
,
[]
byte
(
"hasBlock"
))
...
...
@@ -78,7 +79,7 @@ type ipfs struct {
blockstore
bstore
.
Blockstore
}
func
session
(
net
Network
,
rs
RoutingServer
,
id
peer
.
ID
)
ipfs
{
func
session
(
net
testnet
.
Network
,
rs
testnet
.
RoutingServer
,
id
peer
.
ID
)
ipfs
{
p
:=
&
peer
.
Peer
{}
adapter
:=
net
.
Adapter
(
p
)
...
...
network/interface.go
View file @
01625e32
...
...
@@ -7,6 +7,7 @@ import (
bsmsg
"github.com/jbenet/go-ipfs/exchange/bitswap/message"
netmsg
"github.com/jbenet/go-ipfs/net/message"
peer
"github.com/jbenet/go-ipfs/peer"
u
"github.com/jbenet/go-ipfs/util"
)
// Adapter provides network connectivity for BitSwap sessions
...
...
@@ -41,3 +42,12 @@ type NetMessageService interface {
SendMessage
(
ctx
context
.
Context
,
m
netmsg
.
NetMessage
)
error
SetHandler
(
netservice
.
Handler
)
}
// TODO rename -> Router?
type
Routing
interface
{
// FindProvidersAsync returns a channel of providers for the given key
FindProvidersAsync
(
context
.
Context
,
u
.
Key
,
int
)
<-
chan
*
peer
.
Peer
// Provide provides the key to the network
Provide
(
key
u
.
Key
)
error
}
local_
network.go
→
testnet/
network.go
View file @
01625e32
...
...
@@ -30,7 +30,7 @@ type Network interface {
// network impl
func
Loc
alNetwork
()
Network
{
func
Virtu
alNetwork
()
Network
{
return
&
network
{
clients
:
make
(
map
[
util
.
Key
]
bsnet
.
Receiver
),
}
...
...
local_
network_test.go
→
testnet/
network_test.go
View file @
01625e32
...
...
@@ -12,7 +12,7 @@ import (
)
func
TestSendRequestToCooperativePeer
(
t
*
testing
.
T
)
{
net
:=
Loc
alNetwork
()
net
:=
Virtu
alNetwork
()
idOfRecipient
:=
[]
byte
(
"recipient"
)
...
...
@@ -59,7 +59,7 @@ func TestSendRequestToCooperativePeer(t *testing.T) {
}
func
TestSendMessageAsyncButWaitForResponse
(
t
*
testing
.
T
)
{
net
:=
Loc
alNetwork
()
net
:=
Virtu
alNetwork
()
idOfResponder
:=
[]
byte
(
"responder"
)
waiter
:=
net
.
Adapter
(
&
peer
.
Peer
{
ID
:
[]
byte
(
"waiter"
)})
responder
:=
net
.
Adapter
(
&
peer
.
Peer
{
ID
:
idOfResponder
})
...
...
hash_table
.go
→
testnet/routing
.go
View file @
01625e32
...
...
@@ -5,6 +5,7 @@ import (
"sync"
context
"github.com/jbenet/go-ipfs/Godeps/_workspace/src/code.google.com/p/go.net/context"
bsnet
"github.com/jbenet/go-ipfs/exchange/bitswap/network"
peer
"github.com/jbenet/go-ipfs/peer"
u
"github.com/jbenet/go-ipfs/util"
)
...
...
@@ -18,10 +19,10 @@ type RoutingServer interface {
// TODO
// Returns a Routing instance configured to query this hash table
Client
(
*
peer
.
Peer
)
Routing
Client
(
*
peer
.
Peer
)
bsnet
.
Routing
}
func
new
RoutingServer
()
RoutingServer
{
func
Virtual
RoutingServer
()
RoutingServer
{
return
&
hashTable
{
m
:
make
(
map
[
u
.
Key
]
map
[
*
peer
.
Peer
]
bool
),
}
...
...
@@ -61,7 +62,7 @@ func (rs *hashTable) Providers(k u.Key) []*peer.Peer {
}
// TODO
func
(
rs
*
hashTable
)
Client
(
p
*
peer
.
Peer
)
Routing
{
func
(
rs
*
hashTable
)
Client
(
p
*
peer
.
Peer
)
bsnet
.
Routing
{
return
&
routingClient
{
peer
:
p
,
hashTable
:
rs
,
...
...
hash_table
_test.go
→
testnet/routing
_test.go
View file @
01625e32
...
...
@@ -29,7 +29,7 @@ func TestSetAndGet(t *testing.T) {
ID
:
pid
,
}
k
:=
u
.
Key
(
"42"
)
rs
:=
new
RoutingServer
()
rs
:=
Virtual
RoutingServer
()
err
:=
rs
.
Announce
(
p
,
k
)
if
err
!=
nil
{
t
.
Fatal
(
err
)
...
...
@@ -50,7 +50,7 @@ func TestClientFindProviders(t *testing.T) {
peer
:=
&
peer
.
Peer
{
ID
:
[]
byte
(
"42"
),
}
rs
:=
new
RoutingServer
()
rs
:=
Virtual
RoutingServer
()
client
:=
rs
.
Client
(
peer
)
k
:=
u
.
Key
(
"hello"
)
err
:=
client
.
Provide
(
k
)
...
...
@@ -83,7 +83,7 @@ func TestClientFindProviders(t *testing.T) {
}
func
TestClientOverMax
(
t
*
testing
.
T
)
{
rs
:=
new
RoutingServer
()
rs
:=
Virtual
RoutingServer
()
k
:=
u
.
Key
(
"hello"
)
numProvidersForHelloKey
:=
100
for
i
:=
0
;
i
<
numProvidersForHelloKey
;
i
++
{
...
...
@@ -115,7 +115,7 @@ func TestClientOverMax(t *testing.T) {
// TODO does dht ensure won't receive self as a provider? probably not.
func
TestCanceledContext
(
t
*
testing
.
T
)
{
rs
:=
new
RoutingServer
()
rs
:=
Virtual
RoutingServer
()
k
:=
u
.
Key
(
"hello"
)
t
.
Log
(
"async'ly announce infinite stream of providers for key"
)
...
...
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