Use nonce in data messages to de-dupe SendData API. (#3366)

* Use nonce in data messages to de-dupe SendData API.

With API retries, it is possible that some data messages are sent
multiple times. Check the nonce (if present) to de-dupe data messages
before forwarding it to the clients.

* add nonce to UserPacket

* defer unlock

* 128-bit UUID as nonce

* - UUID nonce
- make a UserPacketDeduper module for easier re-use.

* deps

* feedback
This commit is contained in:
Raja Subramanian
2025-01-27 15:35:37 +05:30
committed by GitHub
parent 30669722c3
commit db75092aa6
8 changed files with 184 additions and 26 deletions
+1
View File
@@ -822,6 +822,7 @@ func (r *RoomManager) SendData(ctx context.Context, req *livekit.SendDataRequest
DestinationSids: req.DestinationSids,
DestinationIdentities: req.DestinationIdentities,
Topic: req.Topic,
Nonce: req.Nonce,
},
},
}, req.Kind)
+5
View File
@@ -234,6 +234,11 @@ func (s *RoomService) SendData(ctx context.Context, req *livekit.SendDataRequest
return nil, twirpAuthError(err)
}
// nonce is either absent or 128-bit UUID
if len(req.Nonce) != 8 && len(req.Nonce) != 16 {
return nil, twirp.NewError(twirp.InvalidArgument, fmt.Sprintf("nonce should be 16-bytes or not present, got: %d bytes", len(req.Nonce)))
}
return s.roomClient.SendData(ctx, s.topicFormatter.RoomTopic(ctx, livekit.RoomName(req.Room)), req)
}