From ccc5775f00206035b782a9bcf724df47a0a1e4be Mon Sep 17 00:00:00 2001 From: Tony Garnock-Jones Date: Tue, 17 Jun 2014 17:01:22 -0400 Subject: [PATCH] Use matcher-key-set/single and set-first --- ethernet.rkt | 17 ++++++++--------- ip.rkt | 10 +++++----- 2 files changed, 13 insertions(+), 14 deletions(-) diff --git a/ethernet.rkt b/ethernet.rkt index f036540..c3b6da9 100644 --- a/ethernet.rkt +++ b/ethernet.rkt @@ -122,15 +122,14 @@ (compile-gestalt-projection (ethernet-packet (ethernet-interface interface-name (?!)) ? ? ? ? ?))) (define (gestalt->hwaddr g interface-name) - (define hwaddrs (matcher-key-set (gestalt-project g 0 0 #t (hwaddr-projection interface-name)))) - (match (set->list hwaddrs) - ['() #f] - [(list (list h)) h] - [(and hs (list* (list h) _)) - (log-warning "gestalt->hwaddr: multiple addresses for interface ~a: ~v" - interface-name - hs) - h])) + (define hwaddrs + (matcher-key-set/single (gestalt-project g 0 0 #t (hwaddr-projection interface-name)))) + (case (set-count hwaddrs) + [(0) #f] + [(1) (set-first hwaddrs)] + [else + (log-warning "gestalt->hwaddr: multiple addresses for interface ~a: ~v" interface-name hwaddrs) + (set-first hwaddrs)])) (define (ethernet-packet-pattern interface-name from-wire? ethertype) (ethernet-packet (ethernet-interface interface-name ?) from-wire? ? ? ethertype ?)) diff --git a/ip.rkt b/ip.rkt index e0b923f..bd565a5 100644 --- a/ip.rkt +++ b/ip.rkt @@ -141,13 +141,13 @@ (match e [(routing-update g) (define all-results - (set->list (matcher-key-set (gestalt-project g 0 0 #t arp-result-projection)))) + (matcher-key-set/single (gestalt-project g 0 0 #t arp-result-projection))) (match all-results [#f (error 'ip "Someone has published a wildcard arp result")] - ['() ;; no results yet, keep waiting - #f] - [(list* (list remote-hwaddr) rest) - (unless (null? rest) + [(? set-empty?) #f] ;; no results yet, keep waiting + [_ + (define remote-hwaddr (set-first all-results)) + (unless (= 1 (set-count all-results)) (log-warning "Ambiguous arp result for ~a: ~v" (ip-address->hostname remote-ip) all-results))