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
Commits
06b5804d
Commit
06b5804d
authored
Sep 15, 2014
by
Brian Tiger Chow
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
wip(bitswap) port service wrapper
parent
fda94d9f
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
12 additions
and
12 deletions
+12
-12
bitswap/bitswap.go
bitswap/bitswap.go
+4
-3
bitswap/transmission/service_wrapper.go
bitswap/transmission/service_wrapper.go
+8
-9
No files found.
bitswap/bitswap.go
View file @
06b5804d
...
...
@@ -11,6 +11,7 @@ import (
notifications
"github.com/jbenet/go-ipfs/bitswap/notifications"
tx
"github.com/jbenet/go-ipfs/bitswap/transmission"
blocks
"github.com/jbenet/go-ipfs/blocks"
net
"github.com/jbenet/go-ipfs/net"
peer
"github.com/jbenet/go-ipfs/peer"
routing
"github.com/jbenet/go-ipfs/routing"
u
"github.com/jbenet/go-ipfs/util"
...
...
@@ -61,14 +62,14 @@ type BitSwap struct {
}
// NewSession initializes a bitswap session.
func
NewSession
(
parent
context
.
Context
,
p
*
peer
.
Peer
,
d
ds
.
Datastore
,
r
routing
.
IpfsRouting
)
*
BitSwap
{
func
NewSession
(
parent
context
.
Context
,
s
net
.
Sender
,
p
*
peer
.
Peer
,
d
ds
.
Datastore
,
r
routing
.
IpfsRouting
)
*
BitSwap
{
// TODO(brian): define a contract for management of async operations that
// fall under bitswap's purview
ctx
,
_
:=
context
.
WithCancel
(
parent
)
//
ctx, _ := context.WithCancel(parent)
receiver
:=
tx
.
Forwarder
{}
sender
:=
tx
.
NewSe
rviceWrapper
(
ctx
,
&
receiver
)
sender
:=
tx
.
NewSe
nder
(
s
)
bs
:=
&
BitSwap
{
peer
:
p
,
datastore
:
d
,
...
...
bitswap/transmission/service_wrapper.go
View file @
06b5804d
...
...
@@ -4,21 +4,20 @@ import (
context
"github.com/jbenet/go-ipfs/Godeps/_workspace/src/code.google.com/p/go.net/context"
bsmsg
"github.com/jbenet/go-ipfs/bitswap/message"
i
net
"github.com/jbenet/go-ipfs/net"
net
"github.com/jbenet/go-ipfs/net"
netmsg
"github.com/jbenet/go-ipfs/net/message"
netservice
"github.com/jbenet/go-ipfs/net/service"
peer
"github.com/jbenet/go-ipfs/peer"
)
// NewServiceWrapper handles protobuf marshalling
func
NewServiceWrapper
(
ctx
context
.
Context
,
r
Receiver
)
Sender
{
h
:=
&
handlerWrapper
{
r
}
s
:=
netservice
.
NewService
(
h
)
s
.
Start
(
ctx
)
// NewSender wraps the net.service.Sender to perform translation between
// BitSwapMessage and NetMessage formats. This allows the BitSwap session to
// ignore these details.
func
NewSender
(
s
net
.
Sender
)
Sender
{
return
&
senderWrapper
{
s
}
}
// handlerWrapper is responsible for marshaling/unmarshaling NetMessages. It
// handlerWrapper implements the net.service.Handler interface. It is
// responsible for converting between
// delegates calls to the BitSwap delegate.
type
handlerWrapper
struct
{
bitswapDelegate
Receiver
...
...
@@ -51,7 +50,7 @@ func (wrapper *handlerWrapper) HandleMessage(
}
type
senderWrapper
struct
{
serviceDelegate
i
net
.
Sender
serviceDelegate
net
.
Sender
}
func
(
wrapper
*
senderWrapper
)
SendMessage
(
...
...
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