Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
7
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Open sidebar
Jonathan Coetzee
Knot Resolver
Commits
38be925e
Commit
38be925e
authored
Nov 12, 2015
by
Marek Vavruša
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
modules/tinyweb: simplified without channels
parent
965c9bc0
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
23 additions
and
44 deletions
+23
-44
modules/predict/predict.lua
modules/predict/predict.lua
+1
-3
modules/tinyweb/tinyweb.go
modules/tinyweb/tinyweb.go
+22
-41
No files found.
modules/predict/predict.lua
View file @
38be925e
...
...
@@ -113,6 +113,7 @@ local function generate(epoch_now)
end
function
predict
.
process
(
ev
)
if
not
stats
then
error
(
"'stats' module required"
)
end
-- Start a new epoch, or continue sampling
predict
.
ev_sample
=
nil
local
epoch_now
=
current_epoch
()
...
...
@@ -158,9 +159,6 @@ function predict.deinit(module)
end
function
predict
.
config
(
config
)
if
not
stats
then
error
(
"'stats' module required"
)
end
-- Reconfigure
if
type
(
config
)
~=
'table'
then
return
end
if
config
.
window
then
predict
.
window
=
config
.
window
end
...
...
modules/tinyweb/tinyweb.go
View file @
38be925e
...
...
@@ -14,7 +14,6 @@ static inline const knot_layer_api_t *_layer(void)
import
"C"
import
(
"os"
"sync"
"unsafe"
"fmt"
"net"
...
...
@@ -25,12 +24,6 @@ import (
"github.com/abh/geoip"
)
type
Sample
struct
{
qname
string
qtype
int
addr
net
.
IP
secure
bool
}
type
QueryInfo
struct
{
Qname
string
Qtype
string
...
...
@@ -41,10 +34,6 @@ type QueryInfo struct {
// Global context
var
resolver
*
C
.
struct_kr_context
// Synchronisation
var
wg
sync
.
WaitGroup
// Global channel for metrics
var
ch_metrics
chan
Sample
// FIFO of last-seen metrics
var
fifo_metrics
[
10
]
QueryInfo
var
fifo_metrics_i
=
0
...
...
@@ -126,35 +115,30 @@ func serve_stats(w http.ResponseWriter, r *http.Request) {
* Module implementation.
*/
func
process_sample
(
qname
string
,
qtype
int
,
addr
net
.
IP
,
secure
bool
)
{
var
qtype_str
[
16
]
byte
C
.
knot_rrtype_to_string
(
C
.
uint16_t
(
qtype
),
(
*
C
.
char
)(
unsafe
.
Pointer
(
&
qtype_str
[
0
])),
C
.
size_t
(
16
))
// Sample NS country code
var
cc
string
switch
len
(
addr
)
{
case
4
:
if
(
geo_db
!=
nil
)
{
cc
,
_
=
geo_db
.
GetCountry
(
addr
.
String
())
}
case
16
:
if
(
geo_db6
!=
nil
)
{
cc
,
_
=
geo_db6
.
GetCountry_v6
(
addr
.
String
())
}
default
:
return
}
// Count occurences
if
freq
,
exists
:=
geo_freq
[
cc
];
exists
{
geo_freq
[
cc
]
=
freq
+
1
}
else
{
geo_freq
[
cc
]
=
1
}
fifo_metrics
[
fifo_metrics_i
]
=
QueryInfo
{
qname
,
string
(
qtype_str
[
:
]),
addr
.
String
(),
secure
,
cc
}
fifo_metrics_i
=
(
fifo_metrics_i
+
1
)
%
len
(
fifo_metrics
)
}
//export tinyweb_init
func
tinyweb_init
(
module
*
C
.
struct_kr_module
)
int
{
resolver
=
(
*
C
.
struct_kr_context
)(
module
.
data
)
ch_metrics
=
make
(
chan
Sample
,
10
)
geo_freq
=
make
(
map
[
string
]
int
)
// Start sample collector goroutine
wg
.
Add
(
1
)
go
func
()
{
defer
wg
.
Done
()
for
msg
:=
range
ch_metrics
{
var
qtype_str
[
16
]
byte
C
.
knot_rrtype_to_string
(
C
.
uint16_t
(
msg
.
qtype
),
(
*
C
.
char
)(
unsafe
.
Pointer
(
&
qtype_str
[
0
])),
C
.
size_t
(
16
))
// Sample NS country code
var
cc
string
switch
len
(
msg
.
addr
)
{
case
4
:
if
(
geo_db
!=
nil
)
{
cc
,
_
=
geo_db
.
GetCountry
(
msg
.
addr
.
String
())
}
case
16
:
if
(
geo_db6
!=
nil
)
{
cc
,
_
=
geo_db6
.
GetCountry_v6
(
msg
.
addr
.
String
())
}
default
:
continue
}
// Count occurences
if
freq
,
exists
:=
geo_freq
[
cc
];
exists
{
geo_freq
[
cc
]
=
freq
+
1
}
else
{
geo_freq
[
cc
]
=
1
}
fifo_metrics
[
fifo_metrics_i
]
=
QueryInfo
{
msg
.
qname
,
string
(
qtype_str
[
:
]),
msg
.
addr
.
String
(),
msg
.
secure
,
cc
}
fifo_metrics_i
=
(
fifo_metrics_i
+
1
)
%
len
(
fifo_metrics
)
}
}()
return
0
}
...
...
@@ -196,7 +180,6 @@ func tinyweb_config(module *C.struct_kr_module, conf *C.char) int {
http
.
HandleFunc
(
"/d3.js"
,
serve_file
)
http
.
HandleFunc
(
"/"
,
serve_page
)
// @todo Not sure how to cancel this routine yet
// wg.Add(1)
fmt
.
Printf
(
"[tinyweb] listening on %s
\n
"
,
addr
)
go
http
.
ListenAndServe
(
addr
,
nil
)
return
0
...
...
@@ -204,8 +187,6 @@ func tinyweb_config(module *C.struct_kr_module, conf *C.char) int {
//export tinyweb_deinit
func
tinyweb_deinit
(
module
*
C
.
struct_kr_module
)
int
{
close
(
ch_metrics
)
wg
.
Wait
()
return
0
}
...
...
@@ -232,8 +213,8 @@ func consume(ctx *C.knot_layer_t, pkt *C.knot_pkt_t) C.int {
defer
C
.
free
(
unsafe
.
Pointer
(
qname
))
qtype
:=
C
.
knot_pkt_qtype
(
pkt
)
secure
:=
(
bool
)(
C
.
knot_pkt_has_dnssec
(
pkt
))
//
Process
metric
ch_metrics
<-
S
ample
{
C
.
GoString
(
qname
),
(
int
)
(
qtype
),
ip
,
secure
}
//
Sample
metric
process_s
ample
(
C
.
GoString
(
qname
),
int
(
qtype
),
ip
,
secure
)
return
state
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment