diff options
author | Nick Mathewson <nickm@torproject.org> | 2018-09-25 17:22:14 -0400 |
---|---|---|
committer | Nick Mathewson <nickm@torproject.org> | 2018-09-25 17:22:14 -0400 |
commit | 3ff58e47d211d8649202c093f00934011effed1b (patch) | |
tree | 1243e4e4107a17a793c24a0b20691a10000d1a9d /src/core | |
parent | b8df2318e9531a17938392cd0cbea0b901f50245 (diff) | |
download | tor-3ff58e47d211d8649202c093f00934011effed1b.tar.gz tor-3ff58e47d211d8649202c093f00934011effed1b.zip |
Move the "is the network disabled?" functions out of router.c
Since this is completely core functionality, I'm putting it in
core/mainloop, even though it depends on feature/hibernate. We'll
have to sort that out in the future.
Diffstat (limited to 'src/core')
-rw-r--r-- | src/core/include.am | 2 | ||||
-rw-r--r-- | src/core/mainloop/netstatus.c | 28 | ||||
-rw-r--r-- | src/core/mainloop/netstatus.h | 13 |
3 files changed, 43 insertions, 0 deletions
diff --git a/src/core/include.am b/src/core/include.am index 21cad6dc24..64a593ca51 100644 --- a/src/core/include.am +++ b/src/core/include.am @@ -20,6 +20,7 @@ LIBTOR_APP_A_SOURCES = \ src/core/mainloop/connection.c \ src/core/mainloop/cpuworker.c \ src/core/mainloop/mainloop.c \ + src/core/mainloop/netstatus.c \ src/core/mainloop/periodic.c \ src/core/or/address_set.c \ src/core/or/channel.c \ @@ -187,6 +188,7 @@ noinst_HEADERS += \ src/core/mainloop/connection.h \ src/core/mainloop/cpuworker.h \ src/core/mainloop/mainloop.h \ + src/core/mainloop/netstatus.h \ src/core/mainloop/periodic.h \ src/core/or/addr_policy_st.h \ src/core/or/address_set.h \ diff --git a/src/core/mainloop/netstatus.c b/src/core/mainloop/netstatus.c new file mode 100644 index 0000000000..f026474494 --- /dev/null +++ b/src/core/mainloop/netstatus.c @@ -0,0 +1,28 @@ +/* Copyright (c) 2001 Matej Pfajfar. + * Copyright (c) 2001-2004, Roger Dingledine. + * Copyright (c) 2004-2006, Roger Dingledine, Nick Mathewson. + * Copyright (c) 2007-2018, The Tor Project, Inc. */ +/* See LICENSE for licensing information */ + +#include "core/or/or.h" +#include "core/mainloop/netstatus.h" +#include "app/config/config.h" +#include "feature/hibernate/hibernate.h" + +/** Return true iff our network is in some sense disabled or shutting down: + * either we're hibernating, entering hibernation, or the network is turned + * off with DisableNetwork. */ +int +net_is_disabled(void) +{ + return get_options()->DisableNetwork || we_are_hibernating(); +} + +/** Return true iff our network is in some sense "completely disabled" either + * we're fully hibernating or the network is turned off with + * DisableNetwork. */ +int +net_is_completely_disabled(void) +{ + return get_options()->DisableNetwork || we_are_fully_hibernating(); +} diff --git a/src/core/mainloop/netstatus.h b/src/core/mainloop/netstatus.h new file mode 100644 index 0000000000..e9310c2929 --- /dev/null +++ b/src/core/mainloop/netstatus.h @@ -0,0 +1,13 @@ +/* Copyright (c) 2001 Matej Pfajfar. + * Copyright (c) 2001-2004, Roger Dingledine. + * Copyright (c) 2004-2006, Roger Dingledine, Nick Mathewson. + * Copyright (c) 2007-2018, The Tor Project, Inc. */ +/* See LICENSE for licensing information */ + +#ifndef TOR_NETSTATUS_H +#define TOR_NETSTATUS_H + +int net_is_disabled(void); +int net_is_completely_disabled(void); + +#endif |