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
89304239
Commit
89304239
authored
Sep 18, 2014
by
Brian Tiger Chow
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
style(exch:bitswap) rename adapter, session, etc.
style(exch:bitswap) rename NetMessage adapter impl
parent
619a9470
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
25 additions
and
24 deletions
+25
-24
bitswap.go
bitswap.go
+5
-4
network/interface.go
network/interface.go
+3
-3
network/net_message_adapter.go
network/net_message_adapter.go
+17
-17
No files found.
bitswap.go
View file @
89304239
...
...
@@ -24,10 +24,11 @@ type Routing interface {
Provide
(
key
u
.
Key
)
error
}
// NewSession initializes a bitswap session.
func
NewSession
(
parent
context
.
Context
,
s
bsnet
.
NetworkService
,
p
*
peer
.
Peer
,
d
ds
.
Datastore
,
directory
Routing
)
exchange
.
Interface
{
// NetMessageSession initializes a BitSwap session that communicates over the
// provided NetMessage service
func
NetMessageSession
(
parent
context
.
Context
,
s
bsnet
.
NetMessageService
,
p
*
peer
.
Peer
,
d
ds
.
Datastore
,
directory
Routing
)
exchange
.
Interface
{
networkAdapter
:=
bsnet
.
Ne
wNetwork
Adapter
(
s
,
nil
)
networkAdapter
:=
bsnet
.
Ne
tMessage
Adapter
(
s
,
nil
)
bs
:=
&
bitswap
{
blockstore
:
blockstore
.
NewBlockstore
(
d
),
notifications
:
notifications
.
New
(),
...
...
@@ -44,7 +45,7 @@ func NewSession(parent context.Context, s bsnet.NetworkService, p *peer.Peer, d
type
bitswap
struct
{
// sender delivers messages on behalf of the session
sender
bsnet
.
Network
Adapter
sender
bsnet
.
Adapter
// blockstore is the local database
// NB: ensure threadsafety
...
...
network/interface.go
View file @
89304239
...
...
@@ -9,8 +9,8 @@ import (
peer
"github.com/jbenet/go-ipfs/peer"
)
//
Network
Adapter
mediates the exchange's communication with the network.
type
Network
Adapter
interface
{
// Adapter
provides network connectivity for BitSwap sessions
type
Adapter
interface
{
// SendMessage sends a BitSwap message to a peer.
SendMessage
(
...
...
@@ -36,7 +36,7 @@ type Receiver interface {
}
// TODO(brian): move this to go-ipfs/net package
type
Net
work
Service
interface
{
type
Net
Message
Service
interface
{
SendRequest
(
ctx
context
.
Context
,
m
netmsg
.
NetMessage
)
(
netmsg
.
NetMessage
,
error
)
SendMessage
(
ctx
context
.
Context
,
m
netmsg
.
NetMessage
)
error
SetHandler
(
netservice
.
Handler
)
...
...
network/net
work
_adapter.go
→
network/net
_message
_adapter.go
View file @
89304239
...
...
@@ -10,27 +10,27 @@ import (
peer
"github.com/jbenet/go-ipfs/peer"
)
// NewSender wraps a network Service to perform translation between
// BitSwapMessage and NetMessage formats. This allows the BitSwap session to
// ignore these details.
func
NewNetworkAdapter
(
s
NetworkService
,
r
Receiver
)
NetworkAdapter
{
adapter
:=
networkAdapter
{
networkService
:
s
,
receiver
:
r
,
// NetMessageAdapter wraps a NetMessage network service
func
NetMessageAdapter
(
s
NetMessageService
,
r
Receiver
)
Adapter
{
adapter
:=
impl
{
nms
:
s
,
receiver
:
r
,
}
s
.
SetHandler
(
&
adapter
)
return
&
adapter
}
// networkAdapter implements NetworkAdapter
type
networkAdapter
struct
{
networkService
NetworkService
receiver
Receiver
// implements an Adapter that integrates with a NetMessage network service
type
impl
struct
{
nms
NetMessageService
// inbound messages from the network are forwarded to the receiver
receiver
Receiver
}
// HandleMessage marshals and unmarshals net messages, forwarding them to the
// BitSwapMessage receiver
func
(
adapter
*
networkAdapter
)
HandleMessage
(
func
(
adapter
*
impl
)
HandleMessage
(
ctx
context
.
Context
,
incoming
netmsg
.
NetMessage
)
(
netmsg
.
NetMessage
,
error
)
{
if
adapter
.
receiver
==
nil
{
...
...
@@ -60,7 +60,7 @@ func (adapter *networkAdapter) HandleMessage(
return
outgoing
,
nil
}
func
(
adapter
*
networkAdapter
)
SendMessage
(
func
(
adapter
*
impl
)
SendMessage
(
ctx
context
.
Context
,
p
*
peer
.
Peer
,
outgoing
bsmsg
.
BitSwapMessage
)
error
{
...
...
@@ -69,10 +69,10 @@ func (adapter *networkAdapter) SendMessage(
if
err
!=
nil
{
return
err
}
return
adapter
.
n
etworkService
.
SendMessage
(
ctx
,
nmsg
)
return
adapter
.
n
ms
.
SendMessage
(
ctx
,
nmsg
)
}
func
(
adapter
*
networkAdapter
)
SendRequest
(
func
(
adapter
*
impl
)
SendRequest
(
ctx
context
.
Context
,
p
*
peer
.
Peer
,
outgoing
bsmsg
.
BitSwapMessage
)
(
bsmsg
.
BitSwapMessage
,
error
)
{
...
...
@@ -81,13 +81,13 @@ func (adapter *networkAdapter) SendRequest(
if
err
!=
nil
{
return
nil
,
err
}
incomingMsg
,
err
:=
adapter
.
n
etworkService
.
SendRequest
(
ctx
,
outgoingMsg
)
incomingMsg
,
err
:=
adapter
.
n
ms
.
SendRequest
(
ctx
,
outgoingMsg
)
if
err
!=
nil
{
return
nil
,
err
}
return
bsmsg
.
FromNet
(
incomingMsg
)
}
func
(
adapter
*
networkAdapter
)
SetDelegate
(
r
Receiver
)
{
func
(
adapter
*
impl
)
SetDelegate
(
r
Receiver
)
{
adapter
.
receiver
=
r
}
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