本文整理汇总了C++中AdcCommand类的典型用法代码示例。如果您正苦于以下问题:C++ AdcCommand类的具体用法?C++ AdcCommand怎么用?C++ AdcCommand使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了AdcCommand类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: respond
void SearchManager::respond(const AdcCommand& adc, const CID& from) {
// Filter own searches
if(from == ClientManager::getInstance()->getMe()->getCID())
return;
UserPtr p = ClientManager::getInstance()->findUser(from);
if(!p)
return;
SearchResultList results;
ShareManager::getInstance()->search(results, adc.getParameters(), 10);
string token;
adc.getParam("TO", 0, token);
if(results.empty())
return;
for(SearchResultList::const_iterator i = results.begin(); i != results.end(); ++i) {
AdcCommand cmd = (*i)->toRES(AdcCommand::TYPE_UDP);
if(!token.empty())
cmd.addParam("TO", token);
ClientManager::getInstance()->send(cmd, from);
}
}
示例2: switch
/** @todo Handle errors better */
void DownloadManager::on(AdcCommand::STA, UserConnection* aSource, const AdcCommand& cmd) noexcept {
if(cmd.getParameters().size() < 2) {
aSource->disconnect();
return;
}
const string& err = cmd.getParameters()[0];
if(err.length() != 3) {
aSource->disconnect();
return;
}
switch(Util::toInt(err.substr(0, 1))) {
case AdcCommand::SEV_FATAL:
aSource->disconnect();
return;
case AdcCommand::SEV_RECOVERABLE:
switch(Util::toInt(err.substr(1))) {
case AdcCommand::ERROR_FILE_NOT_AVAILABLE:
fileNotAvailable(aSource);
return;
case AdcCommand::ERROR_SLOTS_FULL:
noSlots(aSource);
return;
}
case AdcCommand::SEV_SUCCESS:
// We don't know any messages that would give us these...
dcdebug("Unknown success message %s %s", err.c_str(), cmd.getParam(1).c_str());
return;
}
aSource->disconnect();
}
示例3: if
/*
* Sends request to create connection with me
*/
void ConnectionManager::revConnectToMe(const Node::Ptr& node, const AdcCommand& cmd)
{
// don't allow connection if we didn't proceed a handshake
//if(!node->isOnline())
// return;
// this is valid for active-passive connections only
if(!ClientManager::getInstance()->isActive())
return;
const string& protocol = cmd.getParam(1);
const string& token = cmd.getParam(2);
bool secure;
if(protocol == CLIENT_PROTOCOL)
{
secure = false;
}
else if(protocol == SECURE_CLIENT_PROTOCOL_TEST && CryptoManager::getInstance()->TLSOk())
{
secure = true;
}
else
{
AdcCommand sta(AdcCommand::SEV_FATAL, AdcCommand::ERROR_PROTOCOL_UNSUPPORTED, "Protocol unknown", AdcCommand::TYPE_UDP);
sta.addParam("PR", protocol);
sta.addParam("TO", token);
DHT::getInstance()->send(sta, node->getIdentity().getIp(), static_cast<uint16_t>(Util::toInt(node->getIdentity().getUdpPort())),
node->getUser()->getCID(), node->getUdpKey());
return;
}
connect(node, token, secure);
}
示例4: l
/*
* Stores outgoing request to avoid receiving invalid responses
*/
void Utils::trackOutgoingPacket(const string& ip, const AdcCommand& cmd)
{
Lock l(cs);
uint64_t now = GET_TICK();
switch(cmd.getCommand())
{
// request packets
case AdcCommand::CMD_SCH:
case AdcCommand::CMD_PUB:
case AdcCommand::CMD_INF:
case AdcCommand::CMD_CTM:
case AdcCommand::CMD_GET:
case AdcCommand::CMD_PSR:
OutPacket p = { ip, now, cmd.getCommand() };
sentPackets.push_back(p);
break;
}
// clean up old items
// list is sorted by time, so the first unmatched item can break the loop
while(!sentPackets.empty())
{
uint64_t diff = now - sentPackets.front().time;
if(diff >= TIME_FOR_RESPONSE)
sentPackets.pop_front();
else
break;
}
}
示例5: handlePM
void UserConnection::handlePM(const AdcCommand& c, bool echo) noexcept{
const string& message = c.getParam(0);
OnlineUserPtr peer = nullptr;
OnlineUserPtr me = nullptr;
auto cm = ClientManager::getInstance();
{
RLock l(cm->getCS());
peer = cm->findOnlineUser(user->getCID(), getHubUrl());
//try to use the same hub so nicks match to a hub, not the perfect solution for CCPM, nicks keep changing when hubs go offline.
if(peer && peer->getHubUrl() != hubUrl)
setHubUrl(peer->getHubUrl());
me = cm->findOnlineUser(cm->getMe()->getCID(), getHubUrl());
}
if (!me || !peer){ //ChatMessage cant be formatted without the OnlineUser!
disconnect(true);
return;
}
if (echo) {
std::swap(peer, me);
}
string tmp;
auto msg = make_shared<ChatMessage>(message, peer, me, peer);
if (c.getParam("TS", 1, tmp)) {
msg->setTime(Util::toInt64(tmp));
}
msg->setThirdPerson(c.hasFlag("ME", 1));
fire(UserConnectionListener::PrivateMessage(), this, msg);
}
示例6: dcassert
void ClientManager::sendUDP(AdcCommand& cmd, const OnlineUser& user) {
dcassert(cmd.getType() == AdcCommand::TYPE_UDP);
if(!user.getIdentity().isUdpActive()) {
cmd.setType(AdcCommand::TYPE_DIRECT);
cmd.setTo(user.getIdentity().getSID());
const_cast<Client&>(user.getClient()).send(cmd);
} else {
sendUDP(user.getIdentity().getIp(), user.getIdentity().getUdpPort(), cmd.toString(getMe()->getCID()));
}
}
示例7: switch
/*
* General flooding protection
*/
bool Utils::checkFlood(const string& ip, const AdcCommand& cmd)
{
// ignore empty commands
if(cmd.getParameters().empty())
return false;
// there maximum allowed request packets from one IP per minute
// response packets are allowed only if request has been sent to the IP address
size_t maxAllowedPacketsPerMinute = 0;
uint32_t requestCmd = AdcCommand::CMD_SCH;
switch(cmd.getCommand())
{
// request packets
case AdcCommand::CMD_SCH: maxAllowedPacketsPerMinute = 20; break;
case AdcCommand::CMD_PUB: maxAllowedPacketsPerMinute = 10; break;
case AdcCommand::CMD_INF: maxAllowedPacketsPerMinute = 3; break;
case AdcCommand::CMD_CTM: maxAllowedPacketsPerMinute = 2; break;
case AdcCommand::CMD_RCM: maxAllowedPacketsPerMinute = 2; break;
case AdcCommand::CMD_GET: maxAllowedPacketsPerMinute = 2; break;
case AdcCommand::CMD_PSR: maxAllowedPacketsPerMinute = 3; break;
// response packets
case AdcCommand::CMD_STA:
return true; // STA can be response for more commands, but since it is for informative purposes only, there shouldn't be no way to abuse it
case AdcCommand::CMD_SND: requestCmd = AdcCommand::CMD_GET;
case AdcCommand::CMD_RES: // default value of requestCmd
Lock l(cs);
for(std::list<OutPacket>::iterator i = sentPackets.begin(); i != sentPackets.end(); i++)
{
if(i->cmd == requestCmd && i->ip == ip)
{
sentPackets.erase(i);
return true;
}
}
dcdebug("Received unwanted response from %s. Packet dropped.\n", ip.c_str());
return false;
}
Lock l(cs);
std::unordered_multiset<uint32_t>& packetsPerIp = receivedPackets[ip];
packetsPerIp.insert(cmd.getCommand());
if(packetsPerIp.count(cmd.getCommand()) > maxAllowedPacketsPerMinute)
{
dcdebug("Request flood detected (%d) from %s. Packet dropped.\n", packetsPerIp.count(cmd.getCommand()), ip.c_str());
return false;
}
return true;
}
示例8: handle
void UserConnection::handle(AdcCommand::STA t, const AdcCommand& c) {
if(c.getParameters().size() >= 2) {
const string& code = c.getParam(0);
if(!code.empty() && code[0] - '0' == AdcCommand::SEV_FATAL) {
fire(UserConnectionListener::ProtocolError(), this, c.getParam(1));
return;
}
}
fire(t, this, c);
}
示例9: throw
void ConnectionManager::on(AdcCommand::INF, UserConnection* aSource, const AdcCommand& cmd) throw() {
if(aSource->getState() != UserConnection::STATE_INF) {
// Already got this once, ignore...
aSource->send(AdcCommand(AdcCommand::SEV_FATAL, AdcCommand::ERROR_PROTOCOL_GENERIC, "Expecting INF"));
dcdebug("CM::onINF %p sent INF twice\n", (void*)aSource);
aSource->disconnect();
return;
}
string cid;
if(!cmd.getParam("ID", 0, cid)) {
aSource->send(AdcCommand(AdcCommand::SEV_FATAL, AdcCommand::ERROR_INF_MISSING, "ID missing").addParam("FL", "ID"));
dcdebug("CM::onINF missing ID\n");
aSource->disconnect();
return;
}
aSource->setUser(ClientManager::getInstance()->findUser(CID(cid)));
if(!aSource->getUser()) {
dcdebug("CM::onINF: User not found");
aSource->send(AdcCommand(AdcCommand::SEV_FATAL, AdcCommand::ERROR_GENERIC, "User not found"));
putConnection(aSource);
return;
}
if(aSource->isSet(UserConnection::FLAG_INCOMING)) {
aSource->setFlag(UserConnection::FLAG_DOWNLOAD);
addDownloadConnection(aSource);
} else {
aSource->setFlag(UserConnection::FLAG_UPLOAD);
addUploadConnection(aSource);
}
}
示例10: on
void MessageManager::on(AdcCommand::PMI, UserConnection* uc, const AdcCommand& cmd) noexcept {
if (cmd.hasFlag("QU", 0)) {
RLock l(cs);
auto i = ccpms.find(uc->getUser());
if (i != ccpms.end())
uc->disconnect(true);
}
}
示例11: on
void DownloadManager::on(AdcCommand::SND, UserConnection* aSource, const AdcCommand& cmd) noexcept {
if(aSource->getState() != UserConnection::STATE_SND) {
dcdebug("DM::onFileLength Bad state, ignoring\n");
return;
}
const string& type = cmd.getParam(0);
int64_t start = Util::toInt64(cmd.getParam(2));
int64_t bytes = Util::toInt64(cmd.getParam(3));
if(type != Transfer::names[aSource->getDownload()->getType()]) {
// Uhh??? We didn't ask for this...
aSource->disconnect();
return;
}
startData(aSource, start, bytes, cmd.hasFlag("ZL", 4));
}
示例12: l
void ClientManager::send(AdcCommand& cmd, const CID& cid) {
Lock l(cs);
OnlineIter i = onlineUsers.find(cid);
if(i != onlineUsers.end()) {
OnlineUser& u = *i->second;
if(cmd.getType() == AdcCommand::TYPE_UDP && !u.getIdentity().isUdpActive()) {
cmd.setType(AdcCommand::TYPE_DIRECT);
cmd.setTo(u.getIdentity().getSID());
u.getClient().send(cmd);
} else {
try {
udp.writeTo(u.getIdentity().getIp(), static_cast<uint16_t>(Util::toInt(u.getIdentity().getUdpPort())), cmd.toString(getMe()->getCID()));
} catch(const SocketException&) {
dcdebug("Socket exception sending ADC UDP command\n");
}
}
}
}
示例13: respond
void SearchManager::respond(const AdcCommand& cmd, const OnlineUser& user) {
// Filter own searches
if(user.getUser() == ClientManager::getInstance()->getMe())
return;
auto results = ShareManager::getInstance()->search(cmd.getParameters(), user.getIdentity().isUdpActive() ? 10 : 5);
if(results.empty())
return;
string token;
cmd.getParam("TO", 0, token);
for(auto& i: results) {
AdcCommand res = i->toRES(AdcCommand::TYPE_UDP);
if(!token.empty())
res.addParam("TO", token);
ClientManager::getInstance()->sendUDP(res, user);
}
}
示例14: throw
void UploadManager::on(AdcCommand::GFI, UserConnection* aSource, const AdcCommand& c) throw() {
if(c.getParameters().size() < 2) {
aSource->send(AdcCommand(AdcCommand::SEV_RECOVERABLE, AdcCommand::ERROR_PROTOCOL_GENERIC, "Missing parameters"));
return;
}
const string& type = c.getParam(0);
const string& ident = c.getParam(1);
if(type == Transfer::TYPE_FILE) {
try {
aSource->send(ShareManager::getInstance()->getFileInfo(ident));
} catch(const ShareException&) {
aSource->fileNotAvail();
}
} else {
aSource->fileNotAvail();
}
}
示例15: toPSR
void SearchManager::respond(const AdcCommand& adc, const CID& from, bool isUdpActive, const string& hubIpPort) {
// Filter own searches
if(from == ClientManager::getInstance()->getMe()->getCID())
return;
UserPtr p = ClientManager::getInstance()->findUser(from);
if(!p)
return;
SearchResultList results;
ShareManager::getInstance()->search(results, adc.getParameters(), isUdpActive ? 10 : 5);
string token;
adc.getParam("TO", 0, token);
// TODO: don't send replies to passive users
if(results.empty()) {
string tth;
if(!adc.getParam("TR", 0, tth))
return;
PartsInfo partialInfo;
if(!QueueManager::getInstance()->handlePartialSearch(TTHValue(tth), partialInfo)) {
// if not found, try to find in finished list
if(!FinishedManager::getInstance()->handlePartialRequest(TTHValue(tth), partialInfo)) {
return;
}
}
AdcCommand cmd = toPSR(true, Util::emptyString, hubIpPort, tth, partialInfo);
ClientManager::getInstance()->send(cmd, from);
return;
}
for(SearchResultList::const_iterator i = results.begin(); i != results.end(); ++i) {
AdcCommand cmd = (*i)->toRES(AdcCommand::TYPE_UDP);
if(!token.empty())
cmd.addParam("TO", token);
ClientManager::getInstance()->send(cmd, from);
}
}