本文整理汇总了C++中ip6::MessageInfo::SetPeerAddr方法的典型用法代码示例。如果您正苦于以下问题:C++ MessageInfo::SetPeerAddr方法的具体用法?C++ MessageInfo::SetPeerAddr怎么用?C++ MessageInfo::SetPeerAddr使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ip6::MessageInfo
的用法示例。
在下文中一共展示了MessageInfo::SetPeerAddr方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: SendDatasetChanged
otError Leader::SendDatasetChanged(const Ip6::Address &aAddress)
{
ThreadNetif &netif = GetNetif();
otError error = OT_ERROR_NONE;
Coap::Header header;
Ip6::MessageInfo messageInfo;
Message *message;
header.Init(OT_COAP_TYPE_CONFIRMABLE, OT_COAP_CODE_POST);
header.SetToken(Coap::Header::kDefaultTokenLength);
header.AppendUriPathOptions(OT_URI_PATH_DATASET_CHANGED);
VerifyOrExit((message = NewMeshCoPMessage(netif.GetCoap(), header)) != NULL, error = OT_ERROR_NO_BUFS);
messageInfo.SetSockAddr(netif.GetMle().GetMeshLocal16());
messageInfo.SetPeerAddr(aAddress);
messageInfo.SetPeerPort(kCoapUdpPort);
SuccessOrExit(error = netif.GetCoap().SendMessage(*message, messageInfo));
otLogInfoMeshCoP(GetInstance(), "sent dataset changed");
exit:
if (error != OT_ERROR_NONE && message != NULL)
{
message->Free();
}
return error;
}
示例2: HandleUdpReceive
void JoinerRouter::HandleUdpReceive(Message &aMessage, const Ip6::MessageInfo &aMessageInfo)
{
ThreadNetif & netif = GetNetif();
otError error;
Coap::Message * message = NULL;
Ip6::MessageInfo messageInfo;
JoinerUdpPortTlv udpPort;
JoinerIidTlv iid;
JoinerRouterLocatorTlv rloc;
ExtendedTlv tlv;
uint16_t borderAgentRloc;
uint16_t offset;
otLogInfoMeshCoP("JoinerRouter::HandleUdpReceive");
SuccessOrExit(error = GetBorderAgentRloc(GetNetif(), borderAgentRloc));
VerifyOrExit((message = NewMeshCoPMessage(netif.GetCoap())) != NULL, error = OT_ERROR_NO_BUFS);
message->Init(OT_COAP_TYPE_NON_CONFIRMABLE, OT_COAP_CODE_POST);
message->SetToken(Coap::Message::kDefaultTokenLength);
message->AppendUriPathOptions(OT_URI_PATH_RELAY_RX);
message->SetPayloadMarker();
udpPort.Init();
udpPort.SetUdpPort(aMessageInfo.GetPeerPort());
SuccessOrExit(error = message->Append(&udpPort, sizeof(udpPort)));
iid.Init();
iid.SetIid(aMessageInfo.GetPeerAddr().mFields.m8 + 8);
SuccessOrExit(error = message->Append(&iid, sizeof(iid)));
rloc.Init();
rloc.SetJoinerRouterLocator(netif.GetMle().GetRloc16());
SuccessOrExit(error = message->Append(&rloc, sizeof(rloc)));
tlv.SetType(Tlv::kJoinerDtlsEncapsulation);
tlv.SetLength(aMessage.GetLength() - aMessage.GetOffset());
SuccessOrExit(error = message->Append(&tlv, sizeof(tlv)));
offset = message->GetLength();
SuccessOrExit(error = message->SetLength(offset + tlv.GetLength()));
aMessage.CopyTo(aMessage.GetOffset(), offset, tlv.GetLength(), *message);
messageInfo.SetSockAddr(netif.GetMle().GetMeshLocal16());
messageInfo.SetPeerAddr(netif.GetMle().GetMeshLocal16());
messageInfo.GetPeerAddr().mFields.m16[7] = HostSwap16(borderAgentRloc);
messageInfo.SetPeerPort(kCoapUdpPort);
SuccessOrExit(error = netif.GetCoap().SendMessage(*message, messageInfo));
otLogInfoMeshCoP("Sent relay rx");
exit:
if (error != OT_ERROR_NONE && message != NULL)
{
message->Free();
}
}
示例3: SendRequest
otError AnnounceBeginClient::SendRequest(uint32_t aChannelMask, uint8_t aCount, uint16_t aPeriod,
const Ip6::Address &aAddress)
{
otError error = OT_ERROR_NONE;
Coap::Header header;
MeshCoP::CommissionerSessionIdTlv sessionId;
MeshCoP::ChannelMask0Tlv channelMask;
MeshCoP::CountTlv count;
MeshCoP::PeriodTlv period;
Ip6::MessageInfo messageInfo;
Message *message = NULL;
VerifyOrExit(GetNetif().GetCommissioner().IsActive(), error = OT_ERROR_INVALID_STATE);
header.Init(aAddress.IsMulticast() ? OT_COAP_TYPE_NON_CONFIRMABLE : OT_COAP_TYPE_CONFIRMABLE,
OT_COAP_CODE_POST);
header.SetToken(Coap::Header::kDefaultTokenLength);
header.AppendUriPathOptions(OT_URI_PATH_ANNOUNCE_BEGIN);
header.SetPayloadMarker();
VerifyOrExit((message = MeshCoP::NewMeshCoPMessage(GetNetif().GetCoap(), header)) != NULL,
error = OT_ERROR_NO_BUFS);
sessionId.Init();
sessionId.SetCommissionerSessionId(GetNetif().GetCommissioner().GetSessionId());
SuccessOrExit(error = message->Append(&sessionId, sizeof(sessionId)));
channelMask.Init();
channelMask.SetMask(aChannelMask);
SuccessOrExit(error = message->Append(&channelMask, sizeof(channelMask)));
count.Init();
count.SetCount(aCount);
SuccessOrExit(error = message->Append(&count, sizeof(count)));
period.Init();
period.SetPeriod(aPeriod);
SuccessOrExit(error = message->Append(&period, sizeof(period)));
messageInfo.SetSockAddr(GetNetif().GetMle().GetMeshLocal16());
messageInfo.SetPeerAddr(aAddress);
messageInfo.SetPeerPort(kCoapUdpPort);
messageInfo.SetInterfaceId(GetNetif().GetInterfaceId());
SuccessOrExit(error = GetNetif().GetCoap().SendMessage(*message, messageInfo));
otLogInfoMeshCoP(GetInstance(), "sent announce begin query");
exit:
if (error != OT_ERROR_NONE && message != NULL)
{
message->Free();
}
return error;
}
示例4: SendQuery
otError PanIdQueryClient::SendQuery(uint16_t aPanId, uint32_t aChannelMask, const Ip6::Address &aAddress,
otCommissionerPanIdConflictCallback aCallback, void *aContext)
{
ThreadNetif &netif = GetNetif();
otError error = OT_ERROR_NONE;
Coap::Header header;
MeshCoP::CommissionerSessionIdTlv sessionId;
MeshCoP::ChannelMask0Tlv channelMask;
MeshCoP::PanIdTlv panId;
Ip6::MessageInfo messageInfo;
Message *message = NULL;
VerifyOrExit(netif.GetCommissioner().IsActive(), error = OT_ERROR_INVALID_STATE);
header.Init(aAddress.IsMulticast() ? OT_COAP_TYPE_NON_CONFIRMABLE : OT_COAP_TYPE_CONFIRMABLE,
OT_COAP_CODE_POST);
header.SetToken(Coap::Header::kDefaultTokenLength);
header.AppendUriPathOptions(OT_URI_PATH_PANID_QUERY);
header.SetPayloadMarker();
VerifyOrExit((message = MeshCoP::NewMeshCoPMessage(netif.GetCoap(), header)) != NULL,
error = OT_ERROR_NO_BUFS);
sessionId.Init();
sessionId.SetCommissionerSessionId(netif.GetCommissioner().GetSessionId());
SuccessOrExit(error = message->Append(&sessionId, sizeof(sessionId)));
channelMask.Init();
channelMask.SetMask(aChannelMask);
SuccessOrExit(error = message->Append(&channelMask, sizeof(channelMask)));
panId.Init();
panId.SetPanId(aPanId);
SuccessOrExit(error = message->Append(&panId, sizeof(panId)));
messageInfo.SetSockAddr(netif.GetMle().GetMeshLocal16());
messageInfo.SetPeerAddr(aAddress);
messageInfo.SetPeerPort(kCoapUdpPort);
messageInfo.SetInterfaceId(netif.GetInterfaceId());
SuccessOrExit(error = netif.GetCoap().SendMessage(*message, messageInfo));
otLogInfoMeshCoP(GetInstance(), "sent panid query");
mCallback = aCallback;
mContext = aContext;
exit:
if (error != OT_ERROR_NONE && message != NULL)
{
message->Free();
}
return error;
}
示例5: SendReport
otError EnergyScanServer::SendReport(void)
{
otError error = OT_ERROR_NONE;
Coap::Header header;
MeshCoP::ChannelMask0Tlv channelMask;
MeshCoP::EnergyListTlv energyList;
Ip6::MessageInfo messageInfo;
Message * message;
header.Init(OT_COAP_TYPE_CONFIRMABLE, OT_COAP_CODE_POST);
header.SetToken(Coap::Header::kDefaultTokenLength);
header.AppendUriPathOptions(OT_URI_PATH_ENERGY_REPORT);
header.SetPayloadMarker();
VerifyOrExit((message = MeshCoP::NewMeshCoPMessage(GetNetif().GetCoap(), header)) != NULL,
error = OT_ERROR_NO_BUFS);
channelMask.Init();
channelMask.SetMask(mChannelMask);
SuccessOrExit(error = message->Append(&channelMask, sizeof(channelMask)));
energyList.Init();
energyList.SetLength(mScanResultsLength);
SuccessOrExit(error = message->Append(&energyList, sizeof(energyList)));
SuccessOrExit(error = message->Append(mScanResults, mScanResultsLength));
messageInfo.SetSockAddr(GetNetif().GetMle().GetMeshLocal16());
messageInfo.SetPeerAddr(mCommissioner);
messageInfo.SetPeerPort(kCoapUdpPort);
SuccessOrExit(error = GetNetif().GetCoap().SendMessage(*message, messageInfo));
otLogInfoMeshCoP(GetInstance(), "sent scan results");
exit:
if (error != OT_ERROR_NONE && message != NULL)
{
message->Free();
}
mActive = false;
return error;
}
示例6: Register
ThreadError DatasetManager::Register(void)
{
ThreadError error = kThreadError_None;
Coap::Header header;
Message *message;
Ip6::Address leader;
Ip6::MessageInfo messageInfo;
header.Init(kCoapTypeConfirmable, kCoapRequestPost);
header.SetToken(Coap::Header::kDefaultTokenLength);
header.AppendUriPathOptions(mUriSet);
header.SetPayloadMarker();
if (strcmp(mUriSet, OPENTHREAD_URI_PENDING_SET) == 0)
{
PendingDatasetBase *pending = static_cast<PendingDatasetBase *>(this);
pending->UpdateDelayTimer();
}
VerifyOrExit((message = mNetif.GetCoapClient().NewMeshCoPMessage(header)) != NULL, error = kThreadError_NoBufs);
SuccessOrExit(error = message->Append(mLocal.GetBytes(), mLocal.GetSize()));
mNetif.GetMle().GetLeaderAloc(leader);
messageInfo.SetPeerAddr(leader);
messageInfo.SetPeerPort(kCoapUdpPort);
SuccessOrExit(error = mNetif.GetCoapClient().SendMessage(*message, messageInfo));
otLogInfoMeshCoP("sent dataset to leader");
exit:
if (error != kThreadError_None && message != NULL)
{
message->Free();
}
return error;
}
示例7: otUdpProxyReceive
void otUdpProxyReceive(otInstance * aInstance,
otMessage * aMessage,
uint16_t aPeerPort,
const otIp6Address *aPeerAddr,
uint16_t aSockPort)
{
Ip6::MessageInfo messageInfo;
Instance & instance = *static_cast<Instance *>(aInstance);
Ip6::Ip6 & ip6 = instance.Get<Ip6::Ip6>();
assert(aMessage != NULL && aPeerAddr != NULL);
messageInfo.SetSockAddr(instance.GetThreadNetif().GetMle().GetMeshLocal16());
messageInfo.SetSockPort(aSockPort);
messageInfo.SetPeerAddr(*static_cast<const ot::Ip6::Address *>(aPeerAddr));
messageInfo.SetPeerPort(aPeerPort);
messageInfo.SetInterfaceId(OT_NETIF_INTERFACE_ID_HOST);
ip6.GetUdp().HandlePayload(*static_cast<ot::Message *>(aMessage), messageInfo);
static_cast<ot::Message *>(aMessage)->Free();
}
示例8: SendQuery
otError EnergyScanClient::SendQuery(uint32_t aChannelMask,
uint8_t aCount,
uint16_t aPeriod,
uint16_t aScanDuration,
const Ip6::Address & aAddress,
otCommissionerEnergyReportCallback aCallback,
void * aContext)
{
ThreadNetif & netif = GetNetif();
otError error = OT_ERROR_NONE;
MeshCoP::CommissionerSessionIdTlv sessionId;
MeshCoP::ChannelMaskTlv channelMask;
MeshCoP::CountTlv count;
MeshCoP::PeriodTlv period;
MeshCoP::ScanDurationTlv scanDuration;
Ip6::MessageInfo messageInfo;
Coap::Message * message = NULL;
VerifyOrExit(netif.GetCommissioner().IsActive(), error = OT_ERROR_INVALID_STATE);
VerifyOrExit((message = MeshCoP::NewMeshCoPMessage(netif.GetCoap())) != NULL, error = OT_ERROR_NO_BUFS);
message->Init(aAddress.IsMulticast() ? OT_COAP_TYPE_NON_CONFIRMABLE : OT_COAP_TYPE_CONFIRMABLE, OT_COAP_CODE_POST);
message->SetToken(Coap::Message::kDefaultTokenLength);
message->AppendUriPathOptions(OT_URI_PATH_ENERGY_SCAN);
message->SetPayloadMarker();
sessionId.Init();
sessionId.SetCommissionerSessionId(netif.GetCommissioner().GetSessionId());
SuccessOrExit(error = message->Append(&sessionId, sizeof(sessionId)));
channelMask.Init();
channelMask.SetChannelPage(OT_RADIO_CHANNEL_PAGE);
channelMask.SetMask(aChannelMask);
SuccessOrExit(error = message->Append(&channelMask, sizeof(channelMask)));
count.Init();
count.SetCount(aCount);
SuccessOrExit(error = message->Append(&count, sizeof(count)));
period.Init();
period.SetPeriod(aPeriod);
SuccessOrExit(error = message->Append(&period, sizeof(period)));
scanDuration.Init();
scanDuration.SetScanDuration(aScanDuration);
SuccessOrExit(error = message->Append(&scanDuration, sizeof(scanDuration)));
messageInfo.SetSockAddr(netif.GetMle().GetMeshLocal16());
messageInfo.SetPeerAddr(aAddress);
messageInfo.SetPeerPort(kCoapUdpPort);
messageInfo.SetInterfaceId(netif.GetInterfaceId());
SuccessOrExit(error = netif.GetCoap().SendMessage(*message, messageInfo));
otLogInfoMeshCoP("sent energy scan query");
mCallback = aCallback;
mContext = aContext;
exit:
if (error != OT_ERROR_NONE && message != NULL)
{
message->Free();
}
return error;
}
示例9: HandleRetransmissionTimer
void Client::HandleRetransmissionTimer(void)
{
uint32_t now = otPlatAlarmGetNow();
uint32_t nextDelta = 0xffffffff;
RequestMetadata requestMetadata;
Message *message = mPendingRequests.GetHead();
Message *nextMessage = NULL;
Ip6::MessageInfo messageInfo;
while (message != NULL)
{
nextMessage = message->GetNext();
requestMetadata.ReadFrom(*message);
if (requestMetadata.IsLater(now))
{
// Calculate the next delay and choose the lowest.
if (requestMetadata.mNextTimerShot - now < nextDelta)
{
nextDelta = requestMetadata.mNextTimerShot - now;
}
}
else if ((requestMetadata.mConfirmable) &&
(requestMetadata.mRetransmissionCount < kMaxRetransmit))
{
// Increment retransmission counter and timer.
requestMetadata.mRetransmissionCount++;
requestMetadata.mRetransmissionTimeout *= 2;
requestMetadata.mNextTimerShot = now + requestMetadata.mRetransmissionTimeout;
requestMetadata.UpdateIn(*message);
// Check if retransmission time is lower than current lowest.
if (requestMetadata.mRetransmissionTimeout < nextDelta)
{
nextDelta = requestMetadata.mRetransmissionTimeout;
}
// Retransmit
if (!requestMetadata.mAcknowledged)
{
messageInfo.SetPeerAddr(requestMetadata.mDestinationAddress);
messageInfo.SetPeerPort(requestMetadata.mDestinationPort);
messageInfo.SetSockAddr(requestMetadata.mSourceAddress);
SendCopy(*message, messageInfo);
}
}
else
{
// No expected response or acknowledgment.
FinalizeCoapTransaction(*message, requestMetadata, NULL, NULL, NULL, kThreadError_ResponseTimeout);
}
message = nextMessage;
}
if (nextDelta != 0xffffffff)
{
mRetransmissionTimer.Start(nextDelta);
}
}