MCPcopy
hub / github.com/safing/portmaster / prepare

Method prepare

service/netquery/module_api.go:36–176  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

34}
35
36func (nq *NetQuery) prepare() error {
37 var err error
38
39 nq.db = database.NewInterface(&database.Options{
40 Local: true,
41 Internal: true,
42 })
43
44 // TODO: Open database in start() phase.
45 nq.Store, err = NewInMemory()
46 if err != nil {
47 return fmt.Errorf("failed to create in-memory database: %w", err)
48 }
49
50 nq.mng, err = NewManager(nq.Store, "netquery/data/", runtime.DefaultRegistry)
51 if err != nil {
52 return fmt.Errorf("failed to create manager: %w", err)
53 }
54
55 nq.feed = make(chan *network.Connection, 1000)
56
57 queryHander := &QueryHandler{
58 Database: nq.Store,
59 IsDevMode: config.Concurrent.GetAsBool(config.CfgDevModeKey, false),
60 }
61
62 batchHander := &BatchQueryHandler{
63 Database: nq.Store,
64 IsDevMode: config.Concurrent.GetAsBool(config.CfgDevModeKey, false),
65 }
66
67 chartHandler := &ActiveChartHandler{
68 Database: nq.Store,
69 }
70
71 bwChartHandler := &BandwidthChartHandler{
72 Database: nq.Store,
73 }
74
75 if err := api.RegisterEndpoint(api.Endpoint{
76 Name: "Query Connections",
77 Description: "Query the in-memory sqlite connection database.",
78 Path: "netquery/query",
79 MimeType: "application/json",
80 Read: api.PermitUser, // Needs read+write as the query is sent using POST data.
81 Write: api.PermitUser, // Needs read+write as the query is sent using POST data.
82 HandlerFunc: servertiming.Middleware(queryHander, nil).ServeHTTP,
83 }); err != nil {
84 return fmt.Errorf("failed to register API endpoint: %w", err)
85 }
86
87 if err := api.RegisterEndpoint(api.Endpoint{
88 Name: "Batch Query Connections",
89 Description: "Batch query the in-memory sqlite connection database.",
90 Path: "netquery/query/batch",
91 MimeType: "application/json",
92 Read: api.PermitUser, // Needs read+write as the query is sent using POST data.
93 Write: api.PermitUser, // Needs read+write as the query is sent using POST data.

Callers 1

NewModuleFunction · 0.45

Calls 11

NewInterfaceFunction · 0.92
RegisterEndpointFunction · 0.92
InfofFunction · 0.92
NewInMemoryFunction · 0.85
NewManagerFunction · 0.85
ErrorfMethod · 0.80
RemoveAllHistoryDataMethod · 0.65
ContextMethod · 0.65
CleanupHistoryMethod · 0.65
GetAsBoolMethod · 0.45

Tested by

no test coverage detected