Skip to content
This repository has been archived by the owner on Feb 1, 2023. It is now read-only.

Commit

Permalink
migrate to go-libp2p-core.
Browse files Browse the repository at this point in the history
  • Loading branch information
raulk committed May 28, 2019
1 parent a1ca6a6 commit 53761df
Show file tree
Hide file tree
Showing 31 changed files with 128 additions and 180 deletions.
2 changes: 1 addition & 1 deletion bitswap.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ import (
metrics "github.com/ipfs/go-metrics-interface"
process "github.com/jbenet/goprocess"
procctx "github.com/jbenet/goprocess/context"
peer "github.com/libp2p/go-libp2p-peer"
peer "github.com/libp2p/go-libp2p-core/peer"
)

var log = logging.Logger("bitswap")
Expand Down
2 changes: 1 addition & 1 deletion decision/engine.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import (
logging "github.com/ipfs/go-log"
"github.com/ipfs/go-peertaskqueue"
"github.com/ipfs/go-peertaskqueue/peertask"
peer "github.com/libp2p/go-libp2p-peer"
peer "github.com/libp2p/go-libp2p-core/peer"
)

// TODO consider taking responsibility for other types of requests. For
Expand Down
2 changes: 1 addition & 1 deletion decision/engine_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import (
ds "github.com/ipfs/go-datastore"
dssync "github.com/ipfs/go-datastore/sync"
blockstore "github.com/ipfs/go-ipfs-blockstore"
peer "github.com/libp2p/go-libp2p-peer"
peer "github.com/libp2p/go-libp2p-core/peer"
testutil "github.com/libp2p/go-testutil"
)

Expand Down
2 changes: 1 addition & 1 deletion decision/ledger.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
wl "github.com/ipfs/go-bitswap/wantlist"

cid "github.com/ipfs/go-cid"
peer "github.com/libp2p/go-libp2p-peer"
peer "github.com/libp2p/go-libp2p-core/peer"
)

