tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

nsNetworkLinkService.h (2842B)


      1 /* This Source Code Form is subject to the terms of the Mozilla Public
      2 * License, v. 2.0. If a copy of the MPL was not distributed with this
      3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
      4 
      5 #ifndef NSNETWORKLINKSERVICEMAC_H_
      6 #define NSNETWORKLINKSERVICEMAC_H_
      7 
      8 #include "nsINetworkLinkService.h"
      9 #include "nsIObserver.h"
     10 #include "nsITimer.h"
     11 #include "nsString.h"
     12 #include "mozilla/Mutex.h"
     13 #include "mozilla/SHA1.h"
     14 
     15 #include <netinet/in.h>
     16 #include <SystemConfiguration/SCNetworkReachability.h>
     17 #include <SystemConfiguration/SystemConfiguration.h>
     18 
     19 using prefix_and_netmask = std::pair<in6_addr, in6_addr>;
     20 
     21 class nsNetworkLinkService : public nsINetworkLinkService,
     22                             public nsIObserver,
     23                             public nsITimerCallback,
     24                             public nsINamed {
     25 public:
     26  NS_DECL_THREADSAFE_ISUPPORTS
     27  NS_DECL_NSINETWORKLINKSERVICE
     28  NS_DECL_NSIOBSERVER
     29  NS_DECL_NSITIMERCALLBACK
     30  NS_DECL_NSINAMED
     31 
     32  nsNetworkLinkService();
     33 
     34  nsresult Init();
     35  nsresult Shutdown();
     36 
     37  static void HashSortedPrefixesAndNetmasks(
     38      std::vector<prefix_and_netmask> prefixAndNetmaskStore,
     39      mozilla::SHA1Sum* sha1);
     40 
     41 protected:
     42  virtual ~nsNetworkLinkService();
     43 
     44 private:
     45  bool mLinkUp;
     46  bool mStatusKnown;
     47 
     48  SCNetworkReachabilityRef mReachability;
     49  CFRunLoopRef mCFRunLoop;
     50  CFRunLoopSourceRef mRunLoopSource;
     51  SCDynamicStoreRef mStoreRef;
     52 
     53  bool IPv4NetworkId(mozilla::SHA1Sum* sha1);
     54  bool IPv6NetworkId(mozilla::SHA1Sum* sha1);
     55 
     56  void UpdateReachability();
     57  void OnIPConfigChanged();
     58  void OnNetworkIdChanged();
     59  void OnReachabilityChanged();
     60  void NotifyObservers(const char* aTopic, const char* aData);
     61  static void ReachabilityChanged(SCNetworkReachabilityRef target,
     62                                  SCNetworkConnectionFlags flags, void* info);
     63  static void NetworkConfigChanged(SCDynamicStoreRef store,
     64                                   CFArrayRef changedKeys, void* info);
     65  void calculateNetworkIdWithDelay(uint32_t aDelay);
     66  void calculateNetworkIdInternal(void);
     67  void DNSConfigChanged(uint32_t aDelayMs);
     68  void GetDnsSuffixListInternal();
     69  bool RoutingFromKernel(nsTArray<nsCString>& aHash);
     70  bool RoutingTable(nsTArray<nsCString>& aHash);
     71 
     72  mozilla::Mutex mMutex MOZ_UNANNOTATED;
     73  nsCString mNetworkId;
     74  nsTArray<nsCString> mDNSSuffixList;
     75 
     76  // The timer used to delay the calculation of network id since it takes some
     77  // time to discover the gateway's MAC address.
     78  nsCOMPtr<nsITimer> mNetworkIdTimer;
     79 
     80  // Scheduled timers used to delay querying of the DNS suffix list when
     81  // triggered by a network change. Guarded by mMutex.
     82  nsTArray<nsCOMPtr<nsITimer>> mDNSConfigChangedTimers;
     83 
     84  // IP address used to check the route for public traffic.
     85  struct in_addr mRouteCheckIPv4;
     86 };
     87 
     88 #endif /* NSNETWORKLINKSERVICEMAC_H_ */