 
 ! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
 
-: cache-message ( message -- message )
-  dup dup rcode>> NAME-ERROR =
-    [
-      [ question-section>> 1st ]
-      [ authority-section>> [ type>> SOA = ] filter random ttl>> ]
-      bi
-      cache-nx
-    ]
-    [
-        {
-          [ answer-section>>     cache-add-rrs ]
-          [ authority-section>>  cache-add-rrs ]
-          [ additional-section>> cache-add-rrs ]
-        }
-      cleave
-    ]
-  if ;
-
-! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
-
-: query->message ( query -- message ) <query-message> ;
-
-! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
-
 : {name-type-class} ( obj -- seq )
   [ name>> >lower ] [ type>> ] [ class>> ] tri {3} ;
 
 : rr=query? ( rr query -- ? ) [ {name-type-class} ] bi@ = ;
 
 : rr-filter ( rrs query -- rrs ) [ rr=query? ] curry filter ;
-
-! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
-
-: message-query ( message -- query ) question-section>> 1st ;
 
 ! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
 


! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

: recursive-query ( query servers -- message )
  dup random                                 ! query servers server
  pick query->message 0 >>rd                 ! query servers server message
  over ask-server                            ! query servers server message

:  name-hits? ( message -- message ? ) dup  name-hits empty? not ;
: cname-hits? ( message -- message ? ) dup cname-hits empty? not ;

! : name->ip/server ( name -- ip-or-f )
!   A IN query boa root-dns-servers recursive-query ! message
!     {
!       { [ name-hits? ]  [ name-hits  random rdata>>          ] }
!       { [ cname-hits? ] [ cname-hits random rdata>> name->ip ] }
!       { [ t           ] [ drop f ] }
!     }
!   cond ;

! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

: name->ip/server ( name -- ip-or-f )
  A IN query boa recursive-query ! message
    {
      { [ name-hits? ]  [ name-hits  random rdata>>          ] }
      { [ cname-hits? ] [ cname-hits random rdata>> name->ip ] }
