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
ab460ed8
Commit
ab460ed8
authored
Sep 14, 2014
by
Brian Tiger Chow
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
refactor(bs, core) rename bitswap objects
parent
0075a47d
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
19 additions
and
15 deletions
+19
-15
bitswap/bitswap.go
bitswap/bitswap.go
+8
-3
bitswap/transmission/service_wrapper.go
bitswap/transmission/service_wrapper.go
+6
-6
core/core.go
core/core.go
+5
-6
No files found.
bitswap/bitswap.go
View file @
ab460ed8
...
...
@@ -60,10 +60,15 @@ type BitSwap struct {
haltChan
chan
struct
{}
}
// NewBitSwap creates a new BitSwap instance. It does not check its parameters.
func
NewBitSwap
(
p
*
peer
.
Peer
,
d
ds
.
Datastore
,
r
routing
.
IpfsRouting
)
*
BitSwap
{
// NewSession initializes a bitswap session.
func
NewSession
(
parent
context
.
Context
,
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
)
receiver
:=
tx
.
Forwarder
{}
sender
:=
tx
.
New
BSNet
Service
(
context
.
Background
()
,
&
receiver
)
sender
:=
tx
.
NewService
Wrapper
(
ctx
,
&
receiver
)
bs
:=
&
BitSwap
{
peer
:
p
,
datastore
:
d
,
...
...
bitswap/transmission/service_wrapper.go
View file @
ab460ed8
...
...
@@ -9,10 +9,10 @@ import (
peer
"github.com/jbenet/go-ipfs/peer"
)
func
New
BSNet
Service
(
ctx
context
.
Context
,
r
Receiver
)
Sender
{
func
NewService
Wrapper
(
ctx
context
.
Context
,
r
Receiver
)
Sender
{
h
:=
&
handlerWrapper
{
r
}
s
:=
netservice
.
NewService
(
ctx
,
h
)
return
&
se
rvice
Wrapper
{
*
s
}
return
&
se
nder
Wrapper
{
s
}
}
// handlerWrapper is responsible for marshaling/unmarshaling NetMessages. It
...
...
@@ -47,11 +47,11 @@ func (wrapper *handlerWrapper) HandleMessage(
return
outgoing
,
nil
}
type
se
rvice
Wrapper
struct
{
serviceDelegate
netservice
.
Se
rvice
type
se
nder
Wrapper
struct
{
serviceDelegate
netservice
.
Se
nder
}
func
(
wrapper
*
se
rvice
Wrapper
)
SendMessage
(
func
(
wrapper
*
se
nder
Wrapper
)
SendMessage
(
ctx
context
.
Context
,
p
*
peer
.
Peer
,
outgoing
bsmsg
.
Exportable
)
error
{
nmsg
,
err
:=
outgoing
.
ToNet
(
p
)
if
err
!=
nil
{
...
...
@@ -61,7 +61,7 @@ func (wrapper *serviceWrapper) SendMessage(
return
wrapper
.
serviceDelegate
.
SendMessage
(
ctx
,
nmsg
,
req
.
ID
)
}
func
(
wrapper
*
se
rvice
Wrapper
)
SendRequest
(
ctx
context
.
Context
,
func
(
wrapper
*
se
nder
Wrapper
)
SendRequest
(
ctx
context
.
Context
,
p
*
peer
.
Peer
,
outgoing
bsmsg
.
Exportable
)
(
bsmsg
.
BitSwapMessage
,
error
)
{
outgoingMsg
,
err
:=
outgoing
.
ToNet
(
p
)
...
...
core/core.go
View file @
ab460ed8
...
...
@@ -46,7 +46,7 @@ type IpfsNode struct {
Routing
routing
.
IpfsRouting
// the block exchange + strategy (bitswap)
BitSwap
*
bitswap
.
BitSwap
BitSwap
bitswap
.
BitSwap
// the block service, get/add blocks.
Blocks
*
bserv
.
BlockService
...
...
@@ -81,7 +81,6 @@ func NewIpfsNode(cfg *config.Config, online bool) (*IpfsNode, error) {
net
*
inet
.
Network
// TODO: refactor so we can use IpfsRouting interface instead of being DHT-specific
route
*
dht
.
IpfsDHT
swap
*
bitswap
.
BitSwap
)
if
online
{
...
...
@@ -99,14 +98,14 @@ func NewIpfsNode(cfg *config.Config, online bool) (*IpfsNode, error) {
route
.
Start
()
// TODO(brian): pass a context to bs for its async operations
swap
=
bitswap
.
New
BitSwap
(
local
,
d
,
route
)
swap
.
SetStrategy
(
bitswap
.
YesManStrategy
)
bit
swap
Session
:
=
bitswap
.
New
Session
(
context
.
TODO
(),
local
,
d
,
route
)
bit
swap
Session
.
SetStrategy
(
bitswap
.
YesManStrategy
)
// TODO(brian): pass a context to initConnections
go
initConnections
(
cfg
,
route
)
}
bs
,
err
:=
bserv
.
NewBlockService
(
d
,
swap
)
bs
,
err
:=
bserv
.
NewBlockService
(
d
,
bit
swap
Session
)
if
err
!=
nil
{
return
nil
,
err
}
...
...
@@ -120,7 +119,7 @@ func NewIpfsNode(cfg *config.Config, online bool) (*IpfsNode, error) {
Blocks
:
bs
,
DAG
:
dag
,
Resolver
:
&
path
.
Resolver
{
DAG
:
dag
},
BitSwap
:
swap
,
BitSwap
:
bit
swap
Session
,
Identity
:
local
,
Routing
:
route
,
},
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