本文整理汇总了C++中HAGGLE_DBG函数的典型用法代码示例。如果您正苦于以下问题:C++ HAGGLE_DBG函数的具体用法?C++ HAGGLE_DBG怎么用?C++ HAGGLE_DBG使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了HAGGLE_DBG函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: toupper
void SecurityManager::onConfig(Metadata *m)
{
const char *param = m->getParameter("security_level");
if (param) {
char *level = new char[strlen(param) + 1];
size_t i;
// Convert string to uppercase
for (i = 0; i < strlen(param); i++) {
level[i] = toupper(param[i]);
}
level[i] = '\0';
if (strcmp(level, security_level_names[SECURITY_LEVEL_HIGH]) == 0) {
securityLevel = SECURITY_LEVEL_HIGH;
HAGGLE_DBG("Security level set to %s\n", security_level_names[SECURITY_LEVEL_HIGH]);
} else if (strcmp(level, security_level_names[SECURITY_LEVEL_MEDIUM]) == 0) {
securityLevel = SECURITY_LEVEL_MEDIUM;
HAGGLE_DBG("Security level set to %s\n", security_level_names[SECURITY_LEVEL_MEDIUM]);
} else if (strcmp(level, security_level_names[SECURITY_LEVEL_LOW]) == 0) {
securityLevel = SECURITY_LEVEL_LOW;
HAGGLE_DBG("Security level set to %s\n", security_level_names[SECURITY_LEVEL_LOW]);
} else {
HAGGLE_ERR("Unrecognized security level '%s'\n", level);
}
delete [] level;
}
}
示例2: strtoul
void Forwarder::onConfig(const Metadata& m)
{
if (m.getName().compare("Forwarder") != 0)
return;
const char *param = m.getParameter("max_generated_delegates");
if (param) {
char *ptr = NULL;
unsigned long d = strtoul(param, &ptr, 10);
if (ptr && ptr != param && *ptr == '\0') {
HAGGLE_DBG("%s Setting max_generated_delegates to %lu\n", getName(), d);
max_generated_delegates = d;
}
}
param = m.getParameter("max_generated_targets");
if (param) {
char *ptr = NULL;
unsigned long d = strtoul(param, &ptr, 10);
if (ptr && ptr != param && *ptr == '\0') {
HAGGLE_DBG("%s Setting max_generated_targets to %lu\n", getName(), d);
max_generated_targets = d;
}
}
const Metadata *md = m.getMetadata(getName());
if (md) {
onForwarderConfig(*md);
}
}
示例3: HAGGLE_DBG
void ForwarderRank::_onForwarderConfig(const Metadata& m)
{
if (strcmp(getName(), m.getName().c_str()) != 0)
return;
HAGGLE_DBG("Prophet forwarder configuration\n");
const char *param = m.getParameter("label");
if (param) {
myLabel = string(param);
HAGGLE_DBG("%s: Setting label to %s\n", getName(), myLabel.c_str());
}
param = m.getParameter("rank");
if (param)
{
char *ptr = NULL;
RANK_T p = strtol(param,&ptr,10);
if (ptr && ptr != param && *ptr == '\0')
{
myRank = p;
HAGGLE_DBG("%s: Setting rank to %ld\n", getName(), myRank);
}
}
}
示例4: HAGGLE_DBG
bool SecurityHelper::run()
{
HAGGLE_DBG("SecurityHelper running...\n");
while (!shouldExit()) {
QueueEvent_t qe;
SecurityTask *task = NULL;
qe = taskQ.retrieve(&task);
switch (qe) {
case QUEUE_ELEMENT:
doTask(task);
// Delete task here or return it with result in private event?
//delete task;
break;
case QUEUE_WATCH_ABANDONED:
HAGGLE_DBG("SecurityHelper instructed to exit...\n");
return false;
default:
HAGGLE_ERR("Unknown security task queue return value\n");
}
}
return false;
}
示例5: memset
ProtocolEvent ProtocolRFCOMMClient::connectToPeer()
{
struct sockaddr_bt peerAddr;
BluetoothAddress *addr;
if (!peerIface)
return PROT_EVENT_ERROR;
addr = peerIface->getAddress<BluetoothAddress>();
if(!addr)
return PROT_EVENT_ERROR;
memset(&peerAddr, 0, sizeof(peerAddr));
peerAddr.bt_family = AF_BLUETOOTH;
BDADDR_swap(&peerAddr.bt_bdaddr, mac);
peerAddr.bt_channel = channel & 0xff;
HAGGLE_DBG("%s Trying to connect over RFCOMM to [%s] channel=%u\n",
getName(), addr->getStr(), channel);
ProtocolEvent ret = openConnection((struct sockaddr *) &peerAddr, sizeof(peerAddr));
if (ret != PROT_EVENT_SUCCESS) {
HAGGLE_DBG("%s Connection failed to [%s] channel=%u\n",
getName(), addr->getStr(), channel);
return ret;
}
HAGGLE_DBG("%s Connected to [%s] channel=%u\n",
getName(), addr->getStr(), channel);
return ret;
}
示例6: HAGGLE_ERR
bool SecurityHelper::verifyDataObject(DataObjectRef& dObj, CertificateRef& cert) const
{
RSA *key;
// Cannot verify without signature
if (!dObj->getSignature()) {
HAGGLE_ERR("No signature in data object, cannot verify\n");
return false;
}
writeErrors("(not this): ");
key = cert->getPubKey();
if (RSA_verify(NID_sha1, dObj->getId(), sizeof(DataObjectId_t),
const_cast<unsigned char *>(dObj->getSignature()), dObj->getSignatureLength(), key) != 1) {
char *raw;
size_t len;
writeErrors("");
dObj->getRawMetadataAlloc((unsigned char **)&raw, &len);
if (raw) {
HAGGLE_DBG("Signature is invalid:\n%s\n", raw);
free(raw);
}
dObj->setSignatureStatus(DataObject::SIGNATURE_INVALID);
return false;
}
HAGGLE_DBG("Signature is valid\n");
dObj->setSignatureStatus(DataObject::SIGNATURE_VALID);
return true;
}
示例7: HAGGLE_DBG
void ProtocolManager::onNeighborInterfaceDown(Event *e)
{
InterfaceRef& iface = e->getInterface();
if (!iface)
return;
HAGGLE_DBG("Neighbor interface [%s] went away, checking for associated protocols\n", iface->getIdentifierStr());
// Go through the protocol list
protocol_registry_t::iterator it = protocol_registry.begin();
for (;it != protocol_registry.end(); it++) {
Protocol *p = (*it).second;
/*
Never bring down our application IPC protocol when
application interfaces go down (i.e., applications deregister).
*/
if (p->getLocalInterface()->getType() == Interface::TYPE_APPLICATION_PORT) {
continue;
}
// Is the associated with this protocol?
if (p->isClient() && p->isForInterface(iface)) {
HAGGLE_DBG("Shutting down protocol %s because neighbor interface [%s] went away\n",
p->getName(), iface->getIdentifierStr());
p->handleInterfaceDown(iface);
}
}
}
示例8: defined
bool
SocketWrapper::multiplySndBufferSize(int factor)
{
bool res = false;
#if defined(OS_LINUX)
int ret = 0;
long optval = 0;
socklen_t optlen = sizeof(optval);
ret = ::getsockopt(sock, SOL_SOCKET, SO_SNDBUF, &optval, &optlen);
if (-1 == ret) {
return res;
}
HAGGLE_DBG("Original send buffer set to %ld bytes\n", optval);
optval = optval * factor;
ret = ::setsockopt(sock, SOL_SOCKET, SO_SNDBUF, &optval, optlen);
if (-1 == ret) {
HAGGLE_ERR("Could not set send buffer to %ld bytes\n", optval);
} else {
HAGGLE_DBG("Send buffer set to %ld bytes\n", optval);
res = true;
}
#endif
return res;
}
示例9: getQueue
ProtocolEvent ProtocolUDPGeneric::waitForEvent(
DataObjectRef &dObj,
Timeval *timeout,
bool writeevent)
{
QueueElement *qe = NULL;
Queue *q = getQueue();
if (!q) {
return PROT_EVENT_ERROR;
}
SocketWrapper *sock = getReadEndOfReceiveSocket();
if (NULL == sock) {
HAGGLE_ERR("%s Null receive socket\n", getName());
return PROT_EVENT_ERROR_FATAL;
}
HAGGLE_DBG("%s Waiting for queue element or timeout... %s\n",
getName(), timeout->getAsString().c_str());
QueueEvent_t qev = q->retrieve(&qe,
sock->getSOCKET(),
timeout,
writeevent);
if (QUEUE_ELEMENT == qev) {
dObj = qe->getDataObject();
delete qe;
return PROT_EVENT_TXQ_NEW_DATAOBJECT;
}
if (QUEUE_EMPTY == qev) {
return PROT_EVENT_TXQ_EMPTY;
}
if (QUEUE_WATCH_WRITE == qev) {
return PROT_EVENT_WRITEABLE;
}
if (QUEUE_WATCH_ABANDONED == qev) {
// SW: this occurs when the protocol has been shutdown via some other
// mechanism, such as interface down
HAGGLE_DBG("%s Waiting for event abandoned\n", getName());
return PROT_EVENT_SHOULD_EXIT;
}
if (QUEUE_TIMEOUT == qev) {
HAGGLE_DBG("%s Waiting for event timeout\n", getName());
return PROT_EVENT_TIMEOUT;
}
if (QUEUE_WATCH_READ == qev) {
return PROT_EVENT_INCOMING_DATA;
}
HAGGLE_ERR("%s Waiting for event unknown error\n", getName());
return PROT_EVENT_ERROR;
}
示例10: id_from_string
void ForwarderRank::_generateDelegatesFor(const DataObjectRef &dObj, const NodeRef &target, const NodeRefList *other_targets)
{
List<Pair<NodeRef, bubble_metric_t> > sorted_delegate_list;
// Figure out which node to look for:
bubble_node_id_t target_id = id_from_string(target->getIdStr());
LABEL_T targetLabel = rib[target_id].first;
//RANK_T targetRank = rib[target_id].second;
HAGGLE_DBG("HAGGLE_DBG:_generateDelegatesFor node %d string %s label %s\n", target_id, target->getIdStr(), targetLabel.c_str());
for (bubble_rib_t::iterator it = rib.begin();it != rib.end(); it++)
{
if (it->first != this_node_id && it->first != target_id) {
NodeRef delegate = kernel->getNodeStore()->retrieve(id_number_to_nodeid[it->first], true);
if (delegate && !isTarget(delegate, other_targets)) {
LABEL_T &neighborLabel = it->second.first;
RANK_T &neighborRank = it->second.second;
HAGGLE_DBG("HAGGLE_DBG: _generateDelegatesFor neighborLabel=%s, targetLabel=%s\n", neighborLabel.c_str(), targetLabel.c_str());
if (neighborLabel.compare(targetLabel)==0)
{
//NodeRef delegate = Node::create_with_id(Node::TYPE_PEER, id_number_to_nodeid[it->first].c_str(), "Label delegate node");
sortedNodeListInsert(sorted_delegate_list, delegate, it->second);
HAGGLE_DBG("HAGGLE_DBG: _generateDelegatesFor Label same: Node '%s' is a good delegate for target '%s' [label=%s, rank=%ld]\n",
delegate->getName().c_str(), target->getName().c_str(), neighborLabel.c_str(), neighborRank);
}
}
}
}
// Add up to max_generated_delegates delegates to the result in order of decreasing metric
if (!sorted_delegate_list.empty()) {
NodeRefList delegates;
unsigned long num_delegates = max_generated_delegates;
while (num_delegates && sorted_delegate_list.size()) {
NodeRef delegate = sorted_delegate_list.front().first;
sorted_delegate_list.pop_front();
delegates.push_back(delegate);
num_delegates--;
}
kernel->addEvent(new Event(EVENT_TYPE_DELEGATE_NODES, dObj, target, delegates));
HAGGLE_DBG("HAGGLE_DBG: Forward Generated %lu delegates for target %s\n", delegates.size(), target->getName().c_str());
} else {
HAGGLE_DBG("No delegates found for target %s\n", target->getName().c_str());
}
}
示例11: defined
ProtocolEvent ProtocolTCPClient::connectToPeer()
{
socklen_t addrlen;
char buf[SOCKADDR_SIZE];
struct sockaddr *peer_addr = (struct sockaddr *)buf;
unsigned short peerPort;
SocketAddress *addr = NULL;
InterfaceRef pIface;
// FIXME: use other port than the default one?
peerPort = TCP_DEFAULT_PORT;
if (!peerIface ||
!(peerIface->getAddress<IPv4Address>() ||
#if defined(ENABLE_IPv6)
peerIface->getAddress<IPv6Address>()
#else
0
#endif
))
return PROT_EVENT_ERROR;
#if defined(ENABLE_IPv6)
IPv6Address *addr6 = peerIface->getAddress<IPv6Address>();
if (addr6) {
addrlen = addr6->fillInSockaddr((struct sockaddr_in6 *)peer_addr, peerPort);
addr = addr6;
HAGGLE_DBG("Using IPv6 address %s to connect to peer\n", addr6->getStr());
}
#endif
if (!addr) {
// Since the check above passed, we know there has to be an IPv4 or an
// IPv6 address associated with the interface, and since there was no IPv6...
IPv4Address *addr4 = peerIface->getAddress<IPv4Address>();
if (addr4) {
addrlen = addr4->fillInSockaddr((struct sockaddr_in *)peer_addr, peerPort);
addr = addr4;
}
}
if (!addr) {
HAGGLE_DBG("No IP address to connect to\n");
return PROT_EVENT_ERROR;
}
ProtocolEvent ret = openConnection(peer_addr, addrlen);
if (ret != PROT_EVENT_SUCCESS) {
HAGGLE_DBG("%s Connection failed to [%s] tcp port=%u\n",
getName(), addr->getStr(), peerPort);
return ret;
}
HAGGLE_DBG("%s Connected to [%s] tcp port=%u\n", getName(), addr->getStr(), peerPort);
return ret;
}
示例12: isNonblock
ProtocolEvent
SocketWrapper::openConnection(
const struct sockaddr *saddr,
socklen_t addrlen)
{
bool wasNonBlock = isNonblock();
if (INVALID_SOCKET == sock) {
HAGGLE_ERR("Socket is invalid\n");
return PROT_EVENT_ERROR;
}
if (!saddr) {
HAGGLE_ERR("Address is invalid\n");
return PROT_EVENT_ERROR;
}
// block while connecting
if (nonblock) {
setNonblock(false);
}
bool hasError = false;
int ret = ::connect(sock, saddr, addrlen);
if (SOCKET_ERROR == ret) {
hasError = true;
HAGGLE_ERR("Problems connecting: %s\n",
SocketWrapper::getProtocolErrorStr());
}
if (wasNonBlock) {
setNonblock(true);
}
if (!hasError) {
HAGGLE_DBG("Succesfully connected to socket.\n");
setConnected(true);
return PROT_EVENT_SUCCESS;
} else {
HAGGLE_DBG("An error occurred connecting: %s\n",
getProtocolErrorStr());
}
switch (getProtocolError()) {
case PROT_ERROR_BAD_HANDLE:
case PROT_ERROR_INVALID_ARGUMENT:
case PROT_ERROR_NO_MEMORY:
case PROT_ERROR_NOT_A_SOCKET:
case PROT_ERROR_NO_STORAGE_SPACE:
return PROT_EVENT_ERROR_FATAL;
default:
return PROT_EVENT_ERROR;
}
}
示例13: HAGGLE_DBG
ProtocolEvent ProtocolUDP::sendData(const void *buffer, size_t len, const int flags, size_t *bytes)
{
char buf[SOCKADDR_SIZE];
struct sockaddr *sa = (struct sockaddr *)buf;
socklen_t addrlen;
SocketAddress *addr = NULL;
ssize_t ret;
if (!buffer) {
HAGGLE_DBG("%s Send buffer is NULL\n", getName());
return PROT_EVENT_ERROR;
}
if (!peerIface) {
HAGGLE_DBG("%s Send interface invalid\n", getName());
*bytes = 0;
return PROT_EVENT_ERROR;
}
#if defined(ENABLE_IPv6)
addr = peerIface->getAddress<IPv6Address>();
#endif
if (!addr)
addr = peerIface->getAddress<IPv4Address>();
if (!addr) {
HAGGLE_DBG("%s Send interface has no valid address\n", getName());
*bytes = 0;
return PROT_EVENT_ERROR;
}
if (addr->getTransport()->getType() != Transport::TYPE_UDP) {
HAGGLE_DBG("%s Send interface [%s] has no valid UDP port\n", getName(),
peerIface->getIdentifierStr());
*bytes = 0;
return PROT_EVENT_ERROR;
}
addrlen = addr->fillInSockaddr(sa);
HAGGLE_DBG("%s sending to address %s:%d\n",
getName(), addr->getURI(),
reinterpret_cast<const TransportUDP *>(addr->getTransport())->getPort());
ret = sendTo(buffer, len, flags, sa, addrlen);
if (ret < 0)
return PROT_EVENT_ERROR;
else if (ret == 0)
return PROT_EVENT_PEER_CLOSED;
*bytes = ret;
return PROT_EVENT_SUCCESS;
}
示例14: switch
/*
This function is called after the SecurityHelper thread finished a task.
The Security manager may act on any of the results if it wishes.
*/
void SecurityManager::onSecurityTaskComplete(Event *e)
{
if (!e || !e->hasData())
return;
SecurityTask *task = static_cast<SecurityTask *>(e->getData());
switch (task->type) {
case SECURITY_TASK_GENERATE_CERTIFICATE:
HAGGLE_DBG("Certificate generated!\n");
if (task->cert->getSubject() == kernel->getThisNode()->getIdStr()) {
HAGGLE_DBG("Certificate is my own\n");
/* Save our private key and our certificate */
privKey = task->privKey;
myCert = task->cert;
signalIsReadyForStartup();
}
break;
case SECURITY_TASK_VERIFY_CERTIFICATE:
/*
if (task->cert && task->cert->isVerified()) {
printCertificates();
}
*/
break;
case SECURITY_TASK_VERIFY_DATAOBJECT:
/*
NOTE:
Here is the possibility to generate a EVENT_TYPE_DATAOBJECT_VERIFIED
event even if the data object had a bad signature. In that case, the
Data manager will remove the data object from the bloomfilter so that
it can be received again (hopefully with a valid signature the next time).
However, this means that also the data object with the bad signature
can be received once more, in worst case in a never ending circle.
Perhaps the best solution is to hash both the data object ID and the
signature (if available) into a node's bloomfilter?
*/
if (task->dObj->hasValidSignature()) {
HAGGLE_DBG("DataObject %s has a valid signature!\n",
task->dObj->getIdStr());
kernel->addEvent(new Event(EVENT_TYPE_DATAOBJECT_VERIFIED,
task->dObj));
} else {
HAGGLE_DBG("DataObject %s has an unverifiable signature!\n",
task->dObj->getIdStr());
}
break;
case SECURITY_TASK_SIGN_DATAOBJECT:
break;
}
delete task;
}
示例15: signalIsReadyForStartup
void SecurityManager::onRepositoryData(Event *e)
{
RepositoryEntryRef re;
if (!e->getData()) {
signalIsReadyForStartup();
return;
}
HAGGLE_DBG("Got repository callback\n");
DataStoreQueryResult *qr = static_cast < DataStoreQueryResult * >(e->getData());
if (qr->countRepositoryEntries() == 0) {
HAGGLE_DBG("No repository entries, generating new certificate and keypair\n");
helper->addTask(new SecurityTask(SECURITY_TASK_GENERATE_CERTIFICATE));
// Delay signalling that we are ready for startup until we get the
// task result indicating our certificate is ready.
delete qr;
return;
}
while ((re = qr->detachFirstRepositoryEntry())) {
if (strcmp(re->getKey(), "privkey") == 0) {
// Just to make sure
if (privKey)
RSA_free(privKey);
privKey = stringToRSAKey(re->getValueStr(), KEY_TYPE_PRIVATE);
HAGGLE_DBG("Read my own private key from repository\n");
} else {
CertificateRef c = Certificate::fromPEM(re->getValueStr());
if (c) {
if (c->getSubject() == kernel->getThisNode()->getIdStr())
myCert = c;
storeCertificate(c);
HAGGLE_DBG("Read certificate for subject '%s' from repository\n",
c->getSubject().c_str());
} else {
HAGGLE_ERR("Could not read certificate from repository\n");
}
}
}
delete qr;
signalIsReadyForStartup();
}