Skip to content
This repository has been archived by the owner on Sep 9, 2022. It is now read-only.

use io.CopyBuffer with explicitly allocated buffers #69

Merged
merged 4 commits into from
Apr 8, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ module github.com/libp2p/go-libp2p-circuit
require (
github.com/gogo/protobuf v1.2.1
github.com/ipfs/go-log v0.0.1
github.com/libp2p/go-buffer-pool v0.0.1
github.com/libp2p/go-libp2p-blankhost v0.0.1
github.com/libp2p/go-libp2p-host v0.0.1
github.com/libp2p/go-libp2p-net v0.0.1
Expand Down
11 changes: 9 additions & 2 deletions 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