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