tor

The Tor anonymity network
git clone https://git.dasho.dev/tor.git
Log | Files | Refs | README | LICENSE

routermode.c (1674B)


      1 /* Copyright (c) 2001 Matej Pfajfar.
      2 * Copyright (c) 2001-2004, Roger Dingledine.
      3 * Copyright (c) 2004-2006, Roger Dingledine, Nick Mathewson.
      4 * Copyright (c) 2007-2021, The Tor Project, Inc. */
      5 /* See LICENSE for licensing information */
      6 
      7 /**
      8 * @file routermode.c
      9 * @brief Check if we're running as a relay/cache.
     10 **/
     11 
     12 #include "core/or/or.h"
     13 
     14 #include "app/config/config.h"
     15 #include "feature/relay/router.h"
     16 #include "feature/relay/routermode.h"
     17 
     18 /** Return 1 if we are configured to accept either relay or directory requests
     19 * from clients and we aren't at risk of exceeding our bandwidth limits, thus
     20 * we should be a directory server. If not, return 0.
     21 */
     22 int
     23 dir_server_mode(const or_options_t *options)
     24 {
     25  if (!options->DirCache)
     26    return 0;
     27  return options->DirPort_set ||
     28    (server_mode(options) && router_has_bandwidth_to_be_dirserver(options));
     29 }
     30 
     31 /** Return true iff we are trying to be a server.
     32 */
     33 MOCK_IMPL(int,
     34 server_mode,(const or_options_t *options))
     35 {
     36  if (options->ClientOnly) return 0;
     37  return (options->ORPort_set);
     38 }
     39 
     40 /** Return true iff we are trying to be a non-bridge server.
     41 */
     42 MOCK_IMPL(int,
     43 public_server_mode,(const or_options_t *options))
     44 {
     45  if (!server_mode(options)) return 0;
     46  return (!options->BridgeRelay);
     47 }
     48 
     49 /** Remember if we've advertised ourselves to the dirservers. */
     50 static int server_is_advertised=0;
     51 
     52 /** Return true iff we have published our descriptor lately.
     53 */
     54 MOCK_IMPL(int,
     55 advertised_server_mode,(void))
     56 {
     57  return server_is_advertised;
     58 }
     59 
     60 /**
     61 * Called with a boolean: set whether we have recently published our
     62 * descriptor.
     63 */
     64 void
     65 set_server_advertised(int s)
     66 {
     67  server_is_advertised = s;
     68 }