mirror of
https://github.com/obgm/libcoap.git
synced 2026-11-22 07:15:14 +03:00
mcast_ips: Restore mcast ip for mcast sessions for each new coap_send()
If the server is responding to a mcast request with a packet that is a part of larger body (i.e. responding with Block2 option) the requests for the missing packets have to be using unicast, which continues to be supported. The application can determine the unicast remote address before the next coap_send() by using coap_session_get_addr_remote(). Add in a new function coap_session_get_addr_mcast() to get the mcast IP if the client session was set up to talk to a mcast address.
This commit is contained in:
1 parent
46aa5760ee
commit
3ebbcde43a
9 files changed
+107
-29
No files matched your search
@@ -287,6 +287,7 @@ coap_socket_connect_udp(coap_socket_t *sock,
|
||||
coap_socket_strerror());
|
||||
}
|
||||
coap_address_copy(remote_addr, &connect_addr);
|
||||
coap_address_copy(&sock->mcast_addr, &connect_addr);
|
||||
sock->flags |= COAP_SOCKET_MULTICAST;
|
||||
return 1;
|
||||
}
|
||||
|
||||
+19
-3
@@ -1360,6 +1360,18 @@ coap_session_get_addr_local(const coap_session_t *session) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
const coap_address_t *
|
||||
coap_session_get_addr_mcast(const coap_session_t *session) {
|
||||
#if COAP_CLIENT_SUPPORT
|
||||
if (session && session->type == COAP_SESSION_TYPE_CLIENT &&
|
||||
session->sock.flags & COAP_SOCKET_MULTICAST)
|
||||
return &session->sock.mcast_addr;
|
||||
#else /* ! COAP_CLIENT_SUPPORT */
|
||||
(void)session;
|
||||
#endif /* ! COAP_CLIENT_SUPPORT */
|
||||
return NULL;
|
||||
}
|
||||
|
||||
coap_context_t *
|
||||
coap_session_get_context(const coap_session_t *session) {
|
||||
if (session)
|
||||
@@ -1581,9 +1593,13 @@ coap_session_get_by_peer(const coap_context_t *ctx,
|
||||
coap_session_t *s, *rtmp;
|
||||
#if COAP_CLIENT_SUPPORT
|
||||
SESSIONS_ITER(ctx->sessions, s, rtmp) {
|
||||
if (s->ifindex == ifindex && coap_address_equals(&s->addr_info.remote,
|
||||
remote_addr))
|
||||
return s;
|
||||
if (s->ifindex == ifindex) {
|
||||
if (s->sock.flags & COAP_SOCKET_MULTICAST) {
|
||||
if (coap_address_equals(&s->sock.mcast_addr, remote_addr))
|
||||
return s;
|
||||
} else if (coap_address_equals(&s->addr_info.remote, remote_addr))
|
||||
return s;
|
||||
}
|
||||
}
|
||||
#endif /* COAP_CLIENT_SUPPORT */
|
||||
#if COAP_SERVER_SUPPORT
|
||||
|
||||
@@ -1208,6 +1208,8 @@ coap_send(coap_session_t *session, coap_pdu_t *pdu) {
|
||||
lg_xmit->b.b1.state_token = lg_crcv->state_token;
|
||||
}
|
||||
}
|
||||
if (session->sock.flags & COAP_SOCKET_MULTICAST)
|
||||
coap_address_copy(&session->addr_info.remote, &session->sock.mcast_addr);
|
||||
|
||||
send_it:
|
||||
#endif /* COAP_CLIENT_SUPPORT */
|
||||
|
||||
Reference in new issue
Block a user