Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

go fmt #6

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
78 changes: 39 additions & 39 deletions dns-over-https-proxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@ import (
"os/signal"
"syscall"

"github.com/wrouesnel/go.log"
"github.com/miekg/dns"
"net/http"
"encoding/json"
"fmt"
"github.com/miekg/dns"
"github.com/wrouesnel/go.log"
"net"
"net/http"
)

var (
Expand All @@ -41,30 +41,30 @@ var (

// Rough translation of the Google DNS over HTTP API
type DNSResponseJson struct {
Status int32 `json:"Status,omitempty"`
TC bool `json:"TC,omitempty"`
RD bool `json:"RD,omitempty"`
RA bool `json:"RA,omitempty"`
AD bool `json:"AD,omitempty"`
CD bool `json:"CD,omitempty"`
Question []DNSQuestion `json:"Question,omitempty"`
Answer []DNSRR `json:"Answer,omitempty"`
Authority []DNSRR `json:"Authority,omitempty"`
Additional []DNSRR `json:"Additional,omitempty"`
Edns_client_subnet string `json:"edns_client_subnet,omitempty"`
Comment string `json:"Comment,omitempty"`
Status int32 `json:"Status,omitempty"`
TC bool `json:"TC,omitempty"`
RD bool `json:"RD,omitempty"`
RA bool `json:"RA,omitempty"`
AD bool `json:"AD,omitempty"`
CD bool `json:"CD,omitempty"`
Question []DNSQuestion `json:"Question,omitempty"`
Answer []DNSRR `json:"Answer,omitempty"`
Authority []DNSRR `json:"Authority,omitempty"`
Additional []DNSRR `json:"Additional,omitempty"`
Edns_client_subnet string `json:"edns_client_subnet,omitempty"`
Comment string `json:"Comment,omitempty"`
}

type DNSQuestion struct {
Name string `json:"name,omitempty"`
Type int32 `json:"type,omitempty"`
Name string `json:"name,omitempty"`
Type int32 `json:"type,omitempty"`
}

type DNSRR struct {
Name string `json:"name,omitempty"`
Type int32 `json:"type,omitempty"`
TTL int32 `json:"TTL,omitempty"`
Data string `json:"data,omitempty"`
Name string `json:"name,omitempty"`
Type int32 `json:"type,omitempty"`
TTL int32 `json:"TTL,omitempty"`
Data string `json:"data,omitempty"`
}

// Initialize a new RRGeneric from a DNSRR
Expand All @@ -73,10 +73,10 @@ func NewRR(a DNSRR) dns.RR {

// Build an RR header
rrhdr := dns.RR_Header{
Name: a.Name,
Rrtype: uint16(a.Type),
Class: dns.ClassINET,
Ttl: uint32(a.TTL),
Name: a.Name,
Rrtype: uint16(a.Type),
Class: dns.ClassINET,
Ttl: uint32(a.TTL),
Rdlength: uint16(len(a.Data)),
}

Expand All @@ -93,7 +93,7 @@ func NewRR(a DNSRR) dns.RR {
}
} else {
rr = dns.RR(&dns.RFC3597{
Hdr: rrhdr,
Hdr: rrhdr,
Rdata: a.Data,
})
}
Expand Down Expand Up @@ -250,8 +250,8 @@ func proxy(addr string, w dns.ResponseWriter, req *dns.Msg) {
questions := []dns.Question{}
for idx, c := range dnsResp.Question {
questions = append(questions, dns.Question{
Name: c.Name,
Qtype: uint16(c.Type),
Name: c.Name,
Qtype: uint16(c.Type),
Qclass: req.Question[idx].Qclass,
})
}
Expand All @@ -276,23 +276,23 @@ func proxy(addr string, w dns.ResponseWriter, req *dns.Msg) {

resp := dns.Msg{
MsgHdr: dns.MsgHdr{
Id: req.Id,
Response: (dnsResp.Status == 0),
Opcode: dns.OpcodeQuery,
Authoritative: false,
Truncated: dnsResp.TC,
RecursionDesired: dnsResp.RD,
Id: req.Id,
Response: (dnsResp.Status == 0),
Opcode: dns.OpcodeQuery,
Authoritative: false,
Truncated: dnsResp.TC,
RecursionDesired: dnsResp.RD,
RecursionAvailable: dnsResp.RA,
//Zero: false,
AuthenticatedData: dnsResp.AD,
CheckingDisabled: dnsResp.CD,
Rcode: int(dnsResp.Status),
CheckingDisabled: dnsResp.CD,
Rcode: int(dnsResp.Status),
},
Compress: req.Compress,
Question: questions,
Answer: answers,
Ns: authorities,
Extra: extras,
Answer: answers,
Ns: authorities,
Extra: extras,
}

// Write the response
Expand Down