Skip to content

Commit

Permalink
Merge pull request #69 from libp2p/feat/copy-buffer
Browse files Browse the repository at this point in the history
use io.CopyBuffer with explicitly allocated buffers
  • Loading branch information
vyzo authored Apr 8, 2019
2 parents fd75aee + e0ed4d0 commit 5242e48
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions p2p/protocol/internal/circuitv1-deprecated/relay.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
pb "github.com/libp2p/go-libp2p-circuit/pb"

logging "github.com/ipfs/go-log"
pool "github.com/libp2p/go-buffer-pool"
host "github.com/libp2p/go-libp2p-host"
inet "github.com/libp2p/go-libp2p-net"
peer "github.com/libp2p/go-libp2p-peer"
Expand Down Expand Up @@ -376,7 +377,10 @@ func (r *Relay) handleHopStream(s inet.Stream, msg *pb.CircuitRelay) {
go func() {
defer r.rmLiveHop(src.ID, dst.ID)

count, err := io.Copy(s, bs)
buf := pool.Get(4096)
defer pool.Put(buf)

count, err := io.CopyBuffer(s, bs, buf)
if err != nil {
log.Debugf("relay copy error: %s", err)
// Reset both.
Expand All @@ -390,7 +394,10 @@ func (r *Relay) handleHopStream(s inet.Stream, msg *pb.CircuitRelay) {
}()

go func() {
count, err := io.Copy(bs, s)
buf := pool.Get(4096)
defer pool.Put(buf)

count, err := io.CopyBuffer(bs, s, buf)
if err != nil {
log.Debugf("relay copy error: %s", err)
// Reset both.
Expand Down

0 comments on commit 5242e48

Please sign in to comment.