From 8380d8575ac57c9cc43a3b089c459e2d0961ed73 Mon Sep 17 00:00:00 2001 From: David Anderson Date: Tue, 11 Feb 2020 10:33:36 -0800 Subject: [PATCH] logtail: remove unused code from old sentinel logic. Signed-off-by: David Anderson --- logtail/logtail.go | 44 -------------------------------------------- 1 file changed, 44 deletions(-) diff --git a/logtail/logtail.go b/logtail/logtail.go index 4a132363f..77c6ca023 100644 --- a/logtail/logtail.go +++ b/logtail/logtail.go @@ -8,16 +8,12 @@ package logtail import ( "bytes" "context" - "crypto/rand" "encoding/json" - "errors" "fmt" "io" "io/ioutil" - "math/big" "net/http" "os" - "strconv" "time" "tailscale.com/logtail/backoff" @@ -232,44 +228,6 @@ func (l *logger) drainPending() (res []byte) { return buf.Bytes() } -var clientSentinelPrefix = []byte(`{"logtail":{"client_sentinel":`) - -const ( - noSentinel = 0 - stopSentinel = 1 -) - -// newSentinel creates a client sentinel between 2 and maxint32. -// It does not generate the reserved values: -// 0 is no sentinel -// 1 is stop the logger -func newSentinel() ([]byte, int32) { - val, err := rand.Int(rand.Reader, big.NewInt(1<<31-2)) - if err != nil { - panic(err) - } - v := int32(val.Int64()) + 2 - - buf := new(bytes.Buffer) - fmt.Fprintf(buf, "%s%d}}\n", clientSentinelPrefix, v) - return buf.Bytes(), v -} - -// readSentinel reads a sentinel. -// If it is not a sentinel it reports 0. -func readSentinel(b []byte) int32 { - if !bytes.HasPrefix(b, clientSentinelPrefix) { - return 0 - } - b = bytes.TrimPrefix(b, clientSentinelPrefix) - b = bytes.TrimSuffix(bytes.TrimSpace(b), []byte("}}")) - v, err := strconv.Atoi(string(b)) - if err != nil { - return 0 - } - return int32(v) -} - // This is the goroutine that repeatedly uploads logs in the background. func (l *logger) uploading(ctx context.Context) { defer close(l.shutdownDone) @@ -343,8 +301,6 @@ func (l *logger) Flush() error { return nil } -var errHasLogtail = errors.New("logtail: JSON log message contains reserved 'logtail' property") - func (l *logger) send(jsonBlob []byte) (int, error) { n, err := l.buffer.Write(jsonBlob) select {