summaryrefslogtreecommitdiff
path: root/api/main.go
diff options
context:
space:
mode:
authorsinanmohd <sinan@sinanmohd.com>2024-07-08 06:30:30 +0530
committersinanmohd <sinan@sinanmohd.com>2024-07-08 06:33:45 +0530
commit34ea85ac3ab93e3eb34baf006c6ee0837834b820 (patch)
treeb2f297406f3dde244553160b2012f69f2a848a8c /api/main.go
parentd08ae9402429bfca69d72c7a7d99975aa356539f (diff)
api/filter: initHEADmaster
Diffstat (limited to 'api/main.go')
-rw-r--r--api/main.go11
1 files changed, 7 insertions, 4 deletions
diff --git a/api/main.go b/api/main.go
index ea2d7f9..1a5821a 100644
--- a/api/main.go
+++ b/api/main.go
@@ -6,9 +6,10 @@ import (
"log"
"net"
+ "sinanmohd.com/redq/bpf/filter"
+ "sinanmohd.com/redq/bpf/usage"
"sinanmohd.com/redq/db"
"sinanmohd.com/redq/dns"
- "sinanmohd.com/redq/bpf/usage"
)
const (
@@ -43,7 +44,7 @@ func New() (*Api, error) {
return &a, nil
}
-func (a *Api) Run(u *usage.Usage, d *dns.Dns, queries *db.Queries, ctxDb context.Context) {
+func (a *Api) Run(u *usage.Usage, d *dns.Dns, f *filter.Filter, queries *db.Queries, ctxDb context.Context) {
for {
conn, err := a.sock.Accept()
if err != nil {
@@ -51,11 +52,11 @@ func (a *Api) Run(u *usage.Usage, d *dns.Dns, queries *db.Queries, ctxDb context
continue
}
- go handleConn(conn, u, d, queries, ctxDb)
+ go handleConn(conn, u, d, f, queries, ctxDb)
}
}
-func handleConn(conn net.Conn, u *usage.Usage, d *dns.Dns, queries *db.Queries, ctxDb context.Context) {
+func handleConn(conn net.Conn, u *usage.Usage, d *dns.Dns, f *filter.Filter, queries *db.Queries, ctxDb context.Context) {
defer conn.Close()
var req ApiReq
buf := make([]byte, bufSize)
@@ -79,6 +80,8 @@ func handleConn(conn net.Conn, u *usage.Usage, d *dns.Dns, queries *db.Queries,
handleUsage(conn, u, queries, ctxDb)
case "dns":
handleDns(conn, d, req.Arg, req.Action)
+ case "filter":
+ handleFilter(conn, f, req.Arg, req.Action)
default:
log.Printf("invalid request type: %s", req.Type)
}