media/mtransport/nriceresolverfake.h

Tue, 06 Jan 2015 21:39:09 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Tue, 06 Jan 2015 21:39:09 +0100
branch
TOR_BUG_9701
changeset 8
97036ab72558
permissions
-rw-r--r--

Conditionally force memory storage according to privacy.thirdparty.isolate;
This solves Tor bug #9701, complying with disk avoidance documented in
https://www.torproject.org/projects/torbrowser/design/#disk-avoidance.

     1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
     2 /* vim: set ts=2 et sw=2 tw=80: */
     3 /* This Source Code Form is subject to the terms of the Mozilla Public
     4  * License, v. 2.0. If a copy of the MPL was not distributed with this file,
     5  * You can obtain one at http://mozilla.org/MPL/2.0/. */
     8 // Original author: ekr@rtfm.com
    10 // Some of this code is cut-and-pasted from nICEr. Copyright is:
    12 /*
    13 Copyright (c) 2007, Adobe Systems, Incorporated
    14 All rights reserved.
    16 Redistribution and use in source and binary forms, with or without
    17 modification, are permitted provided that the following conditions are
    18 met:
    20 * Redistributions of source code must retain the above copyright
    21   notice, this list of conditions and the following disclaimer.
    23 * Redistributions in binary form must reproduce the above copyright
    24   notice, this list of conditions and the following disclaimer in the
    25   documentation and/or other materials provided with the distribution.
    27 * Neither the name of Adobe Systems, Network Resonance nor the names of its
    28   contributors may be used to endorse or promote products derived from
    29   this software without specific prior written permission.
    31 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
    32 "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
    33 LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
    34 A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
    35 OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
    36 SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
    37 LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
    38 DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
    39 THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
    40 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
    41 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
    42 */
    44 #ifndef nriceresolverfake_h__
    45 #define nriceresolverfake_h__
    47 #include <map>
    48 #include <string>
    50 #include "nspr.h"
    51 #include "prnetdb.h"
    52 #include "mozilla/NullPtr.h"
    54 typedef struct nr_resolver_ nr_resolver;
    55 typedef struct nr_resolver_vtbl_ nr_resolver_vtbl;
    56 typedef struct nr_transport_addr_ nr_transport_addr;
    57 typedef struct nr_resolver_resource_ nr_resolver_resource;
    59 namespace mozilla {
    61 class NrIceResolverFake {
    62  public:
    63   NrIceResolverFake();
    64   ~NrIceResolverFake();
    66   void SetAddr(const std::string& hostname, const PRNetAddr& addr) {
    67     addrs_[hostname] = addr;
    68   }
    70   nr_resolver *AllocateResolver();
    72   void DestroyResolver();
    74 private:
    75   // Implementations of vtbl functions
    76   static int destroy(void **objp);
    77   static int resolve(void *obj,
    78                      nr_resolver_resource *resource,
    79                      int (*cb)(void *cb_arg,
    80                                nr_transport_addr *addr),
    81                      void *cb_arg,
    82                      void **handle);
    83   static void resolve_cb(NR_SOCKET s, int how, void *cb_arg);
    84   static int cancel(void *obj, void *handle);
    86   // Get an address.
    87   const PRNetAddr *Resolve(const std::string& hostname) {
    88     if (!addrs_.count(hostname))
    89       return nullptr;
    91     return &addrs_[hostname];
    92   }
    95   struct PendingResolution {
    96     PendingResolution(NrIceResolverFake *resolver,
    97                       const std::string& hostname,
    98                       uint16_t port,
    99                       int transport,
   100                       int (*cb)(void *cb_arg, nr_transport_addr *addr),
   101                       void *cb_arg) :
   102         resolver_(resolver),
   103         hostname_(hostname),
   104         port_(port),
   105         transport_(transport),
   106         cb_(cb), cb_arg_(cb_arg) {}
   108     NrIceResolverFake *resolver_;
   109     std::string hostname_;
   110     uint16_t port_;
   111     int transport_;
   112     int (*cb_)(void *cb_arg, nr_transport_addr *addr);
   113     void *cb_arg_;
   114     void *timer_handle_;
   115   };
   117   nr_resolver_vtbl* vtbl_;
   118   std::map<std::string, PRNetAddr> addrs_;
   119   uint32_t delay_ms_;
   120   int allocated_resolvers_;
   121 };
   123 }  // End of namespace mozilla
   125 #endif

mercurial