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
bd392b81
Commit
bd392b81
authored
Oct 10, 2014
by
Juan Batiz-Benet
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
clean up and add inet.Network to bitswap
new Service interface
parent
866f2538
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
13 additions
and
14 deletions
+13
-14
bitswap.go
bitswap.go
+10
-3
network/interface.go
network/interface.go
+0
-9
network/net_message_adapter.go
network/net_message_adapter.go
+3
-2
No files found.
bitswap.go
View file @
bd392b81
...
...
@@ -11,6 +11,7 @@ import (
bsnet
"github.com/jbenet/go-ipfs/exchange/bitswap/network"
notifications
"github.com/jbenet/go-ipfs/exchange/bitswap/notifications"
strategy
"github.com/jbenet/go-ipfs/exchange/bitswap/strategy"
inet
"github.com/jbenet/go-ipfs/net"
peer
"github.com/jbenet/go-ipfs/peer"
u
"github.com/jbenet/go-ipfs/util"
)
...
...
@@ -19,14 +20,17 @@ var log = u.Logger("bitswap")
// NetMessageSession initializes a BitSwap session that communicates over the
// provided NetMessage service
func
NetMessageSession
(
parent
context
.
Context
,
p
*
peer
.
Peer
,
s
bsnet
.
NetMessageService
,
directory
bsnet
.
Routing
,
d
ds
.
Datastore
,
nice
bool
)
exchange
.
Interface
{
func
NetMessageSession
(
parent
context
.
Context
,
p
*
peer
.
Peer
,
net
inet
.
Network
,
srv
inet
.
Service
,
directory
bsnet
.
Routing
,
d
ds
.
Datastore
,
nice
bool
)
exchange
.
Interface
{
networkAdapter
:=
bsnet
.
NetMessageAdapter
(
s
,
nil
)
networkAdapter
:=
bsnet
.
NetMessageAdapter
(
s
rv
,
nil
)
bs
:=
&
bitswap
{
blockstore
:
blockstore
.
NewBlockstore
(
d
),
notifications
:
notifications
.
New
(),
strategy
:
strategy
.
New
(
nice
),
routing
:
directory
,
network
:
net
,
sender
:
networkAdapter
,
wantlist
:
u
.
NewKeySet
(),
}
...
...
@@ -38,6 +42,9 @@ func NetMessageSession(parent context.Context, p *peer.Peer, s bsnet.NetMessageS
// bitswap instances implement the bitswap protocol.
type
bitswap
struct
{
// network maintains connections to the outside world.
network
inet
.
Network
// sender delivers messages on behalf of the session
sender
bsnet
.
Adapter
...
...
@@ -79,7 +86,7 @@ func (bs *bitswap) Block(parent context.Context, k u.Key) (*blocks.Block, error)
}
message
.
AppendWanted
(
k
)
for
iiiii
:=
range
peersToQuery
{
//
log.Debug("bitswap got peersToQuery: %s", iiiii)
log
.
Debug
(
"bitswap got peersToQuery: %s"
,
iiiii
)
go
func
(
p
*
peer
.
Peer
)
{
response
,
err
:=
bs
.
sender
.
SendRequest
(
ctx
,
p
,
message
)
if
err
!=
nil
{
...
...
network/interface.go
View file @
bd392b81
...
...
@@ -2,10 +2,8 @@ package network
import
(
context
"github.com/jbenet/go-ipfs/Godeps/_workspace/src/code.google.com/p/go.net/context"
netservice
"github.com/jbenet/go-ipfs/net/service"
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"
)
...
...
@@ -38,13 +36,6 @@ type Receiver interface {
ReceiveError
(
error
)
}
// TODO(brian): move this to go-ipfs/net package
type
NetMessageService
interface
{
SendRequest
(
ctx
context
.
Context
,
m
netmsg
.
NetMessage
)
(
netmsg
.
NetMessage
,
error
)
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
...
...
network/net_message_adapter.go
View file @
bd392b81
...
...
@@ -4,12 +4,13 @@ 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"
inet
"github.com/jbenet/go-ipfs/net"
netmsg
"github.com/jbenet/go-ipfs/net/message"
peer
"github.com/jbenet/go-ipfs/peer"
)
// NetMessageAdapter wraps a NetMessage network service
func
NetMessageAdapter
(
s
NetMessage
Service
,
r
Receiver
)
Adapter
{
func
NetMessageAdapter
(
s
inet
.
Service
,
r
Receiver
)
Adapter
{
adapter
:=
impl
{
nms
:
s
,
receiver
:
r
,
...
...
@@ -20,7 +21,7 @@ func NetMessageAdapter(s NetMessageService, r Receiver) Adapter {
// implements an Adapter that integrates with a NetMessage network service
type
impl
struct
{
nms
NetMessage
Service
nms
inet
.
Service
// inbound messages from the network are forwarded to the receiver
receiver
Receiver
...
...
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