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:
@@ -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)
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user