mirror of
https://github.com/gogrlx/nats-server.git
synced 2026-04-02 03:38:42 -07:00
Properly process INFO messages from routes.
This commit is contained in:
@@ -189,6 +189,11 @@ func (c *client) traceOp(op string, arg []byte) {
|
||||
Trace(logStr(opa), fmt.Sprintf("c: %d", c.cid))
|
||||
}
|
||||
|
||||
func (c *client) processInfo(arg []byte) error {
|
||||
// TODO(dlc) - process INFO
|
||||
return nil
|
||||
}
|
||||
|
||||
func (c *client) processConnect(arg []byte) error {
|
||||
c.traceOp("CONNECT", arg)
|
||||
|
||||
|
||||
@@ -63,6 +63,11 @@ const (
|
||||
OP_MSG
|
||||
OP_MSG_SPC
|
||||
MSG_ARG
|
||||
OP_I
|
||||
OP_IN
|
||||
OP_INF
|
||||
OP_INFO
|
||||
INFO_ARG
|
||||
)
|
||||
|
||||
func (c *client) parse(buf []byte) error {
|
||||
@@ -90,6 +95,8 @@ func (c *client) parse(buf []byte) error {
|
||||
c.state = OP_U
|
||||
case 'M', 'm':
|
||||
c.state = OP_M
|
||||
case 'I', 'i':
|
||||
c.state = OP_I
|
||||
default:
|
||||
goto parseErr
|
||||
}
|
||||
@@ -434,6 +441,45 @@ func (c *client) parse(buf []byte) error {
|
||||
c.argBuf = append(c.argBuf, b)
|
||||
}
|
||||
}
|
||||
case OP_I:
|
||||
switch b {
|
||||
case 'N', 'n':
|
||||
c.state = OP_IN
|
||||
default:
|
||||
goto parseErr
|
||||
}
|
||||
case OP_IN:
|
||||
switch b {
|
||||
case 'F', 'f':
|
||||
c.state = OP_INF
|
||||
default:
|
||||
goto parseErr
|
||||
}
|
||||
case OP_INF:
|
||||
switch b {
|
||||
case 'O', 'o':
|
||||
c.state = OP_INFO
|
||||
default:
|
||||
goto parseErr
|
||||
}
|
||||
case OP_INFO:
|
||||
switch b {
|
||||
case ' ', '\t':
|
||||
continue
|
||||
default:
|
||||
c.state = INFO_ARG
|
||||
c.as = i
|
||||
}
|
||||
case INFO_ARG:
|
||||
switch b {
|
||||
case '\r':
|
||||
c.drop = 1
|
||||
case '\n':
|
||||
if err := c.processInfo(buf[c.as : i-c.drop]); err != nil {
|
||||
return err
|
||||
}
|
||||
c.drop, c.state = 0, OP_START
|
||||
}
|
||||
default:
|
||||
goto parseErr
|
||||
}
|
||||
|
||||
@@ -51,8 +51,8 @@ func TestSendRouteInfoOnConnect(t *testing.T) {
|
||||
s, opts := runRouteServer(t)
|
||||
defer s.Shutdown()
|
||||
rc := createRouteConn(t, opts.ClusterHost, opts.ClusterPort)
|
||||
_, expect := setupRoute(t, rc, opts)
|
||||
buf := expect(infoRe)
|
||||
routeSend, routeExpect := setupRoute(t, rc, opts)
|
||||
buf := routeExpect(infoRe)
|
||||
|
||||
info := server.Info{}
|
||||
if err := json.Unmarshal(buf[4:], &info); err != nil {
|
||||
@@ -66,6 +66,11 @@ func TestSendRouteInfoOnConnect(t *testing.T) {
|
||||
t.Fatalf("Received wrong information for port, expected %d, got %d",
|
||||
info.Port, opts.ClusterPort)
|
||||
}
|
||||
|
||||
// Now send it back and make sure it is processed correctly inbound.
|
||||
routeSend(string(buf))
|
||||
routeSend("PING\r\n")
|
||||
routeExpect(pongRe)
|
||||
}
|
||||
|
||||
func TestSendRouteSubAndUnsub(t *testing.T) {
|
||||
|
||||
Reference in New Issue
Block a user