net_check_logic.h
2.26 KB
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
64
65
66
67
68
69
70
71
72
73
74
75
//
// net_check_logic.h
//
// Created by cairui01 on 18/11/9.
// Copyright (c) 2018年 baidu. All rights reserved.
//
#ifndef SDT_SRC_NET_CHECK_LOGIC_H_
#define SDT_SRC_NET_CHECK_LOGIC_H_
#include <list>
#include <string>
#include "netchecker_profile.h"
namespace apirequest {
namespace sdt {
class NetSource;
class NetCheckLogic {
public:
NetCheckLogic();
~NetCheckLogic();
bool UpdateShortLinkInfo(unsigned int _continue_count, bool isSuccess, int32_t checkCount, long long minCheckTimeSpan, bool isIncrement, std::map<std::string, CheckResultProfile*>& resultMap);
void reset();
// 是否开启DNS Query容错机制
void EnableDnsQueryFailOver(bool dns_query_fail_over) {
enable_dns_query_failover_ = dns_query_fail_over;
}
// 在绑定网卡链路探测时, 指定网卡名称、DNS服务器IP、需要Ping的目标IP
bool BindInterface(const std::string& interface_name,
const std::string& dns_server_ip,
const std::string& ping_ip) {
if (interface_name.empty()) {
return false;
}
interface_name_ = interface_name;
dns_server_ip_ = dns_server_ip;
ping_ip_ = ping_ip;
enable_bind_interface_ = true;
printf("\n%s interface_name: %s, dns_server_ip: %s, ping_ip: %s\n",
SDT_ALTER_INTERFACE_LOG,
interface_name_.c_str(), dns_server_ip_.c_str(), ping_ip_.c_str());
return true;
}
private:
void __StartNetCheck(std::map<std::string, CheckResultProfile*>& resultMap);
bool __ShouldNetCheck(unsigned int _continues_count, bool isSuccess, int32_t checkCount, long long minCheckTimeSpan, bool isIncrement);
const std::string __GetDomainOrIpForPing(const std::string& domain, const CheckResultProfile *dnsProfile);
private:
unsigned long long last_netcheck_time_;
//阶梯递增参数
int increment_steps_;
long long check_time_span_increment_step_; //1min
//斐波那契数列
int fib1_;
int fib2_;
bool enable_dns_query_failover_;
// 绑定网卡探测
bool enable_bind_interface_;
std::string interface_name_;
std::string dns_server_ip_;
std::string ping_ip_;
};
}
}
#endif // SDT_SRC_NET_CHECK_LOGIC_H_