Properly process INFO messages from routes.

This commit is contained in:
Derek Collison
2013-10-16 08:44:59 -07:00
parent 3c050273bd
commit bd0bb5d52c
3 changed files with 58 additions and 2 deletions

View File

@@ -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)

View File

@@ -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
}

View File

@@ -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) {