hammer2 - spanning tree and messaging work
[dragonfly.git] / sbin / hammer2 / cmd_service.c
index 97753db..848a1e6 100644 (file)
@@ -178,6 +178,8 @@ master_service(void *data)
  *                         AUTHENTICATION                              *
  ************************************************************************
  *
+ * Callback via hammer2_iocom_core().
+ *
  * Additional messaging-based authentication must occur before normal
  * message operation.  The connection has already been encrypted at
  * this point.
@@ -200,30 +202,58 @@ master_auth_tx(hammer2_iocom_t *iocom __unused)
        iocom->sendmsg_callback = master_link_tx;
 }
 
-/*
- * Callback from hammer2_iocom_core() when messages might be present
- * on the socket.
+/************************************************************************
+ *                     POST-AUTHENTICATION SERVICE MSGS                *
+ ************************************************************************
+ *
+ * Callback via hammer2_iocom_core().
  */
 static
 void
 master_link_rx(hammer2_iocom_t *iocom)
 {
        hammer2_msg_t *msg;
+       hammer2_state_t *state;
+       uint32_t cmd;
 
        while ((iocom->flags & HAMMER2_IOCOMF_EOF) == 0 &&
               (msg = hammer2_ioq_read(iocom)) != NULL) {
-               fprintf(stderr, "MSG RECEIVED: %08x error %d\n",
-                       msg->any.head.cmd, msg->any.head.error);
-               switch(msg->any.head.cmd & HAMMER2_MSGF_CMDSWMASK) {
-               case HAMMER2_LNK_ERROR:
-                       break;
-               case HAMMER2_DBG_SHELL:
-               case HAMMER2_DBG_SHELL | HAMMER2_MSGF_REPLY:
-                       hammer2_shell_remote(iocom, msg);
-                       break;
-               default:
-                       hammer2_msg_reply(iocom, msg, HAMMER2_MSG_ERR_UNKNOWN);
-                       break;
+               /*
+                * If the message state has a function established we just
+                * call the function, otherwise we call the appropriate
+                * link-level protocol related to the original command and
+                * let it sort it out.
+                *
+                * Non-transactional one-off messages, on the otherhand,
+                * might have REPLY set.
+                */
+               state = msg->state;
+               if (state) {
+                       cmd = state->msg->any.head.cmd;
+                       fprintf(stderr,
+                               "MSGRX persist=%08x cmd=%08x error %d\n",
+                               cmd, msg->any.head.cmd, msg->any.head.error);
+               } else {
+                       cmd = msg->any.head.cmd;
+                       fprintf(stderr,
+                               "MSGRX persist=-------- cmd=%08x error %d\n",
+                               cmd, msg->any.head.error);
+               }
+               if (state && state->func) {
+                       state->func(state, msg);
+               } else {
+                       switch(cmd & HAMMER2_MSGF_PROTOS) {
+                       case HAMMER2_MSG_PROTO_LNK:
+                               hammer2_msg_lnk(iocom, msg);
+                               break;
+                       case HAMMER2_MSG_PROTO_DBG:
+                               hammer2_msg_dbg(iocom, msg);
+                               break;
+                       default:
+                               hammer2_msg_reply(iocom, msg,
+                                                 HAMMER2_MSG_ERR_UNKNOWN);
+                               break;
+                       }
                }
                hammer2_state_cleanuprx(iocom, msg);
        }
@@ -242,5 +272,5 @@ static
 void
 master_link_tx(hammer2_iocom_t *iocom)
 {
-       hammer2_iocom_flush(iocom);
+       hammer2_iocom_flush1(iocom);
 }