Commit 4637c322 authored by Juan Batiz-Benet's avatar Juan Batiz-Benet

swap net2 -> net

parent 442eb2c9
...@@ -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 {
......
...@@ -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.SetHandler(inet.ProtocolBitswap, bitswapNetwork.handleNewStream) host.SetStreamHandler(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:
......
...@@ -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.NewFromIpfsNetwork(client, routing) return bsnet.NewFromIpfsHost(client, routing)
} }
func (pn *peernet) HasPeer(p peer.ID) bool { func (pn *peernet) HasPeer(p peer.ID) bool {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment