nits and beauty

This commit is contained in:
vyzo 2019-11-19 02:28:23 +02:00
parent cd7f42e1d7
commit 7065297ac6
1 changed files with 3 additions and 6 deletions

View File

@ -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
}
@ -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