tor  0.4.0.0-alpha-dev
routerinfo.c
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-2018, The Tor Project, Inc. */
5 /* See LICENSE for licensing information */
6 
7 #include "core/or/or.h"
8 
11 
12 #include "feature/nodelist/node_st.h"
13 #include "feature/nodelist/routerinfo_st.h"
14 
17 void
19 {
20  tor_assert(ap_out != NULL);
21  tor_addr_from_ipv4h(&ap_out->addr, router->addr);
22  ap_out->port = router->or_port;
23 }
24 
25 int
26 router_has_orport(const routerinfo_t *router, const tor_addr_port_t *orport)
27 {
28  return
29  (tor_addr_eq_ipv4h(&orport->addr, router->addr) &&
30  orport->port == router->or_port) ||
31  (tor_addr_eq(&orport->addr, &router->ipv6_addr) &&
32  orport->port == router->ipv6_orport);
33 }
34 
40 {
41  tor_assert(ri);
42  node_t fake_node;
43  memset(&fake_node, 0, sizeof(fake_node));
44  /* we don't modify ri, fake_node is passed as a const node_t *
45  */
46  fake_node.ri = (routerinfo_t *)ri;
47  return node_get_all_orports(&fake_node);
48 }
49 
53 const char *
55 {
56  switch (p)
57  {
58  case ROUTER_PURPOSE_GENERAL: return "general";
59  case ROUTER_PURPOSE_BRIDGE: return "bridge";
60  case ROUTER_PURPOSE_CONTROLLER: return "controller";
61  default:
62  tor_assert(0);
63  }
64  return NULL;
65 }
66 
68 uint8_t
70 {
71  if (!strcmp(s, "general"))
72  return ROUTER_PURPOSE_GENERAL;
73  else if (!strcmp(s, "bridge"))
74  return ROUTER_PURPOSE_BRIDGE;
75  else if (!strcmp(s, "controller"))
76  return ROUTER_PURPOSE_CONTROLLER;
77  else
78  return ROUTER_PURPOSE_UNKNOWN;
79 }
const char * router_purpose_to_string(uint8_t p)
Definition: routerinfo.c:54
Definition: node_st.h:28
static int tor_addr_eq_ipv4h(const tor_addr_t *a, uint32_t u)
Definition: address.h:193
Header file for nodelist.c.
tor_assert(buffer)
#define tor_addr_from_ipv4h(dest, v4addr)
Definition: address.h:287
uint8_t router_purpose_from_string(const char *s)
Definition: routerinfo.c:69
Master header file for Tor-specific functionality.
smartlist_t * router_get_all_orports(const routerinfo_t *ri)
Definition: routerinfo.c:39
void router_get_prim_orport(const routerinfo_t *router, tor_addr_port_t *addr_port_out)
Definition: routerinfo.c:18
smartlist_t * node_get_all_orports(const node_t *node)
Definition: nodelist.c:1398
#define tor_addr_eq(a, b)
Definition: address.h:244
uint32_t addr
Definition: routerinfo_st.h:19
tor_addr_t ipv6_addr
Definition: routerinfo_st.h:27
Header file for routerinfo.c.
uint16_t or_port
Definition: routerinfo_st.h:20