Coverage Report

Created: 2026-08-31 06:56

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/tor/src/feature/relay/routermode.c
Line
Count
Source
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
0
{
25
0
  if (!options->DirCache)
26
0
    return 0;
27
0
  return options->DirPort_set ||
28
0
    (server_mode(options) && router_has_bandwidth_to_be_dirserver(options));
29
0
}
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
0
{
36
0
  if (options->ClientOnly) return 0;
37
0
  return (options->ORPort_set);
38
0
}
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
0
{
45
0
  if (!server_mode(options)) return 0;
46
0
  return (!options->BridgeRelay);
47
0
}
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
0
{
57
0
  return server_is_advertised;
58
0
}
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
0
{
67
0
  server_is_advertised = s;
68
0
}