                    (+ 544 (count legal-to-send)))
                 true))
         :ret (s/keys :opt [::specs/byte-buf]
-                     :req [::log2/state]))
+                     :req [::log/state]))
 (defn build-initiate-packet!
   "Combine message buffer and client state into an Initiate packet
 
 This was destructive in the sense that it overwrites ::shared/work-area
 FIXME: Change that"
   [this msg-bytes]
-  (let [{log-state ::log2/state
+  (let [{log-state ::log/state
          msg ::message/possible-response} (message/filter-initial-message-bytes this
                                                                                 msg-bytes)]
     (if msg

    (send wrapper (fn [_]
                    (throw (ex-info "Should have a valid cookie response packet, but do not"
                                    @wrapper)))))
  (let [{log-state ::log2/state
         logger ::log2/logger
         :as state} @wrapper
        log-state (log2/info log-state
                             ::build-and-send-vouch
                             ""
                             {::cause "Received cookie"
                              ::effect "Forking child"
                              ::state/state (dissoc state ::log2/state)})
        ;; Once we've signaled the child to start doing its own thing,
        ;; cope with the cookie we just received.
        ;; Doing this statefully seems like a terrible
        ;; idea, but I don't want to go back and rewrite it
        ;; until I have a working prototype.
        log-state (log2/info log-state
                             ::build-and-send-vouch
                             "Converting cookie->vouch")]
    (let [state (state/cookie->vouch state cookie-packet)
          timeout (state/current-timeout wrapper)]
      ;; Give the other thread(s) a chance to catch up and return
      ;; from fork!
      (when-not (await-for timeout wrapper)
        (let [log-updates [#(log2/error %
                                        ::build-and-send-vouch
                                        (str "Converting cookie to vouch took longer than "
                                             timeout
                                             " milliseconds."))]
              log-updates (if-let [ex (agent-error wrapper)]
                            (let [log-state (reduce (fn [current log-fn]
                                                      (log-fn current))
                                                    log-state
                                                    log-updates)]
                              (log2/flush-logs! logger
                                                (log2/exception log-state
                                                                ex
                                                                ::build-and-send-vouch
                                                                "Agent failed while we were waiting"))
                              ;; It's very tempting to make this just kill the client.
                              ;; Then again, for all intents and purposes it's already
                              ;; dead.
                              ;; TODO: we do need to signal the message loop to exit
                              (assert (not ex) (str "Should probably be fatal for the sake of debugging:\n"
                                                    (log2/exception-details ex))))
                            (let [log-update
                                  #(log2/warn %
                                              ::build-and-send-vouch
                                              "Switching agent into an error state")]
                              (send wrapper
                                    #(throw (ex-info "cookie->vouch timed out" %)))
                              (conj log-updates log-update)))]
          (send wrapper (fn [{log-state ::log2/state
                              logger ::log2/logger
                              :as this}]
                          ;; This is pretty obnoxious.
                          ;; I want to apply the functions that

            [frereth-cp.shared.bit-twiddling :as b-t]
            [frereth-cp.shared.constants :as K]
            [frereth-cp.shared.crypto :as crypto]
            [frereth-cp.shared.logging :as log]
            [frereth-cp.shared.serialization :as serial]
            [frereth-cp.shared.specs :as specs]
            [frereth-cp.util :as utils])
