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

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

                                        ;; A: Well...I might need to resend it if it
                                        ;; gets dropped initially.
                                        ::vouch]))
(s/def ::immutable-state (s/keys :req-un [::shared/my-keys
                                          ;; Q: How do these mesh with netty's pipeline model?
                                          ;; For that matter, how much sense does the idea of
                                          ;; spawning a child process here?
                                          ::chan->server
                                          ::chan<-server
                                          ::server-extension]))
(s/def ::state (s/merge ::mutable-state ::immutable-state))

(declare hand-shake initialize-immutable-state initialize-mutable-state)
(defrecord State [chan->child       ;; Q: Where do these live?
                  chan<-child       ;; (they don't really seem to fit here)
                  client-extension-load-time   ; mutable
                  ;; Q: Where does this really belong?
                  extension
                  immutable         ; owns nested pieces
                  mutable           ; Becomes an agent
                  my-keys           ; mutable
                  outgoing-message  ; Q: What is this?
                  ;; Q: Where does this really belong?
                  packet-management
                  recent            ; mutable
                  chan<-server      ; belongs under immutable
                  chan->server      ;  ditto
                  server-extension  ;  ditto
                  server-security   ; mutable
                  shared-secrets    ; mutable (build w/ handshake)
                  vouch             ; mutable
                  ;; Q: Where does this really belong?
                  work-area]
  cpt/Lifecycle
  (start
    [this]
    (let [immutable (initialize-immutable-state this)
          mutable (agent (initialize-mutable-state immutable))]

      ;; Q: Does it make sense to just do the deref here?
      ;; Nothing else matters while we're waiting for this.
      ;; Then again, we could really have bunches of these going
      ;; at once, so blocking a full System is a really bad idea.
      ;; This needs more hammock time.
      ;; After very brief consideration, agents seem almost suited
      ;; for what needs to happen here.
      ;; Except for nonce manipulation. That puts a major wrench in the gears.

      ;; Important note:
      ;; The reference implementation actually loops over several servers
      ;; so we can rapidly pick the first that responds.
      ;; This is one of the selling points over TCP, where a connection
      ;; failure might require 3 minutes to fall back to the backup.
      (throw (ex-info "Start here" {:problem "Who should initiate handshake?"}))
      ;; In a lot of ways, this doesn't make sense as a Component at all.
      ;; Yes, it's definitely mutable boundary state.
      ;; But their lifecycle (sorry for the pun) doesn't match System's start/stop.
      ;; There should probably be a Component that owns a collection of these
      ;; that handles that sort of detail.
      ;; It's almost like I've been through this thought process before.
      (hand-shake (assoc this
                         :packet-management (shared/default-packet-manager)
                         :work-area (shared/default-work-area)))))
  (stop
    [this]
    ;; TODO: At the very least, surely I need to purge shared secrets
    this))

(defn hide-long-arrays
