tor  0.4.0.1-alpha
describe.c
Go to the documentation of this file.
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-2019, The Tor Project, Inc. */
5 /* See LICENSE for licensing information */
6 
12 #include "core/or/or.h"
15 
16 #include "core/or/extend_info_st.h"
17 #include "feature/nodelist/node_st.h"
18 #include "feature/nodelist/routerinfo_st.h"
19 #include "feature/nodelist/routerstatus_st.h"
20 
28 #define NODE_DESC_BUF_LEN (MAX_VERBOSE_NICKNAME_LEN+4+TOR_ADDR_BUF_LEN)
29 
40 static const char *
42  const char *id_digest,
43  int is_named,
44  const char *nickname,
45  const tor_addr_t *addr,
46  uint32_t addr32h)
47 {
48  char *cp;
49 
50  if (!buf)
51  return "<NULL BUFFER>";
52 
53  buf[0] = '$';
54  base16_encode(buf+1, HEX_DIGEST_LEN+1, id_digest, DIGEST_LEN);
55  cp = buf+1+HEX_DIGEST_LEN;
56  if (nickname) {
57  buf[1+HEX_DIGEST_LEN] = is_named ? '=' : '~';
58  strlcpy(buf+1+HEX_DIGEST_LEN+1, nickname, MAX_NICKNAME_LEN+1);
59  cp += strlen(cp);
60  }
61  if (addr32h || addr) {
62  memcpy(cp, " at ", 4);
63  cp += 4;
64  if (addr) {
65  tor_addr_to_str(cp, addr, TOR_ADDR_BUF_LEN, 0);
66  } else {
67  struct in_addr in;
68  in.s_addr = htonl(addr32h);
70  }
71  }
72  return buf;
73 }
74 
80 const char *
82 {
83  static char buf[NODE_DESC_BUF_LEN];
84 
85  if (!ri)
86  return "<null>";
87  return format_node_description(buf,
88  ri->cache_info.identity_digest,
89  0,
90  ri->nickname,
91  NULL,
92  ri->addr);
93 }
94 
100 const char *
101 node_describe(const node_t *node)
102 {
103  static char buf[NODE_DESC_BUF_LEN];
104  const char *nickname = NULL;
105  uint32_t addr32h = 0;
106  int is_named = 0;
107 
108  if (!node)
109  return "<null>";
110 
111  if (node->rs) {
112  nickname = node->rs->nickname;
113  is_named = node->rs->is_named;
114  addr32h = node->rs->addr;
115  } else if (node->ri) {
116  nickname = node->ri->nickname;
117  addr32h = node->ri->addr;
118  }
119 
120  return format_node_description(buf,
121  node->identity,
122  is_named,
123  nickname,
124  NULL,
125  addr32h);
126 }
127 
133 const char *
135 {
136  static char buf[NODE_DESC_BUF_LEN];
137 
138  if (!rs)
139  return "<null>";
140  return format_node_description(buf,
141  rs->identity_digest,
142  rs->is_named,
143  rs->nickname,
144  NULL,
145  rs->addr);
146 }
147 
153 const char *
155 {
156  static char buf[NODE_DESC_BUF_LEN];
157 
158  if (!ei)
159  return "<null>";
160  return format_node_description(buf,
161  ei->identity_digest,
162  0,
163  ei->nickname,
164  &ei->addr,
165  0);
166 }
167 
175 void
176 router_get_verbose_nickname(char *buf, const routerinfo_t *router)
177 {
178  buf[0] = '$';
179  base16_encode(buf+1, HEX_DIGEST_LEN+1, router->cache_info.identity_digest,
180  DIGEST_LEN);
181  buf[1+HEX_DIGEST_LEN] = '~';
182  strlcpy(buf+1+HEX_DIGEST_LEN+1, router->nickname, MAX_NICKNAME_LEN+1);
183 }
const char * tor_addr_to_str(char *dest, const tor_addr_t *addr, size_t len, int decorate)
Definition: address.c:317
#define TOR_ADDR_BUF_LEN
Definition: address.h:205
Definition: node_st.h:28
const char * extend_info_describe(const extend_info_t *ei)
Definition: describe.c:154
char identity_digest[DIGEST_LEN]
Header file for describe.c.
#define MAX_NICKNAME_LEN
Definition: or.h:113
#define INET_NTOA_BUF_LEN
Definition: inaddr.h:21
unsigned int is_named
void router_get_verbose_nickname(char *buf, const routerinfo_t *router)
Definition: describe.c:176
static const char * format_node_description(char *buf, const char *id_digest, int is_named, const char *nickname, const tor_addr_t *addr, uint32_t addr32h)
Definition: describe.c:41
char nickname[MAX_HEX_NICKNAME_LEN+1]
#define DIGEST_LEN
Definition: digest_sizes.h:20
const char * node_describe(const node_t *node)
Definition: describe.c:101
char identity[DIGEST_LEN]
Definition: node_st.h:40
Master header file for Tor-specific functionality.
const char * routerstatus_describe(const routerstatus_t *rs)
Definition: describe.c:134
char nickname[MAX_NICKNAME_LEN+1]
void base16_encode(char *dest, size_t destlen, const char *src, size_t srclen)
Definition: binascii.c:476
#define HEX_DIGEST_LEN
Definition: crypto_digest.h:35
char identity_digest[DIGEST_LEN]
char identity_digest[DIGEST_LEN]
char * nickname
Definition: routerinfo_st.h:17
int tor_inet_ntoa(const struct in_addr *in, char *buf, size_t buf_len)
Definition: inaddr.c:58
uint32_t addr
Definition: routerinfo_st.h:19
tor_addr_t addr
Header file for routerinfo.c.
#define NODE_DESC_BUF_LEN
Definition: describe.c:28
const char * router_describe(const routerinfo_t *ri)
Definition: describe.c:81