                           buffer)]
     (assoc this :outgoing-message (:child-msg extracted))))
 
+(defn initialize-immutable-state
+  [{:keys [:my-keys]
+    :as this}]
+  (let [long-pair (shared/do-load-keypair (::keydir my-keys))
+        short-pair (shared/random-key-pair)]
+    (assoc this :my-keys (assoc my-keys
+                                ::long-pair long-pair
+                                ::short-pair short-pair))))
+
+(defn initialize-mutable-state
+  [{:keys [:my-keys
+           :server-security
+           :shared-secrets]}]
+  {:pre [(::server-long-term-pk server-security)]}
+  (let [server-long-term-pk (::server-long-term-pk server-security)
+        long-pair (::long-pair my-keys)
+        short-pair (::short-pair my-keys)]
+    {::client-extension-load-time 0
+     ::recent (System/nanoTime)
+     ;; This seems like something that we should be able to set here.
+     ;; djb's docs say that it's a security matter, like connecting from a
+     ;; random port.
+     ;; Hopefully, someday, operating systems will have some mechanism for
+     ;; rotating these automatically
+     ;; Q: Is this really better than just picking something random here?
+     ;; A: Who am I to argue with an expert?
+     ::server-security server-security
+     ::shared/extension nil
+     ::shared-secrets (assoc shared-secrets
+                             ::client-long<->server-long (shared/crypto-box-prepare
+                                                          server-long-term-pk
+                                                          (.getSecretKey short-pair))
+                             ::client-short<->server-long (shared/crypto-box-prepare
+                                                           server-long-term-pk
+                                                           (.getSecretKey long-pair)))}))
+
 (defn hand-shake
   "This really needs to be some sort of stateful component.
   It almost definitely needs to interact with ByteBuf to

                                        ::outgoing-message
                                        ::shared/packet-management
                                        ::shared/recent
                                        ::server-extension
                                        ::server-security
                                        ::shared-secrets
                                        ::shared/work-area]

            [gloss.io :as gloss]
            [manifold.deferred :as deferred]
            [manifold.stream :as stream]))

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;; Specs

(def cookie (gloss-core/compile-frame (gloss-core/ordered-map :s' (gloss-core/finite-block 32)
                                                              :black-box (gloss-core/finite-block 96))))
