Re: [racket-dev] [plt] Push #26558: master branch updated
Can we make it so that IP addresses are immutable? This would require changing make-ip-address to have a call to make-immutable-bytes in each case. On Thu, Apr 4, 2013 at 10:07 AM, as...@racket-lang.org wrote: asumu has updated `master' from 8246d073c0 to 92102a2f07. http://git.racket-lang.org/plt/8246d073c0..92102a2f07 =[ 2 Commits ]== Directory summary: 55.6% collects/net/private/ 44.3% collects/net/ ~~ 4e76ae8 Asumu Takikawa as...@racket-lang.org 2013-04-03 15:05 : | Add an IP address library | | The library currently lives in a private subfolder so | that the interface can still be changed. The idea is to | eventually make it a top-level `net` library once it is | more mature. : A collects/net/private/ip.rkt ~~ 92102a2 Asumu Takikawa as...@racket-lang.org 2013-04-04 11:53 : | Use net/private/ip in net/dns | | This simplifies the code by outsourcing IP | address functionality to net/private/ip. : M collects/net/dns.rkt | 230 +--- =[ Overall Diff ]=== collects/net/dns.rkt --- OLD/collects/net/dns.rkt +++ NEW/collects/net/dns.rkt @@ -2,7 +2,8 @@ ;; DNS query library for Racket -(require racket/bool +(require private/ip.rkt + racket/bool racket/contract racket/format racket/list @@ -14,13 +15,17 @@ (provide (contract-out [dns-get-address - (-* (ip-address-string? string?) + (-* ((or/c ip-address? ip-address-string?) string?) (#:ipv6? any/c) ip-address-string?)] [dns-get-name - (- ip-address-string? ip-address-string? string?)] + (- (or/c ip-address? ip-address-string?) + (or/c ip-address? ip-address-string?) + string?)] [dns-get-mail-exchanger - (- ip-address-string? string? (or/c bytes? string?))] + (- (or/c ip-address? ip-address-string?) + string? + (or/c bytes? string?))] [dns-find-nameserver (- (or/c ip-address-string? #f))])) @@ -29,95 +34,8 @@ ;; UDP retry timeout: (define INIT-TIMEOUT 50) -;; Contract utilities and Data Definitions -;; +;; Data Definitions ;; An LB is a (Listof Bytes) -;; -;; An IPAddressString passes the following predicate -(define (ip-address-string? val) - (and (string? val) - (or (ipv4-string? val) - (ipv6-string? val - -;; String - Boolean -;; Check if the input string represents an IPv4 address -(define (ipv4-string? str) - ;; String - Boolean - ;; check if the given string has leading zeroes - (define (has-leading-zeroes? str) -(and ( (string-length str) 1) - (char=? (string-ref str 0) #\0))) - (define matches -(regexp-match #px^(\\d{1,3})\\.(\\d{1,3})\\.(\\d{1,3})\\.(\\d{1,3})$ - str)) - (and matches - (= (length matches) 5) - ;; check that each octet field is an octet - (andmap byte? (map string-number (cdr matches))) - ;; leading zeroes lead to query errors - (not (ormap has-leading-zeroes? matches - -;; String - Boolean -;; Check if the input string represents an IPv6 address -;; TODO: support dotted quad notation -(define (ipv6-string? str) - (define re-::/: #px^([0-9a-fA-F]{1,4})(::|:)) - (define re-:: #px^()(::)) - (define re-: #px^([0-9a-fA-F]{1,4})(:)) - (define re-end #px^[0-9a-fA-F]{1,4}$) - (or (regexp-match? #px^::$ str) ; special case - (let loop ([octet-pairs '()] ; keep octet-pairs to count - [::? #f] ; seen a :: in the string yet? - [str str]) -;; match digit groups and a separator -(define matches - (if ::? - (regexp-match re-: str) - (or (regexp-match re-:: str) - (regexp-match re-::/: str -(cond [matches - (match-define (list match digits sep) matches) - (define rest (substring str (string-length match))) - ;; we need to make sure there is only one :: at most - (if (or ::? (string=? sep ::)) - (loop (cons digits octet-pairs) #t rest) - (loop (cons digits octet-pairs) #f rest))] - [else - (and ;; if there isn't a ::, we need 7+1 octet-pairs -(implies (not ::?) (= (length octet-pairs) 7)) -;; this is the +1 octet pair -(regexp-match? re-end str))] - -(module+ test - (check-true (ip-address-string? 8.8.8.8)) - (check-true (ip-address-string? 12.81.255.109)) - (check-true (ip-address-string? 192.168.0.1)) - (check-true (ip-address-string?
Re: [racket-dev] [plt] Push #26558: master branch updated
Sorry make-immutable-bytes should be bytes-immutable-bytes. On Thu, Apr 4, 2013 at 10:29 AM, Eric Dobson eric.n.dob...@gmail.com wrote: Can we make it so that IP addresses are immutable? This would require changing make-ip-address to have a call to make-immutable-bytes in each case. On Thu, Apr 4, 2013 at 10:07 AM, as...@racket-lang.org wrote: asumu has updated `master' from 8246d073c0 to 92102a2f07. http://git.racket-lang.org/plt/8246d073c0..92102a2f07 =[ 2 Commits ]== Directory summary: 55.6% collects/net/private/ 44.3% collects/net/ ~~ 4e76ae8 Asumu Takikawa as...@racket-lang.org 2013-04-03 15:05 : | Add an IP address library | | The library currently lives in a private subfolder so | that the interface can still be changed. The idea is to | eventually make it a top-level `net` library once it is | more mature. : A collects/net/private/ip.rkt ~~ 92102a2 Asumu Takikawa as...@racket-lang.org 2013-04-04 11:53 : | Use net/private/ip in net/dns | | This simplifies the code by outsourcing IP | address functionality to net/private/ip. : M collects/net/dns.rkt | 230 +--- =[ Overall Diff ]=== collects/net/dns.rkt --- OLD/collects/net/dns.rkt +++ NEW/collects/net/dns.rkt @@ -2,7 +2,8 @@ ;; DNS query library for Racket -(require racket/bool +(require private/ip.rkt + racket/bool racket/contract racket/format racket/list @@ -14,13 +15,17 @@ (provide (contract-out [dns-get-address - (-* (ip-address-string? string?) + (-* ((or/c ip-address? ip-address-string?) string?) (#:ipv6? any/c) ip-address-string?)] [dns-get-name - (- ip-address-string? ip-address-string? string?)] + (- (or/c ip-address? ip-address-string?) + (or/c ip-address? ip-address-string?) + string?)] [dns-get-mail-exchanger - (- ip-address-string? string? (or/c bytes? string?))] + (- (or/c ip-address? ip-address-string?) + string? + (or/c bytes? string?))] [dns-find-nameserver (- (or/c ip-address-string? #f))])) @@ -29,95 +34,8 @@ ;; UDP retry timeout: (define INIT-TIMEOUT 50) -;; Contract utilities and Data Definitions -;; +;; Data Definitions ;; An LB is a (Listof Bytes) -;; -;; An IPAddressString passes the following predicate -(define (ip-address-string? val) - (and (string? val) - (or (ipv4-string? val) - (ipv6-string? val - -;; String - Boolean -;; Check if the input string represents an IPv4 address -(define (ipv4-string? str) - ;; String - Boolean - ;; check if the given string has leading zeroes - (define (has-leading-zeroes? str) -(and ( (string-length str) 1) - (char=? (string-ref str 0) #\0))) - (define matches -(regexp-match #px^(\\d{1,3})\\.(\\d{1,3})\\.(\\d{1,3})\\.(\\d{1,3})$ - str)) - (and matches - (= (length matches) 5) - ;; check that each octet field is an octet - (andmap byte? (map string-number (cdr matches))) - ;; leading zeroes lead to query errors - (not (ormap has-leading-zeroes? matches - -;; String - Boolean -;; Check if the input string represents an IPv6 address -;; TODO: support dotted quad notation -(define (ipv6-string? str) - (define re-::/: #px^([0-9a-fA-F]{1,4})(::|:)) - (define re-:: #px^()(::)) - (define re-: #px^([0-9a-fA-F]{1,4})(:)) - (define re-end #px^[0-9a-fA-F]{1,4}$) - (or (regexp-match? #px^::$ str) ; special case - (let loop ([octet-pairs '()] ; keep octet-pairs to count - [::? #f] ; seen a :: in the string yet? - [str str]) -;; match digit groups and a separator -(define matches - (if ::? - (regexp-match re-: str) - (or (regexp-match re-:: str) - (regexp-match re-::/: str -(cond [matches - (match-define (list match digits sep) matches) - (define rest (substring str (string-length match))) - ;; we need to make sure there is only one :: at most - (if (or ::? (string=? sep ::)) - (loop (cons digits octet-pairs) #t rest) - (loop (cons digits octet-pairs) #f rest))] - [else - (and ;; if there isn't a ::, we need 7+1 octet-pairs -(implies (not ::?) (= (length octet-pairs) 7)) -;; this is the +1 octet pair -(regexp-match? re-end str))] - -(module+ test - (check-true (ip-address-string? 8.8.8.8)) - (check-true
Re: [racket-dev] [plt] Push #26558: master branch updated
On 2013-04-04 10:29:30 -0700, Eric Dobson wrote: Can we make it so that IP addresses are immutable? This would require changing make-ip-address to have a call to make-immutable-bytes in each case. That's a good suggestion, thanks. Cheers, Asumu _ Racket Developers list: http://lists.racket-lang.org/dev