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

Commit

Permalink
better variable naming
Browse files Browse the repository at this point in the history
  • Loading branch information
vyzo committed May 7, 2019
1 parent e772f93 commit 9c610be
Showing 1 changed file with 13 additions and 13 deletions.
26 changes: 13 additions & 13 deletions relay.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ var (
HopConnectTimeout = 30 * time.Second
StopHandshakeTimeout = 1 * time.Minute

HopStreamBuffer = 4096
HopStreamLimit = 1 << 19 // 512K hops for 1M goroutines
HopStreamBufferSize = 4096
HopStreamLimit = 1 << 19 // 512K hops for 1M goroutines
)

// Relay is the relay transport and service.
Expand All @@ -52,8 +52,8 @@ type Relay struct {
mx sync.Mutex

// atomic counters
sCount int32
lhCount int32
streamCount int32
liveHopCount int32
}

// RelayOpts are options for configuring the relay transport.
Expand Down Expand Up @@ -117,15 +117,15 @@ func NewRelay(ctx context.Context, h host.Host, upgrader *tptu.Upgrader, opts ..
}

func (r *Relay) addLiveHop(from, to peer.ID) {
atomic.AddInt32(&r.lhCount, 1)
atomic.AddInt32(&r.liveHopCount, 1)
}

func (r *Relay) rmLiveHop(from, to peer.ID) {
atomic.AddInt32(&r.lhCount, -1)
atomic.AddInt32(&r.liveHopCount, -1)
}

func (r *Relay) GetActiveHops() int32 {
return atomic.LoadInt32(&r.lhCount)
return atomic.LoadInt32(&r.liveHopCount)
}

func (r *Relay) DialPeer(ctx context.Context, relay pstore.PeerInfo, dest pstore.PeerInfo) (*Conn, error) {
Expand Down Expand Up @@ -253,11 +253,11 @@ func (r *Relay) handleHopStream(s inet.Stream, msg *pb.CircuitRelay) {
return
}

sCount := atomic.AddInt32(&r.sCount, 1)
lhCount := atomic.LoadInt32(&r.lhCount)
defer atomic.AddInt32(&r.sCount, -1)
streamCount := atomic.AddInt32(&r.streamCount, 1)
liveHopCount := atomic.LoadInt32(&r.liveHopCount)
defer atomic.AddInt32(&r.streamCount, -1)

if (sCount + lhCount) > int32(HopStreamLimit) {
if (streamCount + liveHopCount) > int32(HopStreamLimit) {
log.Warning("hop stream limit exceeded; resetting stream")
s.Reset()
return
Expand Down Expand Up @@ -369,7 +369,7 @@ func (r *Relay) handleHopStream(s inet.Stream, msg *pb.CircuitRelay) {
go func() {
defer r.rmLiveHop(src.ID, dst.ID)

buf := pool.Get(HopStreamBuffer)
buf := pool.Get(HopStreamBufferSize)
defer pool.Put(buf)

count, err := io.CopyBuffer(s, bs, buf)
Expand All @@ -386,7 +386,7 @@ func (r *Relay) handleHopStream(s inet.Stream, msg *pb.CircuitRelay) {
}()

go func() {
buf := pool.Get(HopStreamBuffer)
buf := pool.Get(HopStreamBufferSize)
defer pool.Put(buf)

count, err := io.CopyBuffer(bs, s, buf)
Expand Down

0 comments on commit 9c610be

Please sign in to comment.