sdt.h 2.24 KB
//
//  sdt.h
//
//  Created by cairui01 on 18/11/9.
//  Copyright (c) 2018年 baidu. All rights reserved.
//
#ifndef SDT_INTERFACE_SDT_H_
#define SDT_INTERFACE_SDT_H_

#include <stdlib.h>
#include <stdint.h>
#include <map>
#include <string>
#include <vector>

namespace apirequest {
namespace sdt {

struct CheckResultProfile;

struct CheckIPPort {

	CheckIPPort() {
		Reset();
	}

	CheckIPPort(std::string _ip, uint16_t _port)
	: ip(_ip), port(_port){}

	bool operator < (const CheckIPPort& _rhs) const {
		return ip < _rhs.ip;
	}

	CheckIPPort& operator = (const CheckIPPort& _rhs)  {
		ip = _rhs.ip;
		port = _rhs.port;
		return (*this);
	}

	void Reset() {
		ip.clear();
		port = 0;
	}

	std::string ip;
	uint16_t port;

};
    
typedef std::map< std::string, std::vector<CheckIPPort> > CheckIPPorts;
typedef std::map< std::string, std::vector<CheckIPPort> >::iterator CheckIPPorts_Iterator;

#define DEFAULT_PING_HOST "mbd.baidu.com"
#define DEFAULT_PING_COUNT          (2)        // times

// For DNS
#define DEFAULT_DNS_TIMEOUT         (3*1000)   // 3000ms
// For net check timeout
#define UNUSE_TIMEOUT               (INT_MAX)        // ms

// For Log
#define SDT_LOG                     "### sdt-log:"
#define SDT_ALTER_INTERFACE_LOG     "### sdt-log-bind-interface:"

enum NetCheckStatus {
	kNone = 0,
	kChecking = 1,
	kCheckEnd,
};

enum NetCheckType {
	kPingCheck = 0,
	kDnsCheck = 1,
	kHttpDnsCheck,
    kTracertCheck,
    kTcpCheck
};

enum CheckErrCode {
    kCheckOK = 0,
    kTCPNonErr = 1,
    kSendDnsQueryError = -1,
    kReceiveDnsQueryError = -2,
    kDnsUnknownHostError = -3,
    kDnsError = -4,
    kDnsUDPSocketError = -5,
    kDnsNoDnsServer = -6,
    kPingGetDefaultGatewayError = -7,
    kPingDestHostIsNullError = -8,
    kPingInitICMPError = -9,
    kPingReadWriteError = -10,
    kPingLossRateError = -11,
    kTCPSelectErr    = -12,
    kTCPPipeIntr     = -13,
    kTCPSndRcvErr    = -14,
    kTCPAssertErr    = -15,
    kTCPTimeoutErr   = -16,
    kTCPSelectExpErr = -17,
    kTCPPipeExp      = -18,
    kTCPConnectErr   = -19,
    kTCPRespErr      = -20,
    kBindInterfaceErr = -21
};

enum CheckStatus {
	kCheckContinue = 0,
	kCheckFinish = 1,
} ;

extern void (*ReportNetCheckResult)(const std::vector<CheckResultProfile>& _check_results);

}}
#endif