Skip to content

Commit

Permalink
nits and beauty
Browse files Browse the repository at this point in the history
  • Loading branch information
vyzo committed Nov 19, 2019
1 parent cd7f42e commit 7065297
Showing 1 changed file with 3 additions and 6 deletions.
9 changes: 3 additions & 6 deletions tracer.go
Original file line number Diff line number Diff line change
Expand Up @@ -179,9 +179,7 @@ type RemoteTracer struct {
// NewRemoteTracer constructs a RemoteTracer, tracing to the peer identified by pi
func NewRemoteTracer(ctx context.Context, host host.Host, pi peer.AddrInfo) (*RemoteTracer, error) {
tr := &RemoteTracer{ctx: ctx, host: host, peer: pi.ID, basicTracer: basicTracer{ch: make(chan struct{}, 1), lossy: true}}
for _, addr := range pi.Addrs {
host.Peerstore().AddAddr(pi.ID, addr, peerstore.PermanentAddrTTL)
}
host.Peerstore().AddAddrs(pi.ID, pi.Addrs, peerstore.PermanentAddrTTL)
go tr.doWrite()
return tr, nil
}
Expand All @@ -206,12 +204,11 @@ func (t *RemoteTracer) doWrite() {
// deadline for batch accumulation
deadline := time.Now().Add(time.Second)

again:
t.mx.Lock()
if len(t.buf) < MinTraceBatchSize && time.Now().Before(deadline) {
for len(t.buf) < MinTraceBatchSize && time.Now().Before(deadline) {
t.mx.Unlock()
time.Sleep(100 * time.Millisecond)
goto again
t.mx.Lock()
}

tmp := t.buf
Expand Down

0 comments on commit 7065297

Please sign in to comment.