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
c0ab7e46
Commit
c0ab7e46
authored
Sep 18, 2014
by
Brian Tiger Chow
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
refac(bitswap) let adapter be created with nil delegate
yay deleting code.
parent
978a60f7
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
3 additions
and
58 deletions
+3
-58
bitswap.go
bitswap.go
+3
-4
network/forwarder.go
network/forwarder.go
+0
-28
network/forwarder_test.go
network/forwarder_test.go
+0
-26
No files found.
bitswap.go
View file @
c0ab7e46
...
...
@@ -31,16 +31,15 @@ type Routing interface {
// NewSession initializes a bitswap session.
func
NewSession
(
parent
context
.
Context
,
s
bsnet
.
NetworkService
,
p
*
peer
.
Peer
,
d
ds
.
Datastore
,
directory
Routing
)
exchange
.
Interface
{
// FIXME(brian): instantiate a concrete Strategist
receiver
:=
bsnet
.
Forwarder
{}
adapter
:=
bsnet
.
NewNetworkAdapter
(
s
,
nil
)
bs
:=
&
bitswap
{
blockstore
:
blockstore
.
NewBlockstore
(
d
),
notifications
:
notifications
.
New
(),
strategy
:
strategy
.
New
(),
routing
:
directory
,
sender
:
bsnet
.
NewNetworkAdapter
(
s
,
&
receiver
)
,
sender
:
adapter
,
}
receiver
.
Delegate
(
bs
)
adapter
.
Set
Delegate
(
bs
)
return
bs
}
...
...
network/forwarder.go
deleted
100644 → 0
View file @
978a60f7
package
network
import
(
context
"github.com/jbenet/go-ipfs/Godeps/_workspace/src/code.google.com/p/go.net/context"
bsmsg
"github.com/jbenet/go-ipfs/exchange/bitswap/message"
peer
"github.com/jbenet/go-ipfs/peer"
)
// Forwarder receives messages and forwards them to the delegate.
//
// Forwarder breaks the circular dependency between the BitSwap Session and the
// Network Service.
type
Forwarder
struct
{
delegate
Receiver
}
func
(
r
*
Forwarder
)
ReceiveMessage
(
ctx
context
.
Context
,
sender
*
peer
.
Peer
,
incoming
bsmsg
.
BitSwapMessage
)
(
*
peer
.
Peer
,
bsmsg
.
BitSwapMessage
,
error
)
{
if
r
.
delegate
==
nil
{
return
nil
,
nil
,
nil
}
return
r
.
delegate
.
ReceiveMessage
(
ctx
,
sender
,
incoming
)
}
func
(
r
*
Forwarder
)
Delegate
(
delegate
Receiver
)
{
r
.
delegate
=
delegate
}
network/forwarder_test.go
deleted
100644 → 0
View file @
978a60f7
package
network
import
(
"testing"
context
"github.com/jbenet/go-ipfs/Godeps/_workspace/src/code.google.com/p/go.net/context"
bsmsg
"github.com/jbenet/go-ipfs/exchange/bitswap/message"
peer
"github.com/jbenet/go-ipfs/peer"
)
func
TestDoesntPanicIfDelegateNotPresent
(
t
*
testing
.
T
)
{
fwdr
:=
Forwarder
{}
fwdr
.
ReceiveMessage
(
context
.
Background
(),
&
peer
.
Peer
{},
bsmsg
.
New
())
}
func
TestForwardsMessageToDelegate
(
t
*
testing
.
T
)
{
fwdr
:=
Forwarder
{
delegate
:
&
EchoDelegate
{}}
fwdr
.
ReceiveMessage
(
context
.
Background
(),
&
peer
.
Peer
{},
bsmsg
.
New
())
}
type
EchoDelegate
struct
{}
func
(
d
*
EchoDelegate
)
ReceiveMessage
(
ctx
context
.
Context
,
p
*
peer
.
Peer
,
incoming
bsmsg
.
BitSwapMessage
)
(
*
peer
.
Peer
,
bsmsg
.
BitSwapMessage
,
error
)
{
return
p
,
incoming
,
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