func newLedger(p peer.ID) *ledger {
Expand Down
27 changes: 7 additions & 20 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
module github.com/ipfs/go-bitswap

require (
github.com/btcsuite/btcd v0.0.0-20190523000118-16327141da8c // indirect
github.com/cskr/pubsub v1.0.2
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/gogo/protobuf v1.2.1
Expand All @@ -22,31 +21,19 @@ require (
github.com/ipfs/go-metrics-interface v0.0.1
github.com/ipfs/go-peertaskqueue v0.0.4
github.com/jbenet/goprocess v0.1.3
github.com/libp2p/go-libp2p v0.0.30
github.com/libp2p/go-libp2p-host v0.0.3
github.com/libp2p/go-libp2p-interface-connmgr v0.0.5
github.com/libp2p/go-libp2p-loggables v0.0.1
github.com/libp2p/go-libp2p-net v0.0.2
github.com/libp2p/go-libp2p-netutil v0.0.1
github.com/libp2p/go-libp2p-peer v0.2.0
github.com/libp2p/go-libp2p-peerstore v0.1.0
github.com/libp2p/go-libp2p-protocol v0.1.0
github.com/libp2p/go-libp2p-routing v0.0.1
github.com/libp2p/go-libp2p-yamux v0.1.3 // indirect
github.com/libp2p/go-mplex v0.0.4 // indirect
github.com/libp2p/go-stream-muxer v0.1.0 // indirect
github.com/libp2p/go-libp2p v0.1.0
github.com/libp2p/go-libp2p-core v0.0.2
github.com/libp2p/go-libp2p-loggables v0.1.0
github.com/libp2p/go-libp2p-netutil v0.1.0
github.com/libp2p/go-libp2p-testing v0.0.3
github.com/libp2p/go-testutil v0.0.1
github.com/libp2p/go-yamux v1.2.3 // indirect
github.com/mattn/go-colorable v0.1.2 // indirect
github.com/minio/sha256-simd v0.1.0 // indirect
github.com/multiformats/go-multiaddr v0.0.4
github.com/multiformats/go-multistream v0.1.0 // indirect
github.com/onsi/ginkgo v1.8.0 // indirect
github.com/onsi/gomega v1.5.0 // indirect
github.com/opentracing/opentracing-go v1.1.0 // indirect
golang.org/x/crypto v0.0.0-20190513172903-22d7a77e9e5f // indirect
golang.org/x/net v0.0.0-20190522155817-f3200d17e092 // indirect
golang.org/x/sys v0.0.0-20190524122548-abf6ff778158 // indirect
golang.org/x/text v0.3.2 // indirect
gopkg.in/yaml.v2 v2.2.2 // indirect
)

replace github.com/ipfs/go-ipfs-routing => ../go-ipfs-routing
129 changes: 41 additions & 88 deletions go.sum

Large diffs are not rendered by default.

5 changes: 3 additions & 2 deletions message/message.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ import (

ggio "github.com/gogo/protobuf/io"
cid "github.com/ipfs/go-cid"
inet "github.com/libp2p/go-libp2p-net"

"github.com/libp2p/go-libp2p-core/network"
)

// BitSwapMessage is the basic interface for interacting building, encoding,
Expand Down Expand Up @@ -169,7 +170,7 @@ func (m *impl) AddBlock(b blocks.Block) {

// FromNet generates a new BitswapMessage from incoming data on an io.Reader.
func FromNet(r io.Reader) (BitSwapMessage, error) {
pbr := ggio.NewDelimitedReader(r, inet.MessageSizeMax)
pbr := ggio.NewDelimitedReader(r, network.MessageSizeMax)
return FromPBReader(pbr)
}

Expand Down
2 changes: 1 addition & 1 deletion messagequeue/messagequeue.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
bsnet "github.com/ipfs/go-bitswap/network"
wantlist "github.com/ipfs/go-bitswap/wantlist"
logging "github.com/ipfs/go-log"
peer "github.com/libp2p/go-libp2p-peer"
peer "github.com/libp2p/go-libp2p-core/peer"
)

var log = logging.Logger("bitswap")
Expand Down
2 changes: 1 addition & 1 deletion messagequeue/messagequeue_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (

bsmsg "github.com/ipfs/go-bitswap/message"
bsnet "github.com/ipfs/go-bitswap/network"
peer "github.com/libp2p/go-libp2p-peer"
peer "github.com/libp2p/go-libp2p-core/peer"
)

type fakeMessageNetwork struct {
Expand Down
9 changes: 5 additions & 4 deletions network/interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,10 @@ import (
bsmsg "github.com/ipfs/go-bitswap/message"

cid "github.com/ipfs/go-cid"
ifconnmgr "github.com/libp2p/go-libp2p-interface-connmgr"
peer "github.com/libp2p/go-libp2p-peer"
protocol "github.com/libp2p/go-libp2p-protocol"

"github.com/libp2p/go-libp2p-core/connmgr"
"github.com/libp2p/go-libp2p-core/peer"
"github.com/libp2p/go-libp2p-core/protocol"
)

var (
Expand Down Expand Up @@ -38,7 +39,7 @@ type BitSwapNetwork interface {

NewMessageSender(context.Context, peer.ID) (MessageSender, error)

ConnectionManager() ifconnmgr.ConnManager
ConnectionManager() connmgr.ConnManager

Stats() Stats

Expand Down
45 changes: 23 additions & 22 deletions network/ipfs_impl.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,17 @@ import (
"time"

bsmsg "github.com/ipfs/go-bitswap/message"
"github.com/libp2p/go-libp2p-core/helpers"

ggio "github.com/gogo/protobuf/io"
cid "github.com/ipfs/go-cid"
logging "github.com/ipfs/go-log"
host "github.com/libp2p/go-libp2p-host"
ifconnmgr "github.com/libp2p/go-libp2p-interface-connmgr"
inet "github.com/libp2p/go-libp2p-net"
peer "github.com/libp2p/go-libp2p-peer"
pstore "github.com/libp2p/go-libp2p-peerstore"
routing "github.com/libp2p/go-libp2p-routing"
"github.com/libp2p/go-libp2p-core/connmgr"
"github.com/libp2p/go-libp2p-core/host"
"github.com/libp2p/go-libp2p-core/network"
"github.com/libp2p/go-libp2p-core/peer"
peerstore "github.com/libp2p/go-libp2p-core/peerstore"
"github.com/libp2p/go-libp2p-core/routing"
ma "github.com/multiformats/go-multiaddr"
)

Expand Down Expand Up @@ -47,11 +48,11 @@ type impl struct {
}

type streamMessageSender struct {
s inet.Stream
s network.Stream
}

func (s *streamMessageSender) Close() error {
return inet.FullClose(s.s)
return helpers.FullClose(s.s)
}

func (s *streamMessageSender) Reset() error {
Expand All @@ -62,7 +63,7 @@ func (s *streamMessageSender) SendMsg(ctx context.Context, msg bsmsg.BitSwapMess
return msgToStream(ctx, s.s, msg)
}

func msgToStream(ctx context.Context, s inet.Stream, msg bsmsg.BitSwapMessage) error {
func msgToStream(ctx context.Context, s network.Stream, msg bsmsg.BitSwapMessage) error {
deadline := time.Now().Add(sendMessageTimeout)
if dl, ok := ctx.Deadline(); ok {
deadline = dl
Expand Down Expand Up @@ -102,7 +103,7 @@ func (bsnet *impl) NewMessageSender(ctx context.Context, p peer.ID) (MessageSend
return &streamMessageSender{s: s}, nil
}

func (bsnet *impl) newStreamToPeer(ctx context.Context, p peer.ID) (inet.Stream, error) {
func (bsnet *impl) newStreamToPeer(ctx context.Context, p peer.ID) (network.Stream, error) {
return bsnet.host.NewStream(ctx, p, ProtocolBitswap, ProtocolBitswapOne, ProtocolBitswapNoVers)
}

Expand All @@ -123,7 +124,7 @@ func (bsnet *impl) SendMessage(
atomic.AddUint64(&bsnet.stats.MessagesSent, 1)

// TODO(https://github.com/libp2p/go-libp2p-net/issues/28): Avoid this goroutine.
go inet.AwaitEOF(s)
go helpers.AwaitEOF(s)
return s.Close()

}
Expand All @@ -139,7 +140,7 @@ func (bsnet *impl) SetDelegate(r Receiver) {
}

func (bsnet *impl) ConnectTo(ctx context.Context, p peer.ID) error {
return bsnet.host.Connect(ctx, pstore.PeerInfo{ID: p})
return bsnet.host.Connect(ctx, peer.AddrInfo{ID: p})
}

// FindProvidersAsync returns a channel of providers for the given key.
Expand All @@ -152,7 +153,7 @@ func (bsnet *impl) FindProvidersAsync(ctx context.Context, k cid.Cid, max int) <
if info.ID == bsnet.host.ID() {
continue // ignore self as provider
}
bsnet.host.Peerstore().AddAddrs(info.ID, info.Addrs, pstore.TempAddrTTL)
bsnet.host.Peerstore().AddAddrs(info.ID, info.Addrs, peerstore.TempAddrTTL)
select {
case <-ctx.Done():
return
Expand All @@ -169,15 +170,15 @@ func (bsnet *impl) Provide(ctx context.Context, k cid.Cid) error {
}

// handleNewStream receives a new stream from the network.
func (bsnet *impl) handleNewStream(s inet.Stream) {
func (bsnet *impl) handleNewStream(s network.Stream) {
defer s.Close()

if bsnet.receiver == nil {
s.Reset()
return
}

reader := ggio.NewDelimitedReader(s, inet.MessageSizeMax)
reader := ggio.NewDelimitedReader(s, network.MessageSizeMax)
for {
received, err := bsmsg.FromPBReader(reader)
if err != nil {
Expand All @@ -197,7 +198,7 @@ func (bsnet *impl) handleNewStream(s inet.Stream) {
}
}

func (bsnet *impl) ConnectionManager() ifconnmgr.ConnManager {
func (bsnet *impl) ConnectionManager() connmgr.ConnManager {
return bsnet.host.ConnManager()
}

Expand All @@ -214,15 +215,15 @@ func (nn *netNotifiee) impl() *impl {
return (*impl)(nn)
}

func (nn *netNotifiee) Connected(n inet.Network, v inet.Conn) {
func (nn *netNotifiee) Connected(n network.Network, v network.Conn) {
nn.impl().receiver.PeerConnected(v.RemotePeer())
}

func (nn *netNotifiee) Disconnected(n inet.Network, v inet.Conn) {
func (nn *netNotifiee) Disconnected(n network.Network, v network.Conn) {
nn.impl().receiver.PeerDisconnected(v.RemotePeer())
}

func (nn *netNotifiee) OpenedStream(n inet.Network, v inet.Stream) {}
func (nn *netNotifiee) ClosedStream(n inet.Network, v inet.Stream) {}
func (nn *netNotifiee) Listen(n inet.Network, a ma.Multiaddr) {}
func (nn *netNotifiee) ListenClose(n inet.Network, a ma.Multiaddr) {}
func (nn *netNotifiee) OpenedStream(n network.Network, v network.Stream) {}
func (nn *netNotifiee) ClosedStream(n network.Network, v network.Stream) {}
func (nn *netNotifiee) Listen(n network.Network, a ma.Multiaddr) {}
func (nn *netNotifiee) ListenClose(n network.Network, a ma.Multiaddr) {}
9 changes: 5 additions & 4 deletions network/ipfs_impl_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,10 @@ import (
tn "github.com/ipfs/go-bitswap/testnet"
blocksutil "github.com/ipfs/go-ipfs-blocksutil"
mockrouting "github.com/ipfs/go-ipfs-routing/mock"
peer "github.com/libp2p/go-libp2p-peer"

"github.com/libp2p/go-libp2p-core/peer"
"github.com/libp2p/go-libp2p-testing/net"
mocknet "github.com/libp2p/go-libp2p/p2p/net/mock"
testutil "github.com/libp2p/go-testutil"
)

// Receiver is an interface for receiving messages from the GraphSyncNetwork.
Expand Down Expand Up @@ -62,8 +63,8 @@ func TestMessageSendAndReceive(t *testing.T) {
if err != nil {
t.Fatal("Unable to setup network")
}
p1 := testutil.RandIdentityOrFatal(t)
p2 := testutil.RandIdentityOrFatal(t)
p1 := tnet.RandIdentityOrFatal(t)
p2 := tnet.RandIdentityOrFatal(t)

bsnet1 := streamNet.Adapter(p1)
bsnet2 := streamNet.Adapter(p2)
Expand Down
2 changes: 1 addition & 1 deletion peermanager/peermanager.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
bsmsg "github.com/ipfs/go-bitswap/message"
wantlist "github.com/ipfs/go-bitswap/wantlist"

peer "github.com/libp2p/go-libp2p-peer"
peer "github.com/libp2p/go-libp2p-core/peer"
)

// PeerQueue provides a queer of messages to be sent for a single peer.
Expand Down
2 changes: 1 addition & 1 deletion peermanager/peermanager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (

bsmsg "github.com/ipfs/go-bitswap/message"
wantlist "github.com/ipfs/go-bitswap/wantlist"
"github.com/libp2p/go-libp2p-peer"
"github.com/libp2p/go-libp2p-core/peer"
)

type messageSent struct {
Expand Down
2 changes: 1 addition & 1 deletion providerquerymanager/providerquerymanager.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (

"github.com/ipfs/go-cid"
logging "github.com/ipfs/go-log"
peer "github.com/libp2p/go-libp2p-peer"
peer "github.com/libp2p/go-libp2p-core/peer"
)

var log = logging.Logger("bitswap")
Expand Down
2 changes: 1 addition & 1 deletion providerquerymanager/providerquerymanager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
"github.com/ipfs/go-bitswap/testutil"

cid "github.com/ipfs/go-cid"
"github.com/libp2p/go-libp2p-peer"
"github.com/libp2p/go-libp2p-core/peer"
)

type fakeProviderNetwork struct {
Expand Down
2 changes: 1 addition & 1 deletion session/session.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ import (
blocks "github.com/ipfs/go-block-format"
cid "github.com/ipfs/go-cid"
logging "github.com/ipfs/go-log"
peer "github.com/libp2p/go-libp2p-core/peer"
loggables "github.com/libp2p/go-libp2p-loggables"
peer "github.com/libp2p/go-libp2p-peer"

bssrs "github.com/ipfs/go-bitswap/sessionrequestsplitter"
)
Expand Down
2 changes: 1 addition & 1 deletion session/session_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (
"github.com/ipfs/go-bitswap/testutil"
cid "github.com/ipfs/go-cid"
blocksutil "github.com/ipfs/go-ipfs-blocksutil"
peer "github.com/libp2p/go-libp2p-peer"
peer "github.com/libp2p/go-libp2p-core/peer"
)

type wantReq struct {
Expand Down
2 changes: 1 addition & 1 deletion sessionmanager/sessionmanager.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (

bssession "github.com/ipfs/go-bitswap/session"
exchange "github.com/ipfs/go-ipfs-exchange-interface"
peer "github.com/libp2p/go-libp2p-peer"
peer "github.com/libp2p/go-libp2p-core/peer"
)

// Session is a session that is managed by the session manager
Expand Down
2 changes: 1 addition & 1 deletion sessionmanager/sessionmanager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (

blocks "github.com/ipfs/go-block-format"
cid "github.com/ipfs/go-cid"
peer "github.com/libp2p/go-libp2p-peer"
peer "github.com/libp2p/go-libp2p-core/peer"
)

type fakeSession struct {
Expand Down
2 changes: 1 addition & 1 deletion sessionpeermanager/sessionpeermanager.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"math/rand"

cid "github.com/ipfs/go-cid"
peer "github.com/libp2p/go-libp2p-peer"
peer "github.com/libp2p/go-libp2p-core/peer"
)

const (
Expand Down
2 changes: 1 addition & 1 deletion sessionpeermanager/sessionpeermanager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
"github.com/ipfs/go-bitswap/testutil"

cid "github.com/ipfs/go-cid"
peer "github.com/libp2p/go-libp2p-peer"
peer "github.com/libp2p/go-libp2p-core/peer"
)

type fakePeerProviderFinder struct {
Expand Down
2 changes: 1 addition & 1 deletion sessionrequestsplitter/sessionrequestsplitter.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"context"

"github.com/ipfs/go-cid"
"github.com/libp2p/go-libp2p-peer"
"github.com/libp2p/go-libp2p-core/peer"
)

const (
Expand Down
Loading

0 comments on commit 53761df

Please sign in to comment.