summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPaul Buetow <paul@buetow.org>2021-09-06 13:48:55 +0300
committerPaul Buetow <paul@buetow.org>2021-09-06 13:48:55 +0300
commitcc89d3fb8be2465af276d7ef03ea2a8affd87b2e (patch)
tree7e14b1784a1e74fdf9a3914c5ab54a18dac8af86
parent2c1c70313bb03cf2b2d7e7afadb07a48ff6bb690 (diff)
Print out client/server update notice even from dtail server 4 to dtail
client 3.
-rw-r--r--TODO.md3
-rw-r--r--internal/clients/handlers/basehandler.go2
-rw-r--r--internal/config/client.go8
-rw-r--r--internal/protocol/protocol.go4
-rw-r--r--internal/server/handlers/serverhandler.go30
5 files changed, 31 insertions, 16 deletions
diff --git a/TODO.md b/TODO.md
index 435d153..2563ae7 100644
--- a/TODO.md
+++ b/TODO.md
@@ -9,7 +9,8 @@ This is a loose list of what to do. Maybe for the next releae or maybe for a lat
[x] Have different color conf sections (by REMOTE, CLIENT, SERVER)
[x] Paint ^CLIENT messages (e.g. use yellow backgrounds here)
[x] Paint ^SERVER messages (e.g. use cyan backgrounds here)
+[ ] Adjust dmap with color schemas
[ ] Fix JSONSchema for the colors
[ ] Implement Benchmark cat-ing a file and compare to prev version.
-[ ] Client 4.x should print a warning when trying to connect to a 3.x server.
+[x] Client 4.x should print a warning when trying to connect to a 3.x server.
[ ] Update docs for color configuration
diff --git a/internal/clients/handlers/basehandler.go b/internal/clients/handlers/basehandler.go
index fe83faa..63ceaac 100644
--- a/internal/clients/handlers/basehandler.go
+++ b/internal/clients/handlers/basehandler.go
@@ -56,7 +56,7 @@ func (h *baseHandler) SendMessage(command string) error {
// Read data from the dtail server via Writer interface.
func (h *baseHandler) Write(p []byte) (n int, err error) {
for _, b := range p {
- if b == protocol.MessageDelimiter {
+ if b == protocol.MessageDelimiter || b == '\n' {
if len(h.receiveBuf) == 0 {
continue
}
diff --git a/internal/config/client.go b/internal/config/client.go
index 837c7d6..8bde7a4 100644
--- a/internal/config/client.go
+++ b/internal/config/client.go
@@ -127,8 +127,8 @@ func newDefaultClientConfig() *ClientConfig {
HostnameBg: color.BgYellow,
HostnameFg: color.FgBlack,
TextAttr: color.AttrNone,
- TextBg: color.BgYellow,
- TextFg: color.FgBlack,
+ TextBg: color.BgBlack,
+ TextFg: color.FgWhite,
},
Server: serverTermColors{
DelimiterAttr: color.AttrDim,
@@ -151,9 +151,9 @@ func newDefaultClientConfig() *ClientConfig {
SeverityFatalAttr: color.AttrBlink,
SeverityFatalBg: color.BgRed,
SeverityFatalFg: color.FgWhite,
- SeverityWarnAttr: color.AttrNone,
+ SeverityWarnAttr: color.AttrBold,
SeverityWarnBg: color.BgBlack,
- SeverityWarnFg: color.FgRed,
+ SeverityWarnFg: color.FgWhite,
},
},
}
diff --git a/internal/protocol/protocol.go b/internal/protocol/protocol.go
index e92ec6a..d3035e4 100644
--- a/internal/protocol/protocol.go
+++ b/internal/protocol/protocol.go
@@ -7,8 +7,6 @@ const (
MessageDelimiter byte = '¬'
// FieldDelimiter delimits aggregation fields.
FieldDelimiter string = "|"
- // Arrow for multiple purposes
- Arrow string = "➔"
// AggregateDelimiter delimits parts of an aggregation message.
- AggregateDelimiter string = Arrow
+ AggregateDelimiter string = "➔"
)
diff --git a/internal/server/handlers/serverhandler.go b/internal/server/handlers/serverhandler.go
index 14fc5d0..14f46a3 100644
--- a/internal/server/handlers/serverhandler.go
+++ b/internal/server/handlers/serverhandler.go
@@ -8,6 +8,7 @@ import (
"fmt"
"io"
"os"
+ "strconv"
"strings"
"sync/atomic"
"time"
@@ -167,9 +168,9 @@ func (h *ServerHandler) handleCommand(commandStr string) {
logger.Debug(h.user, commandStr)
ctx := context.Background()
- args, argc, err := h.handleProtocolVersion(strings.Split(commandStr, " "))
+ args, argc, add, err := h.handleProtocolVersion(strings.Split(commandStr, " "))
if err != nil {
- h.send(h.serverMessages, logger.Error(h.user, err))
+ h.send(h.serverMessages, logger.Error(h.user, err)+add)
return
}
@@ -193,19 +194,34 @@ func (h *ServerHandler) handleCommand(commandStr string) {
h.handleUserCommand(ctx, argc, args)
}
-func (h *ServerHandler) handleProtocolVersion(args []string) ([]string, int, error) {
+func (h *ServerHandler) handleProtocolVersion(args []string) ([]string, int, string, error) {
argc := len(args)
+ var add string
if argc <= 2 || args[0] != "protocol" {
- return args, argc, errors.New("unable to determine protocol version")
+ return args, argc, add, errors.New("unable to determine protocol version")
}
if args[1] != protocol.ProtocolCompat {
- err := fmt.Errorf("server with protocol version '%s' but client with '%s', please update DTail", protocol.ProtocolCompat, args[1])
- return args, argc, err
+ clientCompat, _ := strconv.Atoi(args[1])
+ serverCompat, _ := strconv.Atoi(protocol.ProtocolCompat)
+ if clientCompat <= 3 {
+ // Protocol version 3 or lower expect a newline as message separator
+ // One day (after 2 major versions) this exception may be removed!
+ add = "\n"
+ }
+
+ toUpdate := "client"
+ if clientCompat > serverCompat {
+ toUpdate = "server"
+ }
+
+ err := fmt.Errorf("DTail server protocol version '%s' does not match client protocol version '%s', please update DTail %s!",
+ protocol.ProtocolCompat, args[1], toUpdate)
+ return args, argc, add, err
}
- return args[2:], argc - 2, nil
+ return args[2:], argc - 2, add, nil
}
func (h *ServerHandler) handleBase64(args []string, argc int) ([]string, int, error) {