aboutsummaryrefslogtreecommitdiff
path: root/src/common
diff options
context:
space:
mode:
authorNick Mathewson <nickm@torproject.org>2011-04-07 12:17:20 -0400
committerNick Mathewson <nickm@torproject.org>2011-04-07 12:17:20 -0400
commit67d88a7d6021e95a2d423a9f26811accd1da39b6 (patch)
tree30d48f5f922b928f7727ed812905101e5bf24012 /src/common
parent07ab483e62457ee56187037304f25ec50cb0850a (diff)
parentba0cd8094f8e6ae0113ad69958d9d0973bb1f2c3 (diff)
downloadtor-67d88a7d6021e95a2d423a9f26811accd1da39b6.tar.gz
tor-67d88a7d6021e95a2d423a9f26811accd1da39b6.zip
Merge remote-tracking branch 'origin/maint-0.2.2'
Conflicts: src/common/address.c src/common/compat_libevent.c src/common/memarea.c src/common/util.h src/or/buffers.c src/or/circuitbuild.c src/or/circuituse.c src/or/connection.c src/or/directory.c src/or/networkstatus.c src/or/or.h src/or/routerlist.c
Diffstat (limited to 'src/common')
-rw-r--r--src/common/address.c20
-rw-r--r--src/common/address.h2
-rw-r--r--src/common/compat_libevent.c21
-rw-r--r--src/common/memarea.c6
-rw-r--r--src/common/util.h18
5 files changed, 23 insertions, 44 deletions
diff --git a/src/common/address.c b/src/common/address.c
index 20dc152752..5b143b0650 100644
--- a/src/common/address.c
+++ b/src/common/address.c
@@ -50,10 +50,14 @@
#include <assert.h>
/** Convert the tor_addr_t in <b>a</b>, with port in <b>port</b>, into a
- * socklen object in *<b>sa_out</b> of object size <b>len</b>. If not enough
- * room is free, or on error, return -1. Else return the length of the
- * sockaddr. */
-int
+ * sockaddr object in *<b>sa_out</b> of object size <b>len</b>. If not enough
+ * room is available in sa_out, or on error, return 0. On success, return
+ * the length of the sockaddr.
+ *
+ * Interface note: ordinarily, we return -1 for error. We can't do that here,
+ * since socklen_t is unsigned on some platforms.
+ **/
+socklen_t
tor_addr_to_sockaddr(const tor_addr_t *a,
uint16_t port,
struct sockaddr *sa_out,
@@ -63,7 +67,7 @@ tor_addr_to_sockaddr(const tor_addr_t *a,
if (family == AF_INET) {
struct sockaddr_in *sin;
if (len < (int)sizeof(struct sockaddr_in))
- return -1;
+ return 0;
sin = (struct sockaddr_in *)sa_out;
memset(sin, 0, sizeof(struct sockaddr_in));
#ifdef HAVE_STRUCT_SOCKADDR_IN_SIN_LEN
@@ -76,7 +80,7 @@ tor_addr_to_sockaddr(const tor_addr_t *a,
} else if (family == AF_INET6) {
struct sockaddr_in6 *sin6;
if (len < (int)sizeof(struct sockaddr_in6))
- return -1;
+ return 0;
sin6 = (struct sockaddr_in6 *)sa_out;
memset(sin6, 0, sizeof(struct sockaddr_in6));
#ifdef HAVE_STRUCT_SOCKADDR_IN6_SIN6_LEN
@@ -87,7 +91,7 @@ tor_addr_to_sockaddr(const tor_addr_t *a,
memcpy(&sin6->sin6_addr, tor_addr_to_in6(a), sizeof(struct in6_addr));
return sizeof(struct sockaddr_in6);
} else {
- return -1;
+ return 0;
}
}
@@ -1096,7 +1100,7 @@ get_interface_address6(int severity, sa_family_t family, tor_addr_t *addr)
/* ======
* IPv4 helpers
- * XXXX022 IPv6 deprecate some of these.
+ * XXXX023 IPv6 deprecate some of these.
*/
/** Return true iff <b>ip</b> (in host order) is an IP reserved to localhost,
diff --git a/src/common/address.h b/src/common/address.h
index f8b9c02128..3087906340 100644
--- a/src/common/address.h
+++ b/src/common/address.h
@@ -39,7 +39,7 @@ static INLINE sa_family_t tor_addr_family(const tor_addr_t *a);
static INLINE const struct in_addr *tor_addr_to_in(const tor_addr_t *a);
static INLINE int tor_addr_eq_ipv4h(const tor_addr_t *a, uint32_t u);
-int tor_addr_to_sockaddr(const tor_addr_t *a, uint16_t port,
+socklen_t tor_addr_to_sockaddr(const tor_addr_t *a, uint16_t port,
struct sockaddr *sa_out, socklen_t len);
int tor_addr_from_sockaddr(tor_addr_t *a, const struct sockaddr *sa,
uint16_t *port_out);
diff --git a/src/common/compat_libevent.c b/src/common/compat_libevent.c
index 48a5b326c8..7924036e61 100644
--- a/src/common/compat_libevent.c
+++ b/src/common/compat_libevent.c
@@ -354,21 +354,12 @@ tor_check_libevent_version(const char *m, int server,
version = tor_get_libevent_version(&v);
- /* It would be better to disable known-buggy methods than to simply
- warn about them. However, it's not trivial to get libevent to change its
- method once it's initialized, and it's not trivial to tell what method it
- will use without initializing it.
-
- If we saw that the version was definitely bad, we could disable all the
- methods that were bad for that version. But the issue with that is that
- if you've found a libevent before 1.1, you are not at all guaranteed to
- have _any_ good method to use.
-
- As of Libevent 2, we can do better, and have more control over what
- methods get used. But the problem here is that there are no versions of
- Libevent 2 that have buggy event cores, so there's no point in writing
- disable code yet.
- */
+ /* It would be better to disable known-buggy methods rather than warning
+ * about them. But the problem is that with older versions of Libevent,
+ * it's not trivial to get them to change their methods once they're
+ * initialized... and with newer versions of Libevent, they aren't actually
+ * broken. But we should revisit this if we ever find a post-1.4 version
+ * of Libevent where we need to disable a given method. */
if (!strcmp(m, "kqueue")) {
if (version < V_OLD(1,1,'b'))
buggy = 1;
diff --git a/src/common/memarea.c b/src/common/memarea.c
index 94f6424883..a6b8c4ee9c 100644
--- a/src/common/memarea.c
+++ b/src/common/memarea.c
@@ -59,7 +59,9 @@ realign_pointer(void *ptr)
{
uintptr_t x = (uintptr_t)ptr;
x = (x+MEMAREA_ALIGN_MASK) & ~MEMAREA_ALIGN_MASK;
+ /* Reinstate this if bug 930 ever reappears
tor_assert(((void*)x) >= ptr);
+ */
return (void*)x;
}
@@ -241,10 +243,10 @@ memarea_alloc(memarea_t *area, size_t sz)
}
result = chunk->next_mem;
chunk->next_mem = chunk->next_mem + sz;
-
+ /* Reinstate these if bug 930 ever comes back
tor_assert(chunk->next_mem >= chunk->u.mem);
tor_assert(chunk->next_mem <= chunk->u.mem+chunk->mem_size);
-
+ */
chunk->next_mem = realign_pointer(chunk->next_mem);
return result;
}
diff --git a/src/common/util.h b/src/common/util.h
index 97fd4f7aa2..759f068b03 100644
--- a/src/common/util.h
+++ b/src/common/util.h
@@ -247,24 +247,6 @@ time_t approx_time(void);
void update_approx_time(time_t now);
#endif
-/* Fuzzy time. */
-
-/** Return true iff <a>a</b> is definitely after <b>b</b>, even if there
- * could be up to <b>allow_seconds</b> of skew in one of them. */
-static INLINE int
-time_definitely_after(time_t a, time_t b, int allow_skew)
-{
- return a-allow_skew > b;
-}
-
-/** Return true iff <a>a</b> is definitely before <b>b</b>, even if there
- * could be up to <b>allow_seconds</b> of skew in one of them. */
-static INLINE int
-time_definitely_before(time_t a, time_t b, int allow_skew)
-{
- return a+allow_skew < b;
-}
-
/* Rate-limiter */
/** A ratelim_t remembers how often an event is occurring, and how often