本文整理汇总了C++中SPtr::addRelayInfo方法的典型用法代码示例。如果您正苦于以下问题:C++ SPtr::addRelayInfo方法的具体用法?C++ SPtr::addRelayInfo怎么用?C++ SPtr::addRelayInfo使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SPtr
的用法示例。
在下文中一共展示了SPtr::addRelayInfo方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: List
//.........这里部分代码省略.........
// remember options to be echoed
echoListTbl[relays].first();
while (gen = echoListTbl[relays].get()) {
if (!echo) {
Log(Warning) << "Invalid option (" << gen->getOptType() << ") in RELAY_FORW message was ignored." << LogEnd;
echoListTbl[relays].del();
} else {
if (!echo->isOption(gen->getOptType())) {
Log(Warning) << "Invalid option (" << gen->getOptType() << ") in RELAY_FORW message was ignored." << LogEnd;
echoListTbl[relays].del();
} else {
Log(Info) << "Option " << gen->getOptType() << " will be echoed back." << LogEnd;
}
}
}
// remember those links
linkAddrTbl[relays] = linkAddr;
peerAddrTbl[relays] = peerAddr;
interfaceIDTbl[relays] = ptrIfaceID;
hopTbl[relays] = hopCount;
relays++;
if (relays> HOP_COUNT_LIMIT) {
Log(Error) << "Message is nested more than allowed " << HOP_COUNT_LIMIT << " times. Message dropped." << LogEnd;
return 0;
}
if (optRelayCnt!=1) {
Log(Error) << optRelayCnt << " RELAY_MSG options received, but exactly one was expected. Message dropped." << LogEnd;
return 0;
}
if (optIfaceIDCnt>1) {
Log(Error) << "More than one (" << optIfaceIDCnt
<< ") interface-ID options received, but at most 1 was expected. Message dropped." << LogEnd;
return 0;
}
Log(Info) << "RELAY_FORW was decapsulated: link=" << linkAddr->getPlain() << ", peer=" << peerAddr->getPlain();
bool guessMode = SrvCfgMgr().guessMode();
if (ptrIfaceID) {
// find relay interface based on the interface-id option
Log(Cont) << ", interfaceID len=" << ptrIfaceID->getSize() << LogEnd;
relayIface = ptrIface->getRelayByInterfaceID(ptrIfaceID);
if (!relayIface) {
if (!guessMode) {
Log(Error) << "Unable to find relay interface with interfaceID=" << ptrIfaceID->getPlain() << " defined on the "
<< ptrIface->getName() << "/" << ptrIface->getID() << " interface." << LogEnd;
return 0;
}
}
}
else {
// find relay interface based on the link address
Log(Cont) << ", interfaceID option missing." << LogEnd;
Log(Warning) << "InterfaceID option missing, trying to find proper interface using link address: "
<< linkAddr->getPlain() << " (expect troubles)."<< LogEnd;
relayIface = ptrIface->getRelayByLinkAddr(linkAddr);
if (!relayIface) {
Log(Error) << "Unable to find relay interface using link address: " << linkAddr->getPlain() << LogEnd;
if (!guessMode) {
return 0;
}
}
}
if (!relayIface && guessMode) {
relayIface = ptrIface->getAnyRelay();
if (!relayIface) {
Log(Error) << "Guess-mode: Unable to find any relays on " << ptrIface->getFullName() << LogEnd;
return 0;
}
interfaceIDTbl[relays] = -1;
Log(Notice) << "Guess-mode: Relayed interface guessed as " << relayIface->getFullName() << LogEnd;
}
// now switch to relay interface
ptrIface = relayIface;
buf = relay_buf;
bufsize = relay_bufsize;
}
SPtr<TSrvMsg> msg = this->decodeMsg(ptrIface, peer, relay_buf, relay_bufsize);
for (int i=0; i<relays; i++) {
msg->addRelayInfo(linkAddrTbl[i], peerAddrTbl[i], hopTbl[i], interfaceIDTbl[i], echoListTbl[i]);
}
if (remoteID) {
Log(Debug) << "RemoteID received: vendor=" << remoteID->getVendor()
<< ", length=" << remoteID->getVendorDataLen() << "." << LogEnd;
msg->setRemoteID(remoteID);
remoteID = 0;
remoteID = msg->getRemoteID();
PrintHex("RemoteID:", remoteID->getVendorData(), remoteID->getVendorDataLen());
}
return (Ptr*)msg;
}
示例2: while
//.........这里部分代码省略.........
linkAddrTbl[relays] = linkAddr;
peerAddrTbl[relays] = peerAddr;
hopTbl[relays] = hopCount;
relays++;
if (relays> HOP_COUNT_LIMIT) {
Log(Error) << "Message is nested more than allowed " << HOP_COUNT_LIMIT
<< " times. Message dropped." << LogEnd;
return 0;
}
if (optRelayCnt!=1) {
Log(Error) << optRelayCnt << " RELAY_MSG options received, but exactly one was "
<< "expected. Message dropped." << LogEnd;
return 0;
}
if (optIfaceIDCnt>1) {
Log(Error) << "More than one (" << optIfaceIDCnt
<< ") interface-ID options received, but exactly 1 was expected. "
<< "Message dropped." << LogEnd;
return 0;
}
Log(Info) << "RELAY_FORW was decapsulated: link=" << linkAddr->getPlain()
<< ", peer=" << peerAddr->getPlain();
// --- selectSubnet() starts here ---
bool guessMode = SrvCfgMgr().guessMode();
// First try to find a relay based on the interface-id option
if (ptrIfaceID) {
Log(Cont) << ", interfaceID len=" << ptrIfaceID->getSize() << LogEnd;
ifindex = SrvCfgMgr().getRelayByInterfaceID(ptrIfaceID);
if (ifindex == -1) {
Log(Debug) << "Unable to find relay interface with interfaceID="
<< ptrIfaceID->getPlain() << " defined on the "
<< physicalIface->getFullName() << " interface." << LogEnd;
} else {
how_found = "using interface-id=" + ptrIfaceID->getPlain();
}
} else {
Log(Cont) << ", no interface-id option." << LogEnd;
}
// then try to find a relay based on the link address
if (ifindex == -1) {
ifindex = SrvCfgMgr().getRelayByLinkAddr(linkAddr);
if (ifindex == -1) {
Log(Info) << "Unable to find relay interface using link address: "
<< linkAddr->getPlain() << LogEnd;
} else {
how_found = string("using link-addr=") + linkAddr->getPlain();
}
}
// the last hope - use guess-mode to get any relay
if ((ifindex == -1) && guessMode) {
ifindex = SrvCfgMgr().getAnyRelay();
if (ifindex != -1) {
how_found = "using guess-mode";
}
}
// --- selectSubnet() ends here ---
// now switch to relay interface
buf = relay_buf;
bufsize = relay_bufsize;
}
if (ifindex == -1) {
Log(Warning) << "Unable to find appropriate interface for this RELAY-FORW." << LogEnd;
return 0;
} else {
SPtr<TSrvCfgIface> cfgIface = SrvCfgMgr().getIfaceByID(ifindex);
Log(Notice) << "Found relay " << cfgIface->getFullName()
<< " by " << how_found << LogEnd;
}
SPtr<TSrvMsg> msg = decodeMsg(ifindex, peer, relay_buf, relay_bufsize);
if (!msg) {
return 0;
}
for (int i=0; i<relays; i++) {
msg->addRelayInfo(linkAddrTbl[i], peerAddrTbl[i], hopTbl[i], echoListTbl[i]);
}
msg->setPhysicalIface(physicalIface->getID());
if (remoteID) {
Log(Debug) << "RemoteID received: vendor=" << remoteID->getVendor()
<< ", length=" << remoteID->getVendorDataLen() << "." << LogEnd;
msg->setRemoteID(remoteID);
remoteID = 0;
remoteID = msg->getRemoteID();
PrintHex("RemoteID:", (uint8_t*)remoteID->getVendorData(), remoteID->getVendorDataLen());
}
return (Ptr*)msg;
}