   (:require-macros [cbfg.ago :refer [achan-buf ago ago-loop aclose
                                      aput aput-close atake]]))
 
-(defn npr-client-stream-request-msg [actx client token])
-(defn npr-snapshot-beg-msg [stream-request snapshot])
-(defn npr-snapshot-end-msg [stream-request snapshot])
-(defn npr-snapshot-item-msg [stream-request snapshot item])
-(defn npr-rollback-msg [stream-request rollback])
-(defn server-take-snapshot [actx server stream-request prev-snapshot])
-(defn client-rollback [actx client stream-request rollback-msg])
-(defn client-snapshot-beg [actx client stream-request snapshot-beg])
-(defn client-snapshot-end [actx client stream-request snapshot-beg snapshot-end])
-(defn client-snapshot-item [actx client stream-request snapshot-beg snapshot-item])
+(defprotocol NPRMessage
+  "Methods to help form NPR protocol messages"
+  (npr-snapshot-beg-msg [stream-request snapshot])
+  (npr-snapshot-end-msg [stream-request snapshot])
+  (npr-snapshot-item-msg [stream-request snapshot item])
+  (npr-rollback-msg [stream-request rollback]))
+
+(defprotocol NPRSever
+  "Methods than an NPR protocol server must implement"
+  (server-take-snapshot [actx server stream-request prev-snapshot]))
+
+(defprotocol NPRClient
+  "Methods than an NPR protocol client must implement"
+  (client-stream-request-msg [actx client token])
+  (client-rollback [client actx stream-request rollback-msg])
+  (client-snapshot-beg [client actx stream-request snapshot-beg])
+  (client-snapshot-end [client actx stream-request snapshot-beg snapshot-end])
+  (client-snapshot-item [client actx stream-request snapshot-beg snapshot-item]))
 
 (defn make-npr-server-session [actx server stream-request to-client-ch]
   (ago-loop npr-server-session actx

             (= (:status r) :ok) (aput-close npr-client-loop out {:status :ok})
             (and snapshot-beg
                  (= (:status r) :part)
                  (= (:sub-status r) :snapshot-item)) (if-let [err (client-snapshot-item npr-client-loop client
                                                                                         stream-request
                                                                                         snapshot-beg r)]
                                                        (aput-close npr-client-loop out err)

                                                              num-snapshots num-items))
             (and (nil? snapshot-beg)
                  (= (:status :rollback))) (aput-close npr-client-loop out
                                                       (client-rollback client
                                                                        npr-client-loop
                                                                        stream-request r))
             :else (aput-close npr-client-loop out {:status :unexpected-msg}))))

(defn make-npr-client-session [actx client token to-server-ch from-server-ch]
  (let [out (achan-buf actx 1)
        stream-request (client-stream-request-msg client actx token)]
    (ago npr-client-session actx
         (aput npr-client-session to-server-ch stream-request)
         (npr-client-loop npr-client-session client stream-request
