diff options
| -rw-r--r-- | TODO.md | 3 | ||||
| -rw-r--r-- | internal/clients/handlers/basehandler.go | 2 | ||||
| -rw-r--r-- | internal/config/client.go | 8 | ||||
| -rw-r--r-- | internal/protocol/protocol.go | 4 | ||||
| -rw-r--r-- | internal/server/handlers/serverhandler.go | 30 |
5 files changed, 31 insertions, 16 deletions
@@ -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) { |
