bool GroupTagSubscription::matches (const Message *pMessage) { MessageInfo *pMI = pMessage->getMessageInfo(); if (pMI == NULL) { return false; } uint16 ui16Tag = pMI->getTag(); return (_ui16Tags.contains (ui16Tag)); }
bool DiscreteHistory::isInHistory (Message *pMsg, uint32) { MessageInfo *pMI = pMsg->getMessageInfo(); uint32 ui32 = pMI->getMsgSeqId(); if (SequentialArithmetic::greaterThanOrEqual (ui32, _ui32From) && SequentialArithmetic::lessThanOrEqual(ui32, _ui32To)) { return true; } return false; }
bool HSLanFilter::CreaterMessage(google::protobuf::Message* msg) { if (!msg) { return false; } std::string msgName = msg->GetTypeName(); CCLog(msgName.c_str()); if(!msg->IsInitialized()) { CCString* pErrorInfo = CCString::createWithFormat("Init Error [ %s ]",msgName.c_str()); HSMessageBox(pErrorInfo->getCString()); pErrorInfo->release(); return false; } std::string strbody = msg->SerializeAsString(); std::map<std::string,int>::iterator it = m_lanProtocol.find(msgName); if (it == this->m_lanProtocol.end()) { msgName.append(" LAN Not registered "); CC_SAFE_DELETE(msg); return false; } long long checksum = (long long)(this->Adler32((unsigned char*)strbody.c_str(),strbody.length())); MessageInfo hsMsg = message::MessageInfo::default_instance(); hsMsg.Clear(); message::Head* head = hsMsg.mutable_head(); head->set_checksum(checksum); head->set_sign(0); head->set_uid(HS_GAME_CACHE_DATA_LAN().uuid()); head->set_imei("Ambition:IMEI"); Body* body = hsMsg.mutable_body(); body->add_commandid(it->second); body->add_data(strbody); std::string data = hsMsg.SerializeAsString(); CCLog("Send_Lan %d: %s",data.length(),data.c_str()); HSJava::ShaderJava()->distributeDataToOthers(data.c_str(), data.length()); delete msg; msg = NULL; return true; }
otError UdpSocket::SendTo(Message &aMessage, const MessageInfo &aMessageInfo) { otError error = OT_ERROR_NONE; MessageInfo messageInfoLocal; UdpHeader udpHeader; messageInfoLocal = aMessageInfo; if (messageInfoLocal.GetSockAddr().IsUnspecified()) { messageInfoLocal.SetSockAddr(GetSockName().GetAddress()); } if (GetSockName().mPort == 0) { GetSockName().mPort = static_cast<Udp *>(mTransport)->GetEphemeralPort(); } if (messageInfoLocal.GetPeerAddr().IsUnspecified()) { VerifyOrExit(!GetPeerName().GetAddress().IsUnspecified(), error = OT_ERROR_INVALID_ARGS); messageInfoLocal.SetPeerAddr(GetPeerName().GetAddress()); } if (messageInfoLocal.mPeerPort == 0) { VerifyOrExit(GetPeerName().mPort != 0, error = OT_ERROR_INVALID_ARGS); messageInfoLocal.mPeerPort = GetPeerName().mPort; } udpHeader.SetSourcePort(GetSockName().mPort); udpHeader.SetDestinationPort(messageInfoLocal.mPeerPort); udpHeader.SetLength(sizeof(udpHeader) + aMessage.GetLength()); udpHeader.SetChecksum(0); SuccessOrExit(error = aMessage.Prepend(&udpHeader, sizeof(udpHeader))); aMessage.SetOffset(0); SuccessOrExit(error = static_cast<Udp *>(mTransport)->SendDatagram(aMessage, messageInfoLocal, kProtoUdp)); exit: return error; }
otError Udp::HandleMessage(Message &aMessage, MessageInfo &aMessageInfo) { otError error = OT_ERROR_NONE; UdpHeader udpHeader; uint16_t payloadLength; uint16_t checksum; payloadLength = aMessage.GetLength() - aMessage.GetOffset(); // check length VerifyOrExit(payloadLength >= sizeof(UdpHeader), error = OT_ERROR_PARSE); // verify checksum checksum = Ip6::ComputePseudoheaderChecksum(aMessageInfo.GetPeerAddr(), aMessageInfo.GetSockAddr(), payloadLength, kProtoUdp); checksum = aMessage.UpdateChecksum(checksum, aMessage.GetOffset(), payloadLength); #ifndef FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION VerifyOrExit(checksum == 0xffff, error = OT_ERROR_DROP); #endif VerifyOrExit(aMessage.Read(aMessage.GetOffset(), sizeof(udpHeader), &udpHeader) == sizeof(udpHeader), error = OT_ERROR_PARSE); aMessage.MoveOffset(sizeof(udpHeader)); aMessageInfo.mPeerPort = udpHeader.GetSourcePort(); aMessageInfo.mSockPort = udpHeader.GetDestinationPort(); // find socket for (UdpSocket *socket = mSockets; socket; socket = socket->GetNext()) { if (socket->GetSockName().mPort != udpHeader.GetDestinationPort()) { continue; } if (socket->GetSockName().mScopeId != 0 && socket->GetSockName().mScopeId != aMessageInfo.mInterfaceId) { continue; } if (!aMessageInfo.GetSockAddr().IsMulticast() && !socket->GetSockName().GetAddress().IsUnspecified() && socket->GetSockName().GetAddress() != aMessageInfo.GetSockAddr()) { continue; } // verify source if connected socket if (socket->GetPeerName().mPort != 0) { if (socket->GetPeerName().mPort != udpHeader.GetSourcePort()) { continue; } if (!socket->GetPeerName().GetAddress().IsUnspecified() && socket->GetPeerName().GetAddress() != aMessageInfo.GetPeerAddr()) { continue; } } socket->HandleUdpReceive(aMessage, aMessageInfo); } exit: return error; }
bool Connection::processMessage() { if (m_readBufferSize < sizeof(MessageInfo)) return false; uint8_t* messageData = m_readBuffer.data(); MessageInfo messageInfo; memcpy(&messageInfo, messageData, sizeof(messageInfo)); messageData += sizeof(messageInfo); size_t messageLength = sizeof(MessageInfo) + messageInfo.attachmentCount() * sizeof(AttachmentInfo) + (messageInfo.isMessageBodyIsOutOfLine() ? 0 : messageInfo.bodySize()); if (m_readBufferSize < messageLength) return false; size_t attachmentFileDescriptorCount = 0; size_t attachmentCount = messageInfo.attachmentCount(); std::unique_ptr<AttachmentInfo[]> attachmentInfo; if (attachmentCount) { attachmentInfo = std::make_unique<AttachmentInfo[]>(attachmentCount); memcpy(attachmentInfo.get(), messageData, sizeof(AttachmentInfo) * attachmentCount); messageData += sizeof(AttachmentInfo) * attachmentCount; for (size_t i = 0; i < attachmentCount; ++i) { switch (attachmentInfo[i].getType()) { case Attachment::MappedMemoryType: case Attachment::SocketType: if (!attachmentInfo[i].isNull()) attachmentFileDescriptorCount++; break; case Attachment::Uninitialized: default: ASSERT_NOT_REACHED(); break; } } if (messageInfo.isMessageBodyIsOutOfLine()) attachmentCount--; } Vector<Attachment> attachments(attachmentCount); AttachmentResourceGuard<Vector<Attachment>, Vector<Attachment>::iterator> attachementDisposer(attachments); RefPtr<WebKit::SharedMemory> oolMessageBody; size_t fdIndex = 0; for (size_t i = 0; i < attachmentCount; ++i) { int fd = -1; switch (attachmentInfo[i].getType()) { case Attachment::MappedMemoryType: if (!attachmentInfo[i].isNull()) fd = m_fileDescriptors[fdIndex++]; attachments[attachmentCount - i - 1] = Attachment(fd, attachmentInfo[i].getSize()); break; case Attachment::SocketType: if (!attachmentInfo[i].isNull()) fd = m_fileDescriptors[fdIndex++]; attachments[attachmentCount - i - 1] = Attachment(fd); break; case Attachment::Uninitialized: attachments[attachmentCount - i - 1] = Attachment(); default: break; } } if (messageInfo.isMessageBodyIsOutOfLine()) { ASSERT(messageInfo.bodySize()); if (attachmentInfo[attachmentCount].isNull()) { ASSERT_NOT_REACHED(); return false; } WebKit::SharedMemory::Handle handle; handle.adoptFromAttachment(m_fileDescriptors[attachmentFileDescriptorCount - 1], attachmentInfo[attachmentCount].getSize()); oolMessageBody = WebKit::SharedMemory::create(handle, WebKit::SharedMemory::ReadOnly); if (!oolMessageBody) { ASSERT_NOT_REACHED(); return false; } } ASSERT(attachments.size() == (messageInfo.isMessageBodyIsOutOfLine() ? messageInfo.attachmentCount() - 1 : messageInfo.attachmentCount())); uint8_t* messageBody = messageData; if (messageInfo.isMessageBodyIsOutOfLine()) messageBody = reinterpret_cast<uint8_t*>(oolMessageBody->data()); auto decoder = std::make_unique<MessageDecoder>(DataReference(messageBody, messageInfo.bodySize()), std::move(attachments)); processIncomingMessage(std::move(decoder)); if (m_readBufferSize > messageLength) { memmove(m_readBuffer.data(), m_readBuffer.data() + messageLength, m_readBufferSize - messageLength); m_readBufferSize -= messageLength; } else m_readBufferSize = 0; if (attachmentFileDescriptorCount) { if (m_fileDescriptorsSize > attachmentFileDescriptorCount) { size_t fileDescriptorsLength = attachmentFileDescriptorCount * sizeof(int); memmove(m_fileDescriptors.data(), m_fileDescriptors.data() + fileDescriptorsLength, m_fileDescriptorsSize - fileDescriptorsLength); m_fileDescriptorsSize -= fileDescriptorsLength; } else m_fileDescriptorsSize = 0; } return true; }
ThreadError Ip6::SendDatagram(Message &message, MessageInfo &messageInfo, IpProto ipproto) { ThreadError error = kThreadError_None; Header header; uint16_t payloadLength = message.GetLength(); uint16_t checksum; const NetifUnicastAddress *source; header.Init(); header.SetPayloadLength(payloadLength); header.SetNextHeader(ipproto); header.SetHopLimit(messageInfo.mHopLimit ? messageInfo.mHopLimit : kDefaultHopLimit); if (messageInfo.GetSockAddr().IsUnspecified()) { VerifyOrExit((source = Netif::SelectSourceAddress(messageInfo)) != NULL, error = kThreadError_Error); header.SetSource(source->GetAddress()); } else { header.SetSource(messageInfo.GetSockAddr()); } header.SetDestination(messageInfo.GetPeerAddr()); if (header.GetDestination().IsLinkLocal() || header.GetDestination().IsLinkLocalMulticast()) { VerifyOrExit(messageInfo.mInterfaceId != 0, error = kThreadError_Drop); } if (messageInfo.GetPeerAddr().IsRealmLocalMulticast()) { SuccessOrExit(error = AddMplOption(message, header, ipproto, payloadLength)); } SuccessOrExit(error = message.Prepend(&header, sizeof(header))); // compute checksum checksum = ComputePseudoheaderChecksum(header.GetSource(), header.GetDestination(), payloadLength, ipproto); switch (ipproto) { case kProtoUdp: SuccessOrExit(error = Udp::UpdateChecksum(message, checksum)); break; case kProtoIcmp6: SuccessOrExit(error = Icmp::UpdateChecksum(message, checksum)); break; default: break; } exit: if (error == kThreadError_None) { error = HandleDatagram(message, NULL, messageInfo.mInterfaceId, NULL, false); } return error; }
static RacyInterruptPolicy MediateRace(const MessageInfo& parent, const MessageInfo& child) { return (PTestRaceDeferral::Msg_Win__ID == parent.type()) ? RIPParentWins : RIPChildWins; }
void PositionUpdater::doMetadataArrived (StringHashtable<MsgIdList > *pMsgToNotifyByQueryId) { if (pMsgToNotifyByQueryId == nullptr) { return; } const char *pszMethodName = "PositionUpdater::doMetadataArrived"; String msgId; StringHashtable<LList<String> >::Iterator iter = pMsgToNotifyByQueryId->getAllElements(); for (; !iter.end(); iter.nextElement()) { const char *pszQueryId = iter.getKey(); LList<String> *pMsgToNotify = iter.getValue(); for (int rc = pMsgToNotify->getFirst (msgId); rc == 1; rc = pMsgToNotify->getNext (msgId)) { MessageHeaders::MsgType type; Message *pMessage = getCompleteMessageAndRemoveDSProMetadata (_pDSPro->_pDataStore, msgId.c_str(), type); if (pMessage == nullptr || (type != MessageHeaders::Data && type != MessageHeaders::Metadata)) { // The message to be notified to the application was not found at // this time. Re-add it to the list of messages to notify so it can // be tried again later. static const char * messageIds[2]; messageIds[0] = msgId.c_str(); messageIds[1] = nullptr; addMetadataToNotify (pszQueryId, messageIds); } else { MessageInfo *pMI = pMessage->getMessageInfo(); char *pszId = convertFieldToKey (pMI->getGroupName(), pMI->getPublisherNodeId(), pMI->getMsgSeqId()); const String currMsgId (pszId); if (pszId == nullptr) { checkAndLogMsg (pszMethodName, memoryExhausted); } else { free (pszId); pszId = nullptr; } String sGrpName (MessageIdGenerator::extractSubgroupFromMsgGroup (pMI->getGroupName())); if (sGrpName.length() <= 0) { checkAndLogMsg (pszMethodName, Logger::L_MildError, "could not extract group message id\n"); sGrpName = pMI->getGroupName(); } if (type == MessageHeaders::Metadata) { MetaData *pMetadata = toMetadata (pMessage->getData(), pMI->getTotalMessageLength()); if (pMetadata != nullptr) { String sReferredObjectId, sReferredInstanceId, sRefersTo; getReferredObjectAndInstanceIds (pMetadata, sReferredObjectId, sReferredInstanceId, sRefersTo); int rc = _pDSPro->metadataArrived (currMsgId, sGrpName, sReferredObjectId, sReferredInstanceId, pMetadata, sRefersTo, pszQueryId); checkAndLogMsg (pszMethodName, Logger::L_Info, "notified clients " "with message %s matching query request %s\n/", currMsgId.c_str(), pszQueryId); delete pMetadata; pMetadata = nullptr; if (rc != 0) { checkAndLogMsg (pszMethodName, Logger::L_Warning, "Can not notify message " "with id = <%s> failed. Returned %d\n", currMsgId.c_str(), rc); } else { checkAndLogMsg (pszMethodName, Logger::L_Info, "client applications " "notified message with id: <%s>.\n", currMsgId.c_str()); } } } else { // Data or chunked data uint8 ui8ChunkIndex = pMI->getTotalNumberOfChunks() == 0 ? (uint8) 0 : 1; // HACK: For the general case I need to figure out the current number of chunks from the database rc = _pDSPro->dataArrived (currMsgId, sGrpName, pMI->getObjectId(), pMI->getInstanceId(), pMI->getAnnotates(), pMI->getMimeType(), pMessage->getData(), pMI->getTotalMessageLength(), ui8ChunkIndex, pMI->getTotalNumberOfChunks(), pszQueryId); } free ((void*) pMessage->getData()); delete pMessage->getMessageHeader(); delete pMessage; } } } }