home
/
code
/
tt.git
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
|
inline
| side by side (parent:
6380573
)
Switch to just calling it urL instead of urI
author
Siraaj Khandkar
<siraaj@khandkar.net>
Thu, 2 Dec 2021 02:19:06 +0000
(21:19 -0500)
committer
Siraaj Khandkar
<siraaj@khandkar.net>
Thu, 2 Dec 2021 02:19:06 +0000
(21:19 -0500)
tt.rkt
patch
|
blob
|
blame
|
history
diff --git
a/tt.rkt
b/tt.rkt
index
1cd6fa6
..
cbc5b7a
100644
(file)
--- a/
tt.rkt
+++ b/
tt.rkt
@@
-44,7
+44,7
@@
(Immutable-HashTable Url (Immutable-HashTable (Option String) Hist)))
(struct User
(Immutable-HashTable Url (Immutable-HashTable (Option String) Hist)))
(struct User
- ([ur
i
: Url]
+ ([ur
l
: Url]
[nick : (Option String)]))
(struct User-Agent
[nick : (Option String)]))
(struct User-Agent
@@
-64,8
+64,8
@@
(struct Peer
([nick : (Option String)]
(struct Peer
([nick : (Option String)]
- [ur
i
: Url]
- [ur
i
-str : String]
+ [ur
l
: Url]
+ [ur
l
-str : String]
[comment : (Option String)])
#:transparent)
[comment : (Option String)])
#:transparent)
@@
-139,12
+139,12
@@
(: peers-equal? (-> Peer Peer Boolean))
(define (peers-equal? p1 p2)
(: peers-equal? (-> Peer Peer Boolean))
(define (peers-equal? p1 p2)
- (equal? (Peer-ur
i
-str p1)
- (Peer-ur
i
-str p2)))
+ (equal? (Peer-ur
l
-str p1)
+ (Peer-ur
l
-str p2)))
(: peer-hash (-> Peer Fixnum))
(define (peer-hash p)
(: peer-hash (-> Peer Fixnum))
(define (peer-hash p)
- (equal-hash-code (Peer-ur
i
-str p)))
+ (equal-hash-code (Peer-ur
l
-str p)))
(define-custom-set-types peers
#:elem? Peer?
(define-custom-set-types peers
#:elem? Peer?
@@
-169,7
+169,7
@@
(define groups
(foldl
(λ (p groups)
(define groups
(foldl
(λ (p groups)
- (hash-update groups (Peer-ur
i
-str p) (λ (group) (cons p group)) '()))
+ (hash-update groups (Peer-ur
l
-str p) (λ (group) (cons p group)) '()))
(hash)
(append* peer-sets)))
(define (merge peers)
(hash)
(append* peer-sets)))
(define (merge peers)
@@
-261,11
+261,11
@@
(λ (out-format color-i msg)
(let ([color (vector-ref colors (modulo color-i n))]
[nick (Peer-nick (Msg-from msg))]
(λ (out-format color-i msg)
(let ([color (vector-ref colors (modulo color-i n))]
[nick (Peer-nick (Msg-from msg))]
- [ur
i (Peer-uri
-str (Msg-from msg))]
+ [ur
l (Peer-url
-str (Msg-from msg))]
[text (Msg-text msg)])
(match out-format
['single-line
[text (Msg-text msg)])
(match out-format
['single-line
- (let ([nick (if nick nick ur
i
)])
+ (let ([nick (if nick nick ur
l
)])
(printf "~a \033[1;37m<~a>\033[0m \033[0;~am~a\033[0m~n"
(parameterize
([date-display-format 'iso-8601])
(printf "~a \033[1;37m<~a>\033[0m \033[0;~am~a\033[0m~n"
(parameterize
([date-display-format 'iso-8601])
@@
-278,7
+278,7
@@
([date-display-format 'rfc2822])
(date->string (seconds->date (Msg-ts-epoch msg)) #t))
(Msg-ts-orig msg)
([date-display-format 'rfc2822])
(date->string (seconds->date (Msg-ts-epoch msg)) #t))
(Msg-ts-orig msg)
- nick ur
i
color text))])))))
+ nick ur
l
color text))])))))
(: rfc3339->epoch (-> String (Option Nonnegative-Integer)))
(define rfc3339->epoch
(: rfc3339->epoch (-> String (Option Nonnegative-Integer)))
(define rfc3339->epoch
@@
-334,8
+334,8
@@
(let ([mentions
(filter-map
(λ (m) (match (regexp-match #px"@<([^>]+)>" m)
(let ([mentions
(filter-map
(λ (m) (match (regexp-match #px"@<([^>]+)>" m)
- [(list _wholething nick-ur
i
)
- (str->peer nick-ur
i
)]))
+ [(list _wholething nick-ur
l
)
+ (str->peer nick-ur
l
)]))
(regexp-match* #px"@<[^\\s]+([\\s]+)?[^>]+>" text))])
(Msg ts-epoch ts-orig from text mentions))
(begin
(regexp-match* #px"@<[^\\s]+([\\s]+)?[^>]+>" text))])
(Msg ts-epoch ts-orig from text mentions))
(begin
@@
-355,7
+355,7
@@
(string-append d h m))]
[tzs (list* "" "Z" tzs)])
(for* ([n '("fake-nick")]
(string-append d h m))]
[tzs (list* "" "Z" tzs)])
(for* ([n '("fake-nick")]
- [u '("http://fake-ur
i
")]
+ [u '("http://fake-ur
l
")]
[p (list (Peer n (string->url u) u #f))]
[s '("" ":10")]
[f '("" ".1337")]
[p (list (Peer n (string->url u) u #f))]
[s '("" ":10")]
[f '("" ".1337")]
@@
-376,8
+376,8
@@
[tab " "]
[text "Lorem ipsum"]
[nick "foo"]
[tab " "]
[text "Lorem ipsum"]
[nick "foo"]
- [ur
i
"http://bar/"]
- [peer (Peer nick (string->url ur
i) uri
#f)]
+ [ur
l
"http://bar/"]
+ [peer (Peer nick (string->url ur
l) url
#f)]
[actual (str->msg peer (string-append ts tab text))]
[expected (Msg 1605756129 ts peer text '())])
(check-equal?
[actual (str->msg peer (string-append ts tab text))]
[expected (Msg 1605756129 ts peer text '())])
(check-equal?
@@
-393,13
+393,13
@@
(Peer-nick (Msg-from expected))
"str->msg nick")
(check-equal?
(Peer-nick (Msg-from expected))
"str->msg nick")
(check-equal?
- (Peer-ur
i
(Msg-from actual))
- (Peer-ur
i
(Msg-from expected))
- "str->msg ur
i
")
+ (Peer-ur
l
(Msg-from actual))
+ (Peer-ur
l
(Msg-from expected))
+ "str->msg ur
l
")
(check-equal?
(check-equal?
- (Peer-ur
i
-str (Msg-from actual))
- (Peer-ur
i
-str (Msg-from expected))
- "str->msg ur
i
-str")
+ (Peer-ur
l
-str (Msg-from actual))
+ (Peer-ur
l
-str (Msg-from expected))
+ "str->msg ur
l
-str")
(check-equal?
(Msg-text actual)
(Msg-text expected)
(check-equal?
(Msg-text actual)
(Msg-text expected)
@@
-425,37
+425,37
@@
(define cache-object-dir (build-path cache-dir "objects"))
(: url->cache-file-path-v1 (-> Url Path-String))
(define cache-object-dir (build-path cache-dir "objects"))
(: url->cache-file-path-v1 (-> Url Path-String))
-(define (url->cache-file-path-v1 ur
i
)
+(define (url->cache-file-path-v1 ur
l
)
(define (hash-sha1 str) : (-> String String)
(define in (open-input-string str))
(define digest (sha1 in))
(close-input-port in)
digest)
(define (hash-sha1 str) : (-> String String)
(define in (open-input-string str))
(define digest (sha1 in))
(close-input-port in)
digest)
- (build-path cache-object-dir (hash-sha1 (url->string ur
i
))))
+ (build-path cache-object-dir (hash-sha1 (url->string ur
l
))))
(: url->cache-file-path-v2 (-> Url Path-String))
(: url->cache-file-path-v2 (-> Url Path-String))
-(define (url->cache-file-path-v2 ur
i
)
- (build-path cache-object-dir (uri-encode (url->string ur
i
))))
+(define (url->cache-file-path-v2 ur
l
)
+ (build-path cache-object-dir (uri-encode (url->string ur
l
))))
(define url->cache-object-path
url->cache-file-path-v2)
(define url->cache-object-path
url->cache-file-path-v2)
-(define (url->cache-etag-path ur
i
)
- (build-path cache-dir "etags" (uri-encode (url->string ur
i
))))
+(define (url->cache-etag-path ur
l
)
+ (build-path cache-dir "etags" (uri-encode (url->string ur
l
))))
-(define (url->cache-lmod-path ur
i
)
- (build-path cache-dir "lmods" (uri-encode (url->string ur
i
))))
+(define (url->cache-lmod-path ur
l
)
+ (build-path cache-dir "lmods" (uri-encode (url->string ur
l
))))
-(: ur
i
-read-cached (-> Url (Option String)))
-(define (ur
i-read-cached uri
)
- (define path-v1 (url->cache-file-path-v1 ur
i
))
- (define path-v2 (url->cache-file-path-v2 ur
i
))
+(: ur
l
-read-cached (-> Url (Option String)))
+(define (ur
l-read-cached url
)
+ (define path-v1 (url->cache-file-path-v1 ur
l
))
+ (define path-v2 (url->cache-file-path-v2 ur
l
))
(when (file-exists? path-v1)
(rename-file-or-directory path-v1 path-v2 #t))
(if (file-exists? path-v2)
(file->string path-v2)
(begin
(when (file-exists? path-v1)
(rename-file-or-directory path-v1 path-v2 #t))
(if (file-exists? path-v2)
(file->string path-v2)
(begin
- (log-debug "Cache file not found for UR
I: ~a" (url->string uri
))
+ (log-debug "Cache file not found for UR
L: ~a" (url->string url
))
#f)))
(: str->url (-> String (Option String)))
#f)))
(: str->url (-> String (Option String)))
@@
-487,7
+487,7
@@
comment)
(match (str->url url)
[#f
comment)
(match (str->url url)
[#f
- (log-error "Invalid UR
I
in peer string: ~v" str)
+ (log-error "Invalid UR
L
in peer string: ~v" str)
#f]
[url
(Peer nick url (url->string url) comment)])]
#f]
[url
(Peer nick url (url->string url) comment)])]
@@
-596,15
+596,15
@@
[(list val) val]
[_ #f]))
[(list val) val]
[_ #f]))
-(: ur
i
-download-http-from-port
+(: ur
l
-download-http-from-port
(-> Url (Listof (U Bytes String)) Input-Port
(U 'skipped-cached 'downloaded-new))) ; TODO 'ok|'error ?
(-> Url (Listof (U Bytes String)) Input-Port
(U 'skipped-cached 'downloaded-new))) ; TODO 'ok|'error ?
-(define (ur
i
-download-http-from-port u headers body-input)
+(define (ur
l
-download-http-from-port u headers body-input)
; TODO Update message db from here? or where?
; - 1st try can just be an in-memory set that gets written-to
; and read-from disk as a whole.
(define u-str (url->string u))
; TODO Update message db from here? or where?
; - 1st try can just be an in-memory set that gets written-to
; and read-from disk as a whole.
(define u-str (url->string u))
- (log-debug "ur
i
-download-http-from-port ~v into ~v" u-str cached-object-path)
+ (log-debug "ur
l
-download-http-from-port ~v into ~v" u-str cached-object-path)
(define cached-object-path (url->cache-object-path u))
(define cached-etag-path (url->cache-etag-path u))
(define cached-lmod-path (url->cache-lmod-path u))
(define cached-object-path (url->cache-object-path u))
(define cached-etag-path (url->cache-etag-path u))
(define cached-lmod-path (url->cache-lmod-path u))
@@
-646,8
+646,8
@@
'downloaded-new)
'skipped-cached))
'downloaded-new)
'skipped-cached))
-(: ur
i
-download-http (-> Positive-Float Url Download-Result))
-(define (ur
i
-download-http timeout u)
+(: ur
l
-download-http (-> Positive-Float Url Download-Result))
+(define (ur
l
-download-http timeout u)
(define u-str (url->string u))
(define timeout-chan (make-channel))
(define result-chan (make-channel))
(define u-str (url->string u))
(define timeout-chan (make-channel))
(define result-chan (make-channel))
@@
-680,7
+680,7
@@
; TODO Should a redirect update a peer URL?
(match status
[200
; TODO Should a redirect update a peer URL?
(match status
[200
- `(ok . ,(ur
i
-download-http-from-port u headers body-input))]
+ `(ok . ,(ur
l
-download-http-from-port u headers body-input))]
[_
`(error . (http-not-ok . ,status))])])
(close-input-port body-input)
[_
`(error . (http-not-ok . ,status))])])
(close-input-port body-input)
@@
-691,12
+691,12
@@
(kill-thread timeout-thread)
result)
(kill-thread timeout-thread)
result)
-(: ur
i
-download (-> Positive-Float Url Download-Result))
-(define (ur
i
-download timeout u)
+(: ur
l
-download (-> Positive-Float Url Download-Result))
+(define (ur
l
-download timeout u)
(match (url-scheme u)
; TODO Support Gopher.
[(or "http" "https")
(match (url-scheme u)
; TODO Support Gopher.
[(or "http" "https")
- (ur
i
-download-http timeout u)]
+ (ur
l
-download-http timeout u)]
[scheme
`(error . (unsupported-url-scheme . ,scheme))]))
[scheme
`(error . (unsupported-url-scheme . ,scheme))]))
@@
-716,9
+716,9
@@
(: peer->msgs (-> Peer (Listof Msg)))
(define (peer->msgs peer)
(: peer->msgs (-> Peer (Listof Msg)))
(define (peer->msgs peer)
- (match-define (Peer nick ur
i uri
-str _) peer)
- (log-debug "Reading peer nick:~v ur
i:~v" nick uri
-str)
- (define msgs-data (ur
i-read-cached uri
))
+ (match-define (Peer nick ur
l url
-str _) peer)
+ (log-debug "Reading peer nick:~v ur
l:~v" nick url
-str)
+ (define msgs-data (ur
l-read-cached url
))
; TODO Expire cache
(if msgs-data
(str->msgs peer msgs-data)
; TODO Expire cache
(if msgs-data
(str->msgs peer msgs-data)
@@
-729,10
+729,10
@@
(Result (U 'skipped-cached 'downloaded-new)
Any)))
(define (peer-download timeout peer)
(Result (U 'skipped-cached 'downloaded-new)
Any)))
(define (peer-download timeout peer)
- (match-define (Peer nick ur
i
u _) peer)
+ (match-define (Peer nick ur
l
u _) peer)
(log-info "Download BEGIN URL:~a" u)
(define-values (results _tm-cpu-ms tm-real-ms _tm-gc-ms)
(log-info "Download BEGIN URL:~a" u)
(define-values (results _tm-cpu-ms tm-real-ms _tm-gc-ms)
- (time-apply ur
i-download (list timeout uri
)))
+ (time-apply ur
l-download (list timeout url
)))
(define result (car results))
(log-info "Download END in ~a seconds, URL:~a, result:~s"
(/ tm-real-ms 1000.0)
(define result (car results))
(log-info "Download END in ~a seconds, URL:~a, result:~s"
(/ tm-real-ms 1000.0)
@@
-815,7
+815,7
@@
(set-map denied-hosts (λ (h) (pregexp (string-append "\\." h "$")))))
(filter
(λ (p)
(set-map denied-hosts (λ (h) (pregexp (string-append "\\." h "$")))))
(filter
(λ (p)
- (define host (url-host (Peer-ur
i
p)))
+ (define host (url-host (Peer-ur
l
p)))
(not (or (set-member? denied-hosts host)
(ormap (λ (d) (regexp-match? d host)) denied-domain-patterns))))
peers))
(not (or (set-member? denied-hosts host)
(ormap (λ (d) (regexp-match? d host)) denied-domain-patterns))))
peers))
@@
-937,7
+937,7
@@
(define (peers-update-nick-to-common unh peers)
(map
(λ (p)
(define (peers-update-nick-to-common unh peers)
(map
(λ (p)
- (match (url-nick-hist-common unh (Peer-ur
i
p))
+ (match (url-nick-hist-common unh (Peer-ur
l
p))
[#f p]
[n (struct-copy Peer p [nick n])]))
peers))
[#f p]
[n (struct-copy Peer p [nick n])]))
peers))
This page took
0.046626 seconds
and
4
git commands to generate.