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

merge upstream #1

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
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
9 changes: 7 additions & 2 deletions lseed.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ import (
)

var (
listenAddr = flag.String("listen", "0.0.0.0:53", "Listen address for incoming requests.")
listenAddrUDP = flag.String("listenUDP", "0.0.0.0:53", "UDP listen address for incoming requests.")
listenAddrTCP = flag.String("listenTCP", "0.0.0.0:53", "TCP listen address for incoming requests.")

bitcoinNodeHost = flag.String("btc-lnd-node", "", "The host:port of the backing btc lnd node")
litecoinNodeHost = flag.String("ltc-lnd-node", "", "The host:port of the backing ltc lnd node")
Expand Down Expand Up @@ -143,6 +144,8 @@ func poller(lnd lnrpc.LightningClient, nview *seed.NetworkView) {

if _, err := nview.AddNode(node); err != nil {
log.Debugf("Unable to add node: %v", err)
} else {
log.Debugf("Adding node: %v", node.Addresses)
}
}
}
Expand All @@ -160,8 +163,10 @@ func configure() {
flag.Parse()
if *debug {
log.SetLevel(log.DebugLevel)
log.Infof("Logging on level Debug")
} else {
log.SetLevel(log.InfoLevel)
log.Infof("Logging on level Info")
}
}

Expand Down Expand Up @@ -245,7 +250,7 @@ func main() {

rootIP := net.ParseIP(*authoritativeIP)
dnsServer := seed.NewDnsServer(
netViewMap, *listenAddr, *rootDomain, rootIP,
netViewMap, *listenAddrUDP, *listenAddrTCP, *rootDomain, rootIP,
)

dnsServer.Serve()
Expand Down
43 changes: 24 additions & 19 deletions seed/dns.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,17 +25,19 @@ import (

type DnsServer struct {
chainViews map[string]*ChainView
listenAddr string
listenAddrUDP string
listenAddrTCP string
rootDomain string
authoritativeIP net.IP
}

func NewDnsServer(chainViews map[string]*ChainView, listenAddr, rootDomain string,
func NewDnsServer(chainViews map[string]*ChainView, listenAddrUDP, listenAddrTCP, rootDomain string,
authoritativeIP net.IP) *DnsServer {

return &DnsServer{
chainViews: chainViews,
listenAddr: listenAddr,
listenAddrUDP: listenAddrUDP,
listenAddrTCP: listenAddrTCP,
rootDomain: rootDomain,
authoritativeIP: authoritativeIP,
}
Expand Down Expand Up @@ -87,6 +89,7 @@ func addAAAAResponse(n Node, name string, responses *[]dns.RR) {
Hdr: header,
AAAA: a.IP.To16(),
}
log.Debugf("Adding AAAA response record: %s", name)
*responses = append(*responses, rr)
}
}
Expand All @@ -96,8 +99,6 @@ func (ds *DnsServer) locateChainView(subdomain string) *ChainView {

subdomain = strings.TrimSpace(subdomain)
segments := strings.SplitAfter(subdomain, ".")
// log.Debug("seg: ", segments)
//log.Debug("seg: ", len(segments))

switch {

Expand Down Expand Up @@ -125,11 +126,8 @@ func (ds *DnsServer) locateChainView(subdomain string) *ChainView {
func (ds *DnsServer) handleAAAAQuery(request *dns.Msg, response *dns.Msg,
subDomain string) {

log.Debugf("Handling AAAA query")
chainView, ok := ds.chainViews[subDomain]
if !ok {
//log.Errorf("no chain view found for %v", subDomain)
return
}

nodes := chainView.NetView.RandomSample(3, 25)
for _, n := range nodes {
Expand All @@ -140,9 +138,10 @@ func (ds *DnsServer) handleAAAAQuery(request *dns.Msg, response *dns.Msg,
func (ds *DnsServer) handleAQuery(request *dns.Msg, response *dns.Msg,
subDomain string) {

log.Debugf("Handling A query")
chainView, ok := ds.chainViews[subDomain]
if !ok {
//log.Errorf("no chain view found for %v", subDomain)
log.Errorf("no chain view found for %v", subDomain)
return
}

Expand All @@ -161,7 +160,8 @@ func (ds *DnsServer) handleAQuery(request *dns.Msg, response *dns.Msg,
func (ds *DnsServer) handleSRVQuery(request *dns.Msg, response *dns.Msg,
subDomain string) {

//log.Debugf("taget subdomain: ", subDomain)
log.Debugf("Handling SRV query")
log.Debugf("taget subdomain: %s", subDomain)

var (
chainView *ChainView
Expand Down Expand Up @@ -332,7 +332,7 @@ func (ds *DnsServer) handleLightningDns(w dns.ResponseWriter, r *dns.Msg) {
req, err := ds.parseRequest(r.Question[0].Name, r.Question[0].Qtype)

if err != nil {
//log.Errorf("error parsing request: %v", err)
log.Errorf("error parsing request: %v", err)
return
}

Expand All @@ -349,6 +349,7 @@ func (ds *DnsServer) handleLightningDns(w dns.ResponseWriter, r *dns.Msg) {
// IP address of the authoritative DNS server for fallback TCP
// purposes.
case strings.HasPrefix(req.subdomain, "soa"):
log.Debugf("Handling SOA request")
soaResp := &dns.A{
Hdr: dns.RR_Header{
Rrtype: dns.TypeA,
Expand Down Expand Up @@ -407,26 +408,30 @@ func (ds *DnsServer) handleLightningDns(w dns.ResponseWriter, r *dns.Msg) {
func (ds *DnsServer) Serve() {
dns.HandleFunc(ds.rootDomain, ds.handleLightningDns)

// We'll launch goroutines to listen on both udp and tcp as some
// clients may fallback to opening a direct connection to the
// authoritative server in the case that their resolves have issues
// with our large-ish responses over udp.
// We'll launch a goroutine to listen on UDP.
go func() {
udpServer := &dns.Server{Addr: ds.listenAddr, Net: "udp"}
udpServer := &dns.Server{Addr: ds.listenAddrUDP, Net: "udp"}
if err := udpServer.ListenAndServe(); err != nil {
panic(fmt.Sprintf("failed to setup the udp "+
"server: %s\n", err.Error()))
}
}()

// TCP is handled separately as some clients may fallback to opening a
// direct connection to the authoritative server in the case that their
// resolves have issues with our large-ish responses over udp.
// To make this paletable for Kubernetes we need to be able to expose
// two different ports for UDP and TCP to support both protocls behind
// a load balancer.
go func() {
tcpServer := &dns.Server{Addr: ds.listenAddr, Net: "tcp"}
tcpServer := &dns.Server{Addr: ds.listenAddrTCP, Net: "tcp"}
if err := tcpServer.ListenAndServe(); err != nil {
panic(fmt.Sprintf("failed to setup the tcp "+
"server: %s\n", err.Error()))
}
}()

quitChan := make(chan os.Signal)
signal.Notify(quitChan, syscall.SIGINT, syscall.SIGTERM)
<-quitChan
}

8 changes: 4 additions & 4 deletions seed/network.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,8 @@ func (nv *NetworkView) RandomSample(query NodeType, count int) []Node {
}
}

fmt.Println("Num reachable nodes: %v", len(nv.reachableNodes))
// fmt.Println("Num reachable nodes: %v", len(nv.reachableNodes))
log.Infof("Num reachable nodes: %v", len(nv.reachableNodes))

return result
}
Expand Down Expand Up @@ -271,15 +272,14 @@ func (nv *NetworkView) reachabilityPruner() {
// addresses are reachable.
case newNode := <-nv.freshNodes:
go func() {
log.Infof("waiting to grab sema")
// log.Infof("waiting to grab sema")
<-searchSema

defer func() {
searchSema <- struct{}{}
log.Infof("sema returned")
// log.Infof("sema returned")
}()

log.Infof("got sema")
extractReachableAddrs(newNode, false)
}()

Expand Down