本文整理汇总了C++中Packet::Count方法的典型用法代码示例。如果您正苦于以下问题:C++ Packet::Count方法的具体用法?C++ Packet::Count怎么用?C++ Packet::Count使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Packet
的用法示例。
在下文中一共展示了Packet::Count方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: LogError
bool
Connection::JoinParent()
{
if (!Connect())
{
LogError(wxString().Format(wxT(" Handshake failed in con id %d"),id_));
KillSocket(-1);
return FALSE;
}
/*
Tell our parent hello and it has just born a new child.
*/
Packet packet = GenPacket_HelloNext();
if (!Send(packet))
{
LogError(wxString().Format(wxT(" Send failed in con id %d when trying to say hello to parent"),id_));
KillSocket(-1);
return FALSE;
}
/*
Receive all the hashes we are responsible for.
*/
Packet* rcv;
if (!Receive(rcv) || rcv == 0)
{
LogError(wxString().Format(wxT(" Receive failed when getting responsible hashes from parent on con id %d"), id_));
KillSocket(-1);
return FALSE;
}
KillSocket(-1);
// add all the hashes we are responsible for to our hash table
for (int x = 0; x < rcv->Count(Packet::HEADER_HASH);x++)
{
wxString hash = rcv->Get(Packet::HEADER_HASH,x);
wxString node = rcv->Get(Packet::HEADER_NODE,x);
wxString info = rcv->Get(Packet::HEADER_INFO,x);
Network::Instance()->hashTable->Add(HashValue(node,hash,info));
}
delete rcv;
return TRUE;
}
示例2: answer
LookupResponse
Connection::DirectQuery(wxString key)
{
LookupResponse answer(LookupResponse::FAIL);
if (!Connect())
{
LogError(wxString().Format(wxT("Connect() failed when doing a direct query in con id %d"),id_));
KillSocket(-1);
return answer;
}
/*
Send QUERY.
*/
Packet snd = GenPacket_Query(key);
if (!Send(snd))
{
LogError(wxString().Format(wxT("Send failed when trying to direct query on con id %d"),id_));
KillSocket(-1);
return answer;
}
/*
Receive some sort of query response.
*/
Packet* rcv;
if (!Receive(rcv) || rcv == 0)
{
LogError(wxString().Format(wxT("Receive failed when trying to direct query on con id %d"), id_));
KillSocket(-1);
return answer;
}
KillSocket(-1);
switch(rcv->Type())
{
case Packet::TYPE_RESPONSE_FOUND:
{
answer = LookupResponse(LookupResponse::FOUND,Node(currentNid_,currentAddr_));
for (int x = 0; x < rcv->Count(Packet::HEADER_NODE);x++)
{
wxString node = rcv->Get(Packet::HEADER_NODE,x);
wxString info = rcv->Get(Packet::HEADER_INFO,x);
answer.AddResponse(HashValue(node,key,info));
}
break;
}
case Packet::TYPE_RESPONSE_JUMP:
{
answer = LookupResponse(LookupResponse::JUMP,Node(wxT("UNDEFINED"),rcv->Get(Packet::HEADER_JUMP)));
break;
}
case Packet::TYPE_RESPONSE_SUCCESSOR:
{
answer = LookupResponse(LookupResponse::SUCCESSOR,Node(currentNid_,currentAddr_));
break;
}
default:
{
LogError(wxString().Format(wxT("Received an invalid lookup response from node on con id %d"), id_));
break;
}
}
delete rcv;
return answer;
}
示例3: tokens
//.........这里部分代码省略.........
}
wxMutexGuiLeave();
}
else
{
LogError(wxT("Got an invalid info header on buddy hello."));
}
if (buddy != 0)
{
parent_ = buddy;
parentId_ = buddy->id();
ImEventQueue* queue = new ImEventQueue();
PostConEvent(ImEvent::EVENT_MADE,(void*)queue);
/*
Process the IM events.
*/
HandleImEvents(queue);
PostConEvent(ImEvent::EVENT_LOST);
//delete queue;
}
break;
}
case Packet::TYPE_INSERT:
{
// somebody wants to give us some hashes to be responsible for
// TODO we should validate if we are responsible for them or not
for (int x = 0; x < rcv->Count(Packet::HEADER_HASH); x++)
{
wxString hash = rcv->Get(Packet::HEADER_HASH,x);
wxString node = rcv->Get(Packet::HEADER_NODE,x);
wxString info = rcv->Get(Packet::HEADER_INFO,x);
Network::Instance()->hashTable->Add(HashValue(node,hash,info));
LogDebug(wxString().Format(wxT("Now responsible for hash: %s with owner %s and info %s"), hash.c_str(),node.c_str(),info.c_str()));
}
delete rcv;
break;
}
default:
{
LogError(wxString().Format(wxT("Invalid packet on incomming con id %d"), id_));
delete rcv;
return FALSE;
}
}
break;
}
// node is not a network node and wants to join
case Packet::TYPE_JOIN:
{
//currentAddr_ = rcv->Get(Packet::HEADER_SRC_ADDR);
currentAddr_ = wxString().Format(wxT("%s/%d"),socket_->GetPeerHost().c_str(),ParsePort(rcv->Get(Packet::HEADER_SRC_ADDR)));
rsaPub_ = rcv->Get(Packet::HEADER_PUBLIC_KEY);
wxString wrkGrpKey = rcv->Get(Packet::HEADER_WRKGRPKEY);
if (Prefs::Instance()->Get(Prefs::WRKGRPKEY) != wxT("")