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
4637c322
Commit
4637c322
authored
Jan 01, 2015
by
Juan Batiz-Benet
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
swap net2 -> net
parent
442eb2c9
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
14 additions
and
11 deletions
+14
-11
network/interface.go
network/interface.go
+3
-0
network/ipfs_impl.go
network/ipfs_impl.go
+10
-10
testnet/peernet.go
testnet/peernet.go
+1
-1
No files found.
network/interface.go
View file @
4637c322
...
@@ -5,9 +5,12 @@ import (
...
@@ -5,9 +5,12 @@ import (
bsmsg
"github.com/jbenet/go-ipfs/exchange/bitswap/message"
bsmsg
"github.com/jbenet/go-ipfs/exchange/bitswap/message"
peer
"github.com/jbenet/go-ipfs/p2p/peer"
peer
"github.com/jbenet/go-ipfs/p2p/peer"
protocol
"github.com/jbenet/go-ipfs/p2p/protocol"
u
"github.com/jbenet/go-ipfs/util"
u
"github.com/jbenet/go-ipfs/util"
)
)
var
ProtocolBitswap
protocol
.
ID
=
"/ipfs/bitswap"
// BitSwapNetwork provides network connectivity for BitSwap sessions
// BitSwapNetwork provides network connectivity for BitSwap sessions
type
BitSwapNetwork
interface
{
type
BitSwapNetwork
interface
{
...
...
network/ipfs_impl.go
View file @
4637c322
...
@@ -3,6 +3,7 @@ package network
...
@@ -3,6 +3,7 @@ package network
import
(
import
(
context
"github.com/jbenet/go-ipfs/Godeps/_workspace/src/code.google.com/p/go.net/context"
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"
bsmsg
"github.com/jbenet/go-ipfs/exchange/bitswap/message"
host
"github.com/jbenet/go-ipfs/p2p/host"
inet
"github.com/jbenet/go-ipfs/p2p/net"
inet
"github.com/jbenet/go-ipfs/p2p/net"
peer
"github.com/jbenet/go-ipfs/p2p/peer"
peer
"github.com/jbenet/go-ipfs/p2p/peer"
routing
"github.com/jbenet/go-ipfs/routing"
routing
"github.com/jbenet/go-ipfs/routing"
...
@@ -11,21 +12,20 @@ import (
...
@@ -11,21 +12,20 @@ import (
var
log
=
util
.
Logger
(
"bitswap_network"
)
var
log
=
util
.
Logger
(
"bitswap_network"
)
// NewFromIpfsNetwork returns a BitSwapNetwork supported by underlying IPFS
// NewFromIpfsHost returns a BitSwapNetwork supported by underlying IPFS host
// Dialer & Service
func
NewFromIpfsHost
(
host
host
.
Host
,
r
routing
.
IpfsRouting
)
BitSwapNetwork
{
func
NewFromIpfsNetwork
(
n
inet
.
Network
,
r
routing
.
IpfsRouting
)
BitSwapNetwork
{
bitswapNetwork
:=
impl
{
bitswapNetwork
:=
impl
{
network
:
n
,
host
:
host
,
routing
:
r
,
routing
:
r
,
}
}
n
.
Set
Handler
(
inet
.
ProtocolBitswap
,
bitswapNetwork
.
handleNewStream
)
host
.
SetStream
Handler
(
ProtocolBitswap
,
bitswapNetwork
.
handleNewStream
)
return
&
bitswapNetwork
return
&
bitswapNetwork
}
}
// impl transforms the ipfs network interface, which sends and receives
// impl transforms the ipfs network interface, which sends and receives
// NetMessage objects, into the bitswap network interface.
// NetMessage objects, into the bitswap network interface.
type
impl
struct
{
type
impl
struct
{
network
inet
.
Network
host
host
.
Host
routing
routing
.
IpfsRouting
routing
routing
.
IpfsRouting
// inbound messages from the network are forwarded to the receiver
// inbound messages from the network are forwarded to the receiver
...
@@ -33,7 +33,7 @@ type impl struct {
...
@@ -33,7 +33,7 @@ type impl struct {
}
}
func
(
bsnet
*
impl
)
DialPeer
(
ctx
context
.
Context
,
p
peer
.
ID
)
error
{
func
(
bsnet
*
impl
)
DialPeer
(
ctx
context
.
Context
,
p
peer
.
ID
)
error
{
return
bsnet
.
network
.
DialPeer
(
ctx
,
p
)
return
bsnet
.
host
.
Connect
(
ctx
,
peer
.
PeerInfo
{
ID
:
p
}
)
}
}
func
(
bsnet
*
impl
)
SendMessage
(
func
(
bsnet
*
impl
)
SendMessage
(
...
@@ -41,7 +41,7 @@ func (bsnet *impl) SendMessage(
...
@@ -41,7 +41,7 @@ func (bsnet *impl) SendMessage(
p
peer
.
ID
,
p
peer
.
ID
,
outgoing
bsmsg
.
BitSwapMessage
)
error
{
outgoing
bsmsg
.
BitSwapMessage
)
error
{
s
,
err
:=
bsnet
.
network
.
NewStream
(
inet
.
ProtocolBitswap
,
p
)
s
,
err
:=
bsnet
.
host
.
NewStream
(
ProtocolBitswap
,
p
)
if
err
!=
nil
{
if
err
!=
nil
{
return
err
return
err
}
}
...
@@ -55,7 +55,7 @@ func (bsnet *impl) SendRequest(
...
@@ -55,7 +55,7 @@ func (bsnet *impl) SendRequest(
p
peer
.
ID
,
p
peer
.
ID
,
outgoing
bsmsg
.
BitSwapMessage
)
(
bsmsg
.
BitSwapMessage
,
error
)
{
outgoing
bsmsg
.
BitSwapMessage
)
(
bsmsg
.
BitSwapMessage
,
error
)
{
s
,
err
:=
bsnet
.
network
.
NewStream
(
inet
.
ProtocolBitswap
,
p
)
s
,
err
:=
bsnet
.
host
.
NewStream
(
ProtocolBitswap
,
p
)
if
err
!=
nil
{
if
err
!=
nil
{
return
nil
,
err
return
nil
,
err
}
}
...
@@ -79,7 +79,7 @@ func (bsnet *impl) FindProvidersAsync(ctx context.Context, k util.Key, max int)
...
@@ -79,7 +79,7 @@ func (bsnet *impl) FindProvidersAsync(ctx context.Context, k util.Key, max int)
defer
close
(
out
)
defer
close
(
out
)
providers
:=
bsnet
.
routing
.
FindProvidersAsync
(
ctx
,
k
,
max
)
providers
:=
bsnet
.
routing
.
FindProvidersAsync
(
ctx
,
k
,
max
)
for
info
:=
range
providers
{
for
info
:=
range
providers
{
bsnet
.
network
.
Peerstore
()
.
AddAddresses
(
info
.
ID
,
info
.
Addrs
)
bsnet
.
host
.
Peerstore
()
.
AddAddresses
(
info
.
ID
,
info
.
Addrs
)
select
{
select
{
case
<-
ctx
.
Done
()
:
case
<-
ctx
.
Done
()
:
case
out
<-
info
.
ID
:
case
out
<-
info
.
ID
:
...
...
testnet/peernet.go
View file @
4637c322
...
@@ -25,7 +25,7 @@ func (pn *peernet) Adapter(p testutil.Identity) bsnet.BitSwapNetwork {
...
@@ -25,7 +25,7 @@ func (pn *peernet) Adapter(p testutil.Identity) bsnet.BitSwapNetwork {
panic
(
err
.
Error
())
panic
(
err
.
Error
())
}
}
routing
:=
pn
.
routingserver
.
ClientWithDatastore
(
context
.
TODO
(),
p
,
ds
.
NewMapDatastore
())
routing
:=
pn
.
routingserver
.
ClientWithDatastore
(
context
.
TODO
(),
p
,
ds
.
NewMapDatastore
())
return
bsnet
.
NewFromIpfs
Network
(
client
,
routing
)
return
bsnet
.
NewFromIpfs
Host
(
client
,
routing
)
}
}
func
(
pn
*
peernet
)
HasPeer
(
p
peer
.
ID
)
bool
{
func
(
pn
*
peernet
)
HasPeer
(
p
peer
.
ID
)
bool
{
...
...
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