 USING: kernel
        combinators
        vectors
+       sequences
        io.sockets
        accessors
+       combinators.lib
        newfx
-       dns dns.cache ;
+       dns dns.cache dns.misc ;
 
 IN: dns.forwarding
 


: socket ( -- socket ) (socket) 1st ;

: init-socket ( -- ) f 5353 <inet4> <datagram> 0 (socket) as-mutate ;

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



: set-upstream-server ( ip -- ) 0 (upstream-server) as-mutate ;

: init-upstream-server ( -- )
  upstream-server not
    [ resolv-conf-server set-upstream-server ]
  when ;

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

: 1&& <-&& ;

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

: rrs? ( obj -- ? ) { [ NX = not ] [ f = not ] } 1&& ;

: query->answer/cache ( query -- rrs/NX/f )
  dup cache-get* dup { [ rrs? ] [ NX = ] } 1||
    [ nip ]
    [
      drop
      dup clone CNAME >>type cache-get* dup { [ NX = ] [ f = ] } 1||
        [ nip ]
        [                                       ! query rrs
          tuck                                  ! rrs query rrs
          1st                                   ! rrs query rr/cname
          rdata>>                               ! rrs query name
          >r clone r> >>name                    ! rrs query
          query->answer/cache                   ! rrs rrs/NX/f
          dup rrs? [ append ] [ nip ] if
        ]
      if
    ]
  if ;

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

