From 78e747186a80198f6754b19e6bccd54e16169fd1 Mon Sep 17 00:00:00 2001 From: Eduardo Cavazos Date: Mon, 13 Oct 2008 23:32:35 -0500 Subject: [PATCH 1/3] *** empty log message *** --- extra/dns/cache/rr/rr.factor | 68 ++++++++++++++++++++++++++++++++++++ 1 file changed, 68 insertions(+) create mode 100644 extra/dns/cache/rr/rr.factor diff --git a/extra/dns/cache/rr/rr.factor b/extra/dns/cache/rr/rr.factor new file mode 100644 index 0000000000..b9c12786e2 --- /dev/null +++ b/extra/dns/cache/rr/rr.factor @@ -0,0 +1,68 @@ + +USING: kernel sequences assocs sets locals combinators + accessors system math math.functions unicode.case prettyprint + combinators.cleave dns ; + +IN: dns.cache.rr + +! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + +TUPLE: time data ; + +: now ( -- seconds ) millis 1000.0 / round >integer ; + +: expired? ( -- ? ) time>> now <= ; + +! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + +: make-cache-key ( obj -- key ) + { [ name>> >lower ] [ type>> unparse ] [ class>> unparse ] } 1arr " " join ; + +! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + +: cache ( -- table ) H{ } ; + +: cache-at ( obj -- ent ) make-cache-key cache at ; +: cache-delete ( obj -- ) make-cache-key cache delete-at ; +: cache-set-at ( ent obj -- ) make-cache-key cache set-at ; + +! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + +:: cache-get ( OBJ -- rrs/f ) + [let | ENT [ OBJ cache-at ] | + { + { [ ENT f = ] [ f ] } + { [ ENT expired? ] [ OBJ cache-delete f ] } + { + [ t ] + [ + [let | NAME [ OBJ name>> ] + TYPE [ OBJ type>> ] + CLASS [ OBJ class>> ] + TTL [ now ENT time>> - ] | + ENT data>> + [| RDATA | T{ rr f NAME TYPE CLASS TTL RDATA } ] + map + ] + ] + } + } + cond + ] ; + +! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + +:: cache-add ( RR -- ) + [let | ENT [ RR cache-at ] + TIME [ RR ttl>> now + ] + RDATA [ RR rdata>> ] | + { + { [ ENT f = ] [ T{ f TIME V{ RDATA } } RR cache-set-at ] } + { [ ENT expired? ] [ RR cache-delete RR cache-add ] } + { [ t ] [ TIME ENT (>>time) RDATA ENT data>> adjoin ] } + } + cond + ] ; + +! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + From fa41397a17235d7488e0db9bbc4f8a2a6a66b2d8 Mon Sep 17 00:00:00 2001 From: Eduardo Cavazos Date: Wed, 15 Oct 2008 04:44:18 -0500 Subject: [PATCH 2/3] Add 'bind-in' vocabulary (the -> operator...) --- extra/bind-in/bind-in.factor | 12 ++++++++++++ extra/dns/cache/nx/nx.factor | 35 +++++++++++++++++++++++++++++++++++ 2 files changed, 47 insertions(+) create mode 100644 extra/bind-in/bind-in.factor create mode 100644 extra/dns/cache/nx/nx.factor diff --git a/extra/bind-in/bind-in.factor b/extra/bind-in/bind-in.factor new file mode 100644 index 0000000000..ab6ff19094 --- /dev/null +++ b/extra/bind-in/bind-in.factor @@ -0,0 +1,12 @@ + +USING: kernel parser lexer locals.private ; + +IN: bind-in + +! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + +: -> + "[" parse-tokens make-locals dup push-locals + \ ] (parse-lambda) + parsed-lambda + \ call parsed ; parsing \ No newline at end of file diff --git a/extra/dns/cache/nx/nx.factor b/extra/dns/cache/nx/nx.factor new file mode 100644 index 0000000000..9904f857ba --- /dev/null +++ b/extra/dns/cache/nx/nx.factor @@ -0,0 +1,35 @@ + +USING: kernel assocs locals combinators + math math.functions system unicode.case ; + +IN: dns.cache.nx + +! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + +: nx-cache ( -- table ) H{ } ; + +: nx-cache-at ( name -- time ) >lower nx-cache at ; +: nx-cache-delete-at ( name -- ) >lower nx-cache delete-at ; +: nx-cache-set-at ( time name -- ) >lower nx-cache set-at ; + +! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + +: now ( -- seconds ) millis 1000.0 / round >integer ; + +:: non-existent-name? ( NAME -- ? ) + [let | TIME [ NAME nx-cache-at ] | + { + { [ TIME f = ] [ f ] } + { [ TIME now <= ] [ NAME nx-cache-delete-at f ] } + { [ t ] [ t ] } + } + cond + ] ; + +! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + +:: cache-non-existent-name ( NAME TTL -- ) + [let | TIME [ TTL now + ] | TIME NAME nx-cache-set-at ] ; + +! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + From 4505ab4944753a70a8fda0f626605580c671b08b Mon Sep 17 00:00:00 2001 From: Eduardo Cavazos Date: Wed, 15 Oct 2008 04:45:01 -0500 Subject: [PATCH 3/3] dns.cache.rr: Separate cache just for the rr objects --- extra/dns/cache/rr/rr.factor | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/extra/dns/cache/rr/rr.factor b/extra/dns/cache/rr/rr.factor index b9c12786e2..f3082b124c 100644 --- a/extra/dns/cache/rr/rr.factor +++ b/extra/dns/cache/rr/rr.factor @@ -62,7 +62,4 @@ TUPLE: time data ; { [ t ] [ TIME ENT (>>time) RDATA ENT data>> adjoin ] } } cond - ] ; - -! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! - + ] ; \ No newline at end of file