summaryrefslogtreecommitdiff
path: root/discovered_peer.h
blob: ac92b326662aa16826f910430e08220c1d8daafc (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
// Copyright 2014 The Chromium OS Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef PEERD_DISCOVERED_PEER_H_
#define PEERD_DISCOVERED_PEER_H_

#include <map>
#include <string>

#include <base/time/time.h>

#include "peerd/peer.h"
#include "peerd/technologies.h"

namespace peerd {

class DiscoveredPeer : public Peer {
 public:
  DiscoveredPeer(const scoped_refptr<dbus::Bus>& bus,
                 chromeos::dbus_utils::ExportedObjectManager* object_manager,
                 const dbus::ObjectPath& path,
                 technologies::Technology technology);
  ~DiscoveredPeer() override = default;

  // Update |this| with the most recent time |last_seen|.  Note that if
  // |last_seen| is older than the current value we'll discard this
  // advertisement.  Remember that we've seen this peer on the given
  // |technology|.
  virtual void UpdateFromAdvertisement(const base::Time& last_seen,
                                       technologies::Technology technology);
  // Add or update an existing service, and record that we've seen it
  // on the given |technology|.  Note that if the service has been updated
  // more recently than |last_seen|, we'll discard this update.  Remember that
  // we've seen advertisements on |technology| for the given service, and the
  // peer itself.  Updates peer |last_seen| if more recent that the last
  // update.
  virtual void UpdateService(const std::string& service_id,
                             const Service::IpAddresses& addresses,
                             const Service::ServiceInfo& info,
                             const base::Time& last_seen,
                             technologies::Technology technology);
  // Remove knowledge that we were seen on the given technology from |this|
  // and child services.
  virtual void RemoveTechnology(technologies::Technology technology);
  // Remove knowledge that a service was seen on |technology| from service.
  // Removes the service if no remaining technologies claim to have seen it.
  virtual void RemoveTechnologyFromService(const std::string& service_id,
                                           technologies::Technology technology);
  // Returns the number of technologies that we've seen this peer, or child
  // services have been updated over.
  virtual size_t GetTechnologyCount() const;

 private:
  struct ServiceMetadata {
    technologies::TechnologySet technology;
    base::Time last_seen;
  };
  std::map<std::string, ServiceMetadata> service_metadata_;
  technologies::TechnologySet discovered_on_technologies_;

  friend class DiscoveredPeerTest;
  DISALLOW_COPY_AND_ASSIGN(DiscoveredPeer);
};

}  // namespace peerd

#endif  // PEERD_DISCOVERED_PEER_H_