Skip to content

Commit

Permalink
feat: update to go-libp2p-core 0.7.0
Browse files Browse the repository at this point in the history
Update for stream interface changes. See
https://github.com/libp2p/go-libp2p-core/releases/tag/v0.7.0 for details.
  • Loading branch information
Stebalien committed Nov 12, 2020
1 parent dfa5d46 commit 31a8833
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 27 deletions.
19 changes: 11 additions & 8 deletions dht_net.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import (
"sync"
"time"

"github.com/libp2p/go-libp2p-core/helpers"
"github.com/libp2p/go-libp2p-core/network"
"github.com/libp2p/go-libp2p-core/peer"
"github.com/libp2p/go-msgio/protoio"
Expand Down Expand Up @@ -64,10 +63,12 @@ func (w *bufferedDelimitedWriter) Flush() error {

// handleNewStream implements the network.StreamHandler
func (dht *IpfsDHT) handleNewStream(s network.Stream) {
defer s.Reset() //nolint
if dht.handleNewMessage(s) {
// Gracefully close the stream for writes.
s.Close()
// If we exited without error, close gracefully.
_ = s.Close()
} else {
// otherwise, send an error.
_ = s.Reset()
}
}

Expand Down Expand Up @@ -392,14 +393,15 @@ func (ms *messageSender) SendMessage(ctx context.Context, pmes *pb.Message) erro
continue
}

var err error
if ms.singleMes > streamReuseTries {
go helpers.FullClose(ms.s)
err = ms.s.Close()
ms.s = nil
} else if retry {
ms.singleMes++
}

return nil
return err
}
}

Expand Down Expand Up @@ -442,14 +444,15 @@ func (ms *messageSender) SendRequest(ctx context.Context, pmes *pb.Message) (*pb
continue
}

var err error
if ms.singleMes > streamReuseTries {
go helpers.FullClose(ms.s)
err = ms.s.Close()
ms.s = nil
} else if retry {
ms.singleMes++
}

return mes, nil
return mes, err
}
}

Expand Down
14 changes: 7 additions & 7 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ go 1.14
require (
github.com/gogo/protobuf v1.3.1
github.com/google/gopacket v1.1.18
github.com/google/uuid v1.1.1
github.com/google/uuid v1.1.2
github.com/hashicorp/go-multierror v1.1.0
github.com/hashicorp/golang-lru v0.5.4
github.com/ipfs/go-cid v0.0.7
Expand All @@ -16,23 +16,23 @@ require (
github.com/ipfs/go-log v1.0.4
github.com/jbenet/goprocess v0.1.4
github.com/libp2p/go-eventbus v0.2.1
github.com/libp2p/go-libp2p v0.11.0
github.com/libp2p/go-libp2p-core v0.6.1
github.com/libp2p/go-libp2p v0.12.0
github.com/libp2p/go-libp2p-core v0.7.0
github.com/libp2p/go-libp2p-kbucket v0.4.7
github.com/libp2p/go-libp2p-peerstore v0.2.6
github.com/libp2p/go-libp2p-record v0.1.3
github.com/libp2p/go-libp2p-routing-helpers v0.2.3
github.com/libp2p/go-libp2p-swarm v0.2.8
github.com/libp2p/go-libp2p-testing v0.2.0
github.com/libp2p/go-libp2p-swarm v0.3.1
github.com/libp2p/go-libp2p-testing v0.3.0
github.com/libp2p/go-msgio v0.0.6
github.com/libp2p/go-netroute v0.1.3
github.com/multiformats/go-base32 v0.0.3
github.com/multiformats/go-multiaddr v0.3.1
github.com/multiformats/go-multibase v0.0.3
github.com/multiformats/go-multihash v0.0.14
github.com/multiformats/go-multistream v0.1.2
github.com/multiformats/go-multistream v0.2.0
github.com/stretchr/testify v1.6.1
github.com/whyrusleeping/go-keyspace v0.0.0-20160322163242-5b898ac5add1
go.opencensus.io v0.22.4
go.uber.org/zap v1.15.0
go.uber.org/zap v1.16.0
)
Loading

0 comments on commit 31a8833

Please sign in to comment.