                                             (assoc m :status :ok)))
                               (recur name ((:update-fn m) state)))
                   (when unknown-fn
-                    (when-let [[state2 res] (unknown-fn state m)]
+                    (when-let [[state2 res] (unknown-fn state-loop state m)]
                       (when (and res (:res-ch m))
                         (aput-close state-loop (:res-ch m) res))
                       (recur name state2))))))


; --------------------------------------------

(defn server-handler [server-state m]
  (case (:op m)
    :authenticate
    (if-let [{:keys [realm user pswd]} m]

          [server-state (assoc (dissoc m :pswd) :status :mismatch)])
        [server-state (assoc (dissoc m :pswd) :status :invalid)])
      [server-state (assoc (dissoc m :pswd) :status :invalid)])
    "realms-list"
    [server-state (assoc m :result (keys (:realms server-state)))]
    nil))

(defn rq-authenticate [actx m]
