From e0f32fb48caf9397ac87fdd6c6597d888f9a8a40 Mon Sep 17 00:00:00 2001 From: sinanmohd Date: Sun, 7 Jul 2024 15:20:11 +0530 Subject: api/dns: init --- dns/main.go | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) (limited to 'dns') diff --git a/dns/main.go b/dns/main.go index a9be24e..3daa879 100644 --- a/dns/main.go +++ b/dns/main.go @@ -37,6 +37,7 @@ func (d *Dns) ServeDNS(w dns.ResponseWriter, req *dns.Msg) { resp = new(dns.Msg) resp.SetReply(req) w.WriteMsg(resp) + d.blackList.mutex.RUnlock() return } d.blackList.mutex.RUnlock() @@ -92,3 +93,31 @@ func New(queries *db.Queries, ctxDb context.Context) (*Dns, error) { func (d *Dns) Run() { d.server.ListenAndServe() } + +func (d *Dns) Block(domain string) error { + err := d.queries.EnterDnsBlackList(d.ctxDb, domain) + if err != nil { + log.Printf("adding dns blacklist entry: %s", err) + return err + } + + d.blackList.mutex.Lock() + d.blackList.data[domain] = true + d.blackList.mutex.Unlock() + + return nil +} + +func (d *Dns) Unblock(domain string) error { + err := d.queries.DeleteDnsBlackList(d.ctxDb, domain) + if err != nil { + log.Printf("deleting dns blacklist entry: %s", err) + return err + } + + d.blackList.mutex.Lock() + delete(d.blackList.data, domain) + d.blackList.mutex.Unlock() + + return nil +} -- cgit v1.2.3