blob: 1d695a09279702a37852a6dd7e50ba166cb70a48 [file] [log] [blame]
// 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.
#include <map>
#include <string>
#include <base/time/time.h>
#include "peerd/peer.h"
#include "peerd/technologies.h"
namespace peerd {
class DiscoveredPeer : public Peer {
DiscoveredPeer(const scoped_refptr<dbus::Bus>& bus,
brillo::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;
struct ServiceMetadata {
technologies::TechnologySet technology;
base::Time last_seen;
std::map<std::string, ServiceMetadata> service_metadata_;
technologies::TechnologySet discovered_on_technologies_;
friend class DiscoveredPeerTest;
} // namespace peerd