|
28 | 28 | (defclass http3-client ()
|
29 | 29 | ((engine-version :initarg :quic-version :initform (error "You are required to supply a QUIC protocol version string"))
|
30 | 30 | (engine-settings :initform (safe-foreign-alloc '(:struct lsquic-engine-settings)))
|
31 |
| - (engine-api :initform (safe-foreign-alloc '(:struct lsquic-engine-api))))) |
| 31 | + (engine-api :initform (safe-foreign-alloc '(:struct lsquic-engine-api))) |
| 32 | + (engine :accessor engine) |
| 33 | + (host :initarg :host :initform (error "You must supply a host to connect to")) |
| 34 | + (port :initarg :host :initform 443) |
| 35 | + (quic-socket) |
| 36 | + (quic-conn) |
| 37 | + (log-level :initarg :log-level :initform "debug"))) |
32 | 38 |
|
33 | 39 | ;; TODO: the `lsquic-str2ver` doesn't work. It signals an error
|
34 | 40 | ;; because the return value doesn't cast back to what the enum was
|
|
51 | 57 |
|
52 | 58 | (defmacro check-null-p (sym)
|
53 | 59 | `(when (cffi:null-pointer-p ,sym)
|
54 |
| - (error 'library-error :slot-name ,sym))) |
| 60 | + (error 'library-error-null-p :slot-name ,sym))) |
55 | 61 |
|
56 | 62 | (defmethod initialize-instance :after ((client http3-client) &key)
|
57 | 63 | (unless already-lsquic-global-init
|
58 | 64 | (setf already-lsquic-global-init t)
|
59 | 65 | (lsquic-global-init LSQUIC-GLOBAL-CLIENT))
|
60 |
| - (with-slots (engine-settings engine-version engine-api) client |
| 66 | + (with-slots (engine-settings engine-version engine-api log-level) client |
61 | 67 | (check-null-p engine-settings)
|
62 | 68 | (check-null-p engine-api)
|
63 | 69 | (lsquic-engine-init-settings engine-settings LSENG-HTTP)
|
|
70 | 76 | (setf es-versions (logior es-versions (ash 1 (str->quic-version engine-version))))
|
71 | 77 | (when (not (eq 0 (lsquic-engine-check-settings engine-settings LSENG-HTTP errbuf bufsize)))
|
72 | 78 | (error 'invalid-settings))
|
| 79 | + (with-foreign-string (ll log-level) |
| 80 | + (lsquic-set-log-level ll)) |
73 | 81 | (lsquic-logger-init logger-if (weird-pointers:save :nil) (foreign-enum-value 'lsquic-logger-timestamp-style :LLTS-HHMMSSUS))
|
74 | 82 | (with-foreign-slots ((ea-settings ea-packets-out ea-packets-out-ctx ea-stream-if ea-stream-if-ctx) engine-api (:struct lsquic-engine-api))
|
75 | 83 | (setf ea-settings engine-settings)
|
76 | 84 | (setf ea-stream-if client-callbacks)
|
77 | 85 | (setf ea-stream-if-ctx (weird-pointers:save client))
|
78 |
| - ;(setf ea-packets-out (callback cb-packets-out)) |
| 86 | + (setf ea-packets-out (callback cb-packets-out)) |
79 | 87 | (setf ea-packets-out-ctx (weird-pointers:save client)))
|
80 | 88 | (let ((engine (lsquic-engine-new LSENG-HTTP engine-api)))
|
| 89 | + (format t "~A~%" engine) |
81 | 90 | (check-null-p engine)))))))
|
82 | 91 |
|
83 | 92 | (defmethod close-client ((client http3-client))
|
84 | 93 | (with-slots (engine-settings engine-api) client
|
85 | 94 | (foreign-free engine-settings)
|
86 | 95 | (foreign-free engine-api)))
|
| 96 | + |
| 97 | + |
| 98 | +;; lsquic_conn_t * |
| 99 | +;; lsquic_engine_connect (lsquic_engine_t *, enum lsquic_version, |
| 100 | +;; const struct sockaddr *local_sa, |
| 101 | +;; const struct sockaddr *peer_sa, |
| 102 | +;; void *peer_ctx, lsquic_conn_ctx_t *conn_ctx, |
| 103 | +;; const char *hostname, unsigned short base_plpmtu, |
| 104 | +;; const unsigned char *sess_resume, size_t sess_resume_len, |
| 105 | +;; /** Resumption token: optional */ |
| 106 | +;; const unsigned char *token, size_t token_sz); |
| 107 | + |
| 108 | +(defmethod quic-connect ((client http3-client)) |
| 109 | + (with-slots (host port engine quic-socket quic-conn engine-version) client |
| 110 | + (with-pointer-to-int (version (str->quic-version engine-version)) |
| 111 | + (let* ((peer-sa (get-peer-address-for-host host)) |
| 112 | + (socket (create-udp-socket host :port 443)) |
| 113 | + (conn (lsquic-engine-connect engine |
| 114 | + version |
| 115 | + ))) |
| 116 | + (check-null-p engine) |
| 117 | + (setf quic-socket socket) |
| 118 | + (setf quic-conn conn))))) |
| 119 | + |
0 commit comments