本文整理汇总了C++中Endpoint::setTime方法的典型用法代码示例。如果您正苦于以下问题:C++ Endpoint::setTime方法的具体用法?C++ Endpoint::setTime怎么用?C++ Endpoint::setTime使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Endpoint
的用法示例。
在下文中一共展示了Endpoint::setTime方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: addEndpoint
bool EndpointPool::addEndpoint(Endpoint endpoint, int64_t penalty)
{
if (!endpoint.isRoutable())
return false;
if (endpoint.getIP() == _localhost.getIP())
return false;
endpoint.setTime(max((int64_t)0, (int64_t)endpoint.getTime() - penalty));
Endpoint found = endpoint;
query("INSERT OR REPLACE INTO Endpoints VALUES (?, ?, ?, ?)", (int64_t)endpoint.getIP(), (int64_t)endpoint.getPort(), (int64_t)endpoint.getTime(), 0);
return true;
}
示例2: handle_read_line
//.........这里部分代码省略.........
// set my IP:
vector<string> words;
split(words, rx, is_any_of(" "));
if (words.size() > 3) {
string str = words[3];
if (str.rfind("@") != string::npos) {
string host = str.substr(str.rfind("@")+1);
// Hybrid IRC used by lfnet always returns IP when you userhost yourself,
// but in case another IRC is ever used this should work.
log_debug("GetIPFromIRC() got userhost %s\n", host.c_str());
Endpoint endpoint(host, 0, true);
if (endpoint.isValid()) {
_endpointPool.setLocal(endpoint);
_my_name = encodeAddress(endpoint);
_notifier(); // this will start the Node...
}
if (_proxy)
// re nick
txstream << "NICK " << _my_name << "\r";
// now join the chat room
if (_channels > 1) {
// randomly join e.g. #bitcoin00-#bitcoin99
int channel_number = GetRandInt(_channels);
stringstream ss;
ss << setfill('0') << setw(2) << channel_number;
txstream << "JOIN #" << _channel << ss.str() << "\r";
txstream << "WHO #" << _channel << ss.str() << "\r";
}
else {
txstream << "JOIN #" << _channel << "00\r";
txstream << "WHO #" << _channel << "00\r";
}
async_write(_socket, _send, boost::bind(&ChatClient::handle_write_request, this, asio::placeholders::error));
break;
}
}
}
}
case in_chat_room: {
if (rx.empty() || rx.size() > 900)
break;
vector<string> words;
split(words, rx, is_any_of(" "));
if (words.size() < 2)
break;
string name;
if (words[0] == "PING") {
string tx = rx;
ostream txstream(&_send);
tx[1] = 'O'; // change line to PONG
tx += '\r';
txstream << tx;
async_write(_socket, _send, boost::bind(&ChatClient::handle_write_request, this, asio::placeholders::error));
break;
}
if (words[1] == "352" && words.size() >= 8) {
// index 7 is limited to 16 characters
// could get full length name at index 10, but would be different from join messages
name = words[7];
log_debug("IRC got who\n");
}
if (words[1] == "JOIN" && words[0].size() > 1) {
// :[email protected] JOIN :#channelname
name = words[0].substr(1);
size_t exclamation_pos = words[0].find("!");
if(exclamation_pos != string::npos)
name = words[0].substr(1, exclamation_pos-1); // the 1, -1 is due to the colon
// if (strchr(pszName, '!'))
// *strchr(pszName, '!') = '\0';
log_debug("IRC got join\n");
}
if (name[0] == 'u') {
Endpoint endpoint;
if (decodeAddress(name, endpoint)) {
endpoint.setTime(GetAdjustedTime());
if (_endpointPool.addEndpoint(endpoint, 51 * 60)) {
log_debug("IRC got new address: %s\n", endpoint.toString().c_str());
_notifier();
}
// nGotIREndpointes++;
}
else {
log_debug("IRC decode failed\n");
}
}
break;
}
default:
break;
}
async_read_until(_socket, _recv, "\r\n", boost::bind(&ChatClient::handle_read_line, this, asio::placeholders::error, asio::placeholders::bytes_transferred));
}