-
-
Notifications
You must be signed in to change notification settings - Fork 6
/
stats.h
63 lines (52 loc) · 2.48 KB
/
stats.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
/*
* Copyright (C) 2016 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#pragma once
#include <stdbool.h>
#include <stdint.h>
#include <sys/socket.h>
#include <time.h>
#include "params.h"
#define RCODE_INTERNAL_ERROR 254
#define RCODE_TIMEOUT 255
struct res_sample {
time_t at; // time in s at which the sample was recorded
uint16_t rtt; // round-trip time in ms
uint8_t rcode; // the DNS rcode or RCODE_XXX defined above
};
// Resolver reachability statistics and run-time parameters.
struct res_stats {
// Stats of the last <sample_count> queries.
res_sample samples[MAXNSSAMPLES];
// The number of samples stored.
uint8_t sample_count;
// The next sample to modify.
uint8_t sample_next;
};
// Aggregates the reachability statistics for the given server based on on the stored samples.
void android_net_res_stats_aggregate(res_stats* stats, int* successes, int* errors, int* timeouts,
int* internal_errors, int* rtt_avg, time_t* last_sample_time);
int android_net_res_stats_get_info_for_net(unsigned netid, int* nscount,
sockaddr_storage servers[MAXNS], int* dcount,
char domains[MAXDNSRCH][MAXDNSRCHPATH],
res_params* params, res_stats stats[MAXNS],
int* wait_for_pending_req_timeout_count);
// Returns an array of bools indicating which servers are considered good
int android_net_res_stats_get_usable_servers(const res_params* params, res_stats stats[],
int nscount, bool valid_servers[]);
// Calculate the round-trip-time from start time t0 and end time t1.
int res_stats_calculate_rtt(const timespec* t1, const timespec* t0);
// Create a sample for calculating server reachability statistics.
void res_stats_set_sample(res_sample* sample, time_t now, int rcode, int rtt);