mirror of
https://gitlab.torproject.org/tpo/core/tor.git
synced 2024-11-24 12:23:32 +01:00
Move routerinfo_t functions out of router.c
(It turns out that some of the functions in router.h didn't even exist any more, so I just got to delete their declarations completely.)
This commit is contained in:
parent
efa978124f
commit
b8df2318e9
@ -97,6 +97,7 @@ LIBTOR_APP_A_SOURCES = \
|
||||
src/feature/nodelist/nodelist.c \
|
||||
src/feature/nodelist/node_select.c \
|
||||
src/feature/nodelist/parsecommon.c \
|
||||
src/feature/nodelist/routerinfo.c \
|
||||
src/feature/nodelist/routerlist.c \
|
||||
src/feature/nodelist/routerparse.c \
|
||||
src/feature/nodelist/routerset.c \
|
||||
@ -315,6 +316,7 @@ noinst_HEADERS += \
|
||||
src/feature/nodelist/nodelist.h \
|
||||
src/feature/nodelist/node_select.h \
|
||||
src/feature/nodelist/parsecommon.h \
|
||||
src/feature/nodelist/routerinfo.h \
|
||||
src/feature/nodelist/routerinfo_st.h \
|
||||
src/feature/nodelist/routerlist.h \
|
||||
src/feature/nodelist/routerlist_st.h \
|
||||
|
79
src/feature/nodelist/routerinfo.c
Normal file
79
src/feature/nodelist/routerinfo.c
Normal file
@ -0,0 +1,79 @@
|
||||
/* 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 "feature/nodelist/nodelist.h"
|
||||
#include "feature/nodelist/routerinfo.h"
|
||||
|
||||
#include "feature/nodelist/node_st.h"
|
||||
#include "feature/nodelist/routerinfo_st.h"
|
||||
|
||||
/** Copy the primary (IPv4) OR port (IP address and TCP port) for
|
||||
* <b>router</b> into *<b>ap_out</b>. */
|
||||
void
|
||||
router_get_prim_orport(const routerinfo_t *router, tor_addr_port_t *ap_out)
|
||||
{
|
||||
tor_assert(ap_out != NULL);
|
||||
tor_addr_from_ipv4h(&ap_out->addr, router->addr);
|
||||
ap_out->port = router->or_port;
|
||||
}
|
||||
|
||||
int
|
||||
router_has_orport(const routerinfo_t *router, const tor_addr_port_t *orport)
|
||||
{
|
||||
return
|
||||
(tor_addr_eq_ipv4h(&orport->addr, router->addr) &&
|
||||
orport->port == router->or_port) ||
|
||||
(tor_addr_eq(&orport->addr, &router->ipv6_addr) &&
|
||||
orport->port == router->ipv6_orport);
|
||||
}
|
||||
|
||||
/** Return a smartlist of tor_addr_port_t's with all the OR ports of
|
||||
<b>ri</b>. Note that freeing of the items in the list as well as
|
||||
the smartlist itself is the callers responsibility. */
|
||||
smartlist_t *
|
||||
router_get_all_orports(const routerinfo_t *ri)
|
||||
{
|
||||
tor_assert(ri);
|
||||
node_t fake_node;
|
||||
memset(&fake_node, 0, sizeof(fake_node));
|
||||
/* we don't modify ri, fake_node is passed as a const node_t *
|
||||
*/
|
||||
fake_node.ri = (routerinfo_t *)ri;
|
||||
return node_get_all_orports(&fake_node);
|
||||
}
|
||||
|
||||
/** Given a router purpose, convert it to a string. Don't call this on
|
||||
* ROUTER_PURPOSE_UNKNOWN: The whole point of that value is that we don't
|
||||
* know its string representation. */
|
||||
const char *
|
||||
router_purpose_to_string(uint8_t p)
|
||||
{
|
||||
switch (p)
|
||||
{
|
||||
case ROUTER_PURPOSE_GENERAL: return "general";
|
||||
case ROUTER_PURPOSE_BRIDGE: return "bridge";
|
||||
case ROUTER_PURPOSE_CONTROLLER: return "controller";
|
||||
default:
|
||||
tor_assert(0);
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/** Given a string, convert it to a router purpose. */
|
||||
uint8_t
|
||||
router_purpose_from_string(const char *s)
|
||||
{
|
||||
if (!strcmp(s, "general"))
|
||||
return ROUTER_PURPOSE_GENERAL;
|
||||
else if (!strcmp(s, "bridge"))
|
||||
return ROUTER_PURPOSE_BRIDGE;
|
||||
else if (!strcmp(s, "controller"))
|
||||
return ROUTER_PURPOSE_CONTROLLER;
|
||||
else
|
||||
return ROUTER_PURPOSE_UNKNOWN;
|
||||
}
|
27
src/feature/nodelist/routerinfo.h
Normal file
27
src/feature/nodelist/routerinfo.h
Normal file
@ -0,0 +1,27 @@
|
||||
/* 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 */
|
||||
|
||||
/**
|
||||
* \file routerinfo.h
|
||||
* \brief Header file for routerinfo.c.
|
||||
**/
|
||||
|
||||
#ifndef TOR_ROUTERINFO_H
|
||||
#define TOR_ROUTERINFO_H
|
||||
|
||||
void router_get_prim_orport(const routerinfo_t *router,
|
||||
tor_addr_port_t *addr_port_out);
|
||||
int router_has_orport(const routerinfo_t *router,
|
||||
const tor_addr_port_t *orport);
|
||||
|
||||
void router_get_verbose_nickname(char *buf, const routerinfo_t *router);
|
||||
|
||||
smartlist_t *router_get_all_orports(const routerinfo_t *ri);
|
||||
|
||||
const char *router_purpose_to_string(uint8_t p);
|
||||
uint8_t router_purpose_from_string(const char *s);
|
||||
|
||||
#endif
|
@ -2805,36 +2805,6 @@ router_dump_exit_policy_to_string(const routerinfo_t *router,
|
||||
include_ipv6);
|
||||
}
|
||||
|
||||
/** Copy the primary (IPv4) OR port (IP address and TCP port) for
|
||||
* <b>router</b> into *<b>ap_out</b>. */
|
||||
void
|
||||
router_get_prim_orport(const routerinfo_t *router, tor_addr_port_t *ap_out)
|
||||
{
|
||||
tor_assert(ap_out != NULL);
|
||||
tor_addr_from_ipv4h(&ap_out->addr, router->addr);
|
||||
ap_out->port = router->or_port;
|
||||
}
|
||||
|
||||
/** Return 1 if any of <b>router</b>'s addresses are <b>addr</b>.
|
||||
* Otherwise return 0. */
|
||||
int
|
||||
router_has_addr(const routerinfo_t *router, const tor_addr_t *addr)
|
||||
{
|
||||
return
|
||||
tor_addr_eq_ipv4h(addr, router->addr) ||
|
||||
tor_addr_eq(&router->ipv6_addr, addr);
|
||||
}
|
||||
|
||||
int
|
||||
router_has_orport(const routerinfo_t *router, const tor_addr_port_t *orport)
|
||||
{
|
||||
return
|
||||
(tor_addr_eq_ipv4h(&orport->addr, router->addr) &&
|
||||
orport->port == router->or_port) ||
|
||||
(tor_addr_eq(&orport->addr, &router->ipv6_addr) &&
|
||||
orport->port == router->ipv6_orport);
|
||||
}
|
||||
|
||||
/** Load the contents of <b>filename</b>, find the last line starting with
|
||||
* <b>end_line</b>, ensure that its timestamp is not more than 25 hours in
|
||||
* the past or more than 1 hour in the future with respect to <b>now</b>,
|
||||
@ -3115,37 +3085,6 @@ router_reset_warnings(void)
|
||||
}
|
||||
}
|
||||
|
||||
/** Given a router purpose, convert it to a string. Don't call this on
|
||||
* ROUTER_PURPOSE_UNKNOWN: The whole point of that value is that we don't
|
||||
* know its string representation. */
|
||||
const char *
|
||||
router_purpose_to_string(uint8_t p)
|
||||
{
|
||||
switch (p)
|
||||
{
|
||||
case ROUTER_PURPOSE_GENERAL: return "general";
|
||||
case ROUTER_PURPOSE_BRIDGE: return "bridge";
|
||||
case ROUTER_PURPOSE_CONTROLLER: return "controller";
|
||||
default:
|
||||
tor_assert(0);
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/** Given a string, convert it to a router purpose. */
|
||||
uint8_t
|
||||
router_purpose_from_string(const char *s)
|
||||
{
|
||||
if (!strcmp(s, "general"))
|
||||
return ROUTER_PURPOSE_GENERAL;
|
||||
else if (!strcmp(s, "bridge"))
|
||||
return ROUTER_PURPOSE_BRIDGE;
|
||||
else if (!strcmp(s, "controller"))
|
||||
return ROUTER_PURPOSE_CONTROLLER;
|
||||
else
|
||||
return ROUTER_PURPOSE_UNKNOWN;
|
||||
}
|
||||
|
||||
/** Release all static resources held in router.c */
|
||||
void
|
||||
router_free_all(void)
|
||||
@ -3171,22 +3110,6 @@ router_free_all(void)
|
||||
smartlist_free(warned_nonexistent_family);
|
||||
}
|
||||
}
|
||||
|
||||
/** Return a smartlist of tor_addr_port_t's with all the OR ports of
|
||||
<b>ri</b>. Note that freeing of the items in the list as well as
|
||||
the smartlist itself is the callers responsibility. */
|
||||
smartlist_t *
|
||||
router_get_all_orports(const routerinfo_t *ri)
|
||||
{
|
||||
tor_assert(ri);
|
||||
node_t fake_node;
|
||||
memset(&fake_node, 0, sizeof(fake_node));
|
||||
/* we don't modify ri, fake_node is passed as a const node_t *
|
||||
*/
|
||||
fake_node.ri = (routerinfo_t *)ri;
|
||||
return node_get_all_orports(&fake_node);
|
||||
}
|
||||
|
||||
/* From the given RSA key object, convert it to ASN-1 encoded format and set
|
||||
* the newly allocated object in onion_pkey_out. The length of the key is set
|
||||
* in onion_pkey_len_out. */
|
||||
|
@ -15,6 +15,7 @@
|
||||
#include "lib/testsupport/testsupport.h"
|
||||
#include "feature/nodelist/describe.h"
|
||||
#include "feature/nodelist/nickname.h"
|
||||
#include "feature/nodelist/routerinfo.h"
|
||||
|
||||
struct curve25519_keypair_t;
|
||||
struct ed25519_keypair_t;
|
||||
@ -107,16 +108,6 @@ char *router_dump_router_to_string(routerinfo_t *router,
|
||||
char *router_dump_exit_policy_to_string(const routerinfo_t *router,
|
||||
int include_ipv4,
|
||||
int include_ipv6);
|
||||
void router_get_prim_orport(const routerinfo_t *router,
|
||||
tor_addr_port_t *addr_port_out);
|
||||
void router_get_pref_orport(const routerinfo_t *router,
|
||||
tor_addr_port_t *addr_port_out);
|
||||
void router_get_pref_ipv6_orport(const routerinfo_t *router,
|
||||
tor_addr_port_t *addr_port_out);
|
||||
int router_ipv6_preferred(const routerinfo_t *router);
|
||||
int router_has_addr(const routerinfo_t *router, const tor_addr_t *addr);
|
||||
int router_has_orport(const routerinfo_t *router,
|
||||
const tor_addr_port_t *orport);
|
||||
int extrainfo_dump_to_string(char **s, extrainfo_t *extrainfo,
|
||||
crypto_pk_t *ident_key,
|
||||
const struct ed25519_keypair_t *signing_keypair);
|
||||
@ -124,16 +115,10 @@ int extrainfo_dump_to_string(char **s, extrainfo_t *extrainfo,
|
||||
const char *routerinfo_err_to_string(int err);
|
||||
int routerinfo_err_is_transient(int err);
|
||||
|
||||
void router_get_verbose_nickname(char *buf, const routerinfo_t *router);
|
||||
void router_reset_warnings(void);
|
||||
void router_reset_reachability(void);
|
||||
void router_free_all(void);
|
||||
|
||||
const char *router_purpose_to_string(uint8_t p);
|
||||
uint8_t router_purpose_from_string(const char *s);
|
||||
|
||||
smartlist_t *router_get_all_orports(const routerinfo_t *ri);
|
||||
|
||||
#ifdef ROUTER_PRIVATE
|
||||
/* Used only by router.c and test.c */
|
||||
STATIC void get_platform_str(char *platform, size_t len);
|
||||
|
Loading…
Reference in New Issue
Block a user