mirror of
https://github.com/tailscale/tailscale.git
synced 2025-04-16 11:41:39 +00:00
wgengine/magicsock: drop a bytes.Buffer sync.Pool, use logger.ArgWriter instead
This commit is contained in:
parent
becce82246
commit
9e5d79e2f1
@ -7,7 +7,7 @@
|
|||||||
package magicsock
|
package magicsock
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bufio"
|
||||||
"context"
|
"context"
|
||||||
"encoding/binary"
|
"encoding/binary"
|
||||||
"errors"
|
"errors"
|
||||||
@ -1362,37 +1362,29 @@ func (c *Conn) closeDerpLocked(node int, why string) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var bufPool = sync.Pool{New: func() interface{} { return new(bytes.Buffer) }}
|
|
||||||
|
|
||||||
// c.mu must be held.
|
// c.mu must be held.
|
||||||
func (c *Conn) logActiveDerpLocked() {
|
func (c *Conn) logActiveDerpLocked() {
|
||||||
buf := bufPool.Get().(*bytes.Buffer)
|
|
||||||
defer bufPool.Put(buf)
|
|
||||||
now := time.Now()
|
now := time.Now()
|
||||||
buf.Reset()
|
c.logf("magicsock: %v active derp conns%s", len(c.activeDerp), logger.ArgWriter(func(buf *bufio.Writer) {
|
||||||
|
if len(c.activeDerp) == 0 {
|
||||||
|
return
|
||||||
|
}
|
||||||
buf.WriteString(":")
|
buf.WriteString(":")
|
||||||
c.foreachActiveDerpSortedLocked(func(node int, ad activeDerp) {
|
c.foreachActiveDerpSortedLocked(func(node int, ad activeDerp) {
|
||||||
fmt.Fprintf(buf, " derp-%d=cr%v,wr%v", node, simpleDur(now.Sub(ad.createTime)), simpleDur(now.Sub(*ad.lastWrite)))
|
fmt.Fprintf(buf, " derp-%d=cr%v,wr%v", node, simpleDur(now.Sub(ad.createTime)), simpleDur(now.Sub(*ad.lastWrite)))
|
||||||
})
|
})
|
||||||
var details []byte
|
}))
|
||||||
if buf.Len() > len(": ") {
|
|
||||||
details = bytes.TrimSpace(buf.Bytes())
|
|
||||||
}
|
|
||||||
c.logf("magicsock: %v active derp conns%s", len(c.activeDerp), details)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Conn) logEndpointChange(endpoints []string, reasons map[string]string) {
|
func (c *Conn) logEndpointChange(endpoints []string, reasons map[string]string) {
|
||||||
buf := bufPool.Get().(*bytes.Buffer)
|
c.logf("magicsock: endpoints changed: %s", logger.ArgWriter(func(buf *bufio.Writer) {
|
||||||
defer bufPool.Put(buf)
|
|
||||||
buf.Reset()
|
|
||||||
buf.WriteString("magicsock: endpoints changed: ")
|
|
||||||
for i, ep := range endpoints {
|
for i, ep := range endpoints {
|
||||||
if i > 0 {
|
if i > 0 {
|
||||||
buf.WriteString(", ")
|
buf.WriteString(", ")
|
||||||
}
|
}
|
||||||
fmt.Fprintf(buf, "%s (%s)", ep, reasons[ep])
|
fmt.Fprintf(buf, "%s (%s)", ep, reasons[ep])
|
||||||
}
|
}
|
||||||
c.logf("%s", buf.Bytes())
|
}))
|
||||||
}
|
}
|
||||||
|
|
||||||
// c.mu must be held.
|
// c.mu must be held.
|
||||||
|
Loading…
x
Reference in New Issue
Block a user