• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2019 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
5 #include "osp/public/endpoint_request_ids.h"
6 
7 namespace openscreen {
8 namespace osp {
9 
EndpointRequestIds(Role role)10 EndpointRequestIds::EndpointRequestIds(Role role) : role_(role) {}
11 EndpointRequestIds::~EndpointRequestIds() = default;
12 
GetNextRequestId(uint64_t endpoint_id)13 uint64_t EndpointRequestIds::GetNextRequestId(uint64_t endpoint_id) {
14   uint64_t& next_request_id = request_ids_by_endpoint_id_[endpoint_id];
15   uint64_t request_id = next_request_id + (role_ == Role::kServer);
16   next_request_id += 2;
17   return request_id;
18 }
19 
ResetRequestId(uint64_t endpoint_id)20 void EndpointRequestIds::ResetRequestId(uint64_t endpoint_id) {
21   // TODO(crbug.com/openscreen/42): Consider using a timeout to drop the request
22   // id counter, and/or possibly set the initial value as part of the handshake.
23   request_ids_by_endpoint_id_.erase(endpoint_id);
24 }
25 
Reset()26 void EndpointRequestIds::Reset() {
27   request_ids_by_endpoint_id_.clear();
28 }
29 
30 }  // namespace osp
31 }  // namespace openscreen
32