From 5c60297a1eaab7b10d6f584ba329493a41b812d0 Mon Sep 17 00:00:00 2001 From: Linus Nordberg Date: Sun, 6 Mar 2011 15:53:58 +0100 Subject: Restructure code, moving most code out of packet.c Also, move copyright notice out of COPYING and into every file. --- lib/peer.c | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) (limited to 'lib/peer.c') diff --git a/lib/peer.c b/lib/peer.c index 4fbb54f..0a1d2ec 100644 --- a/lib/peer.c +++ b/lib/peer.c @@ -1,4 +1,6 @@ -/* See the file COPYING for licensing information. */ +/* Copyright 2010, 2011 NORDUnet A/S. All rights reserved. + See the file COPYING for licensing information. */ + #if defined HAVE_CONFIG_H #include #endif @@ -6,7 +8,22 @@ #include #include #include +#include "peer.h" + +struct rs_peer * +peer_pick_peer (struct rs_connection *conn) +{ + assert (conn); + + if (conn->active_peer) + conn->active_peer = conn->active_peer->next; /* Next. */ + if (!conn->active_peer) + conn->active_peer = conn->peers; /* From the top. */ + + return conn->active_peer; +} +/* Public functions. */ int rs_peer_create (struct rs_connection *conn, struct rs_peer **peer_out) { -- cgit v1.1 From fac0219dad91c574417f78ec674aa0dd10949e15 Mon Sep 17 00:00:00 2001 From: Linus Nordberg Date: Wed, 9 Mar 2011 10:14:20 +0100 Subject: Rename and move around a few helper functions. --- lib/peer.c | 31 ++++++++++++++++++++++++++----- 1 file changed, 26 insertions(+), 5 deletions(-) (limited to 'lib/peer.c') diff --git a/lib/peer.c b/lib/peer.c index 0a1d2ec..bcd5c97 100644 --- a/lib/peer.c +++ b/lib/peer.c @@ -8,6 +8,7 @@ #include #include #include +#include "err.h" #include "peer.h" struct rs_peer * @@ -23,18 +24,38 @@ peer_pick_peer (struct rs_connection *conn) return conn->active_peer; } +struct rs_peer * +peer_create (struct rs_context *ctx, struct rs_peer **rootp) +{ + struct rs_peer *p; + + p = (struct rs_peer *) rs_malloc (ctx, sizeof(*p)); + if (p) + { + memset (p, 0, sizeof(struct rs_peer)); + if (*rootp) + { + p->next = (*rootp)->next; + (*rootp)->next = p; + } + else + *rootp = p; + } + return p; +} + /* Public functions. */ int rs_peer_create (struct rs_connection *conn, struct rs_peer **peer_out) { struct rs_peer *peer; - peer = _rs_peer_create (conn->ctx, &conn->peers); + peer = peer_create (conn->ctx, &conn->peers); if (peer) { peer->conn = conn; - peer->realm->timeout = 2; - peer->realm->retries = 2; + peer->realm->timeout = 2; /* FIXME: Why? */ + peer->realm->retries = 2; /* FIXME: Why? */ } else return rs_err_conn_push_fl (conn, RSE_NOMEM, __FILE__, __LINE__, NULL); @@ -52,9 +73,9 @@ rs_peer_set_address (struct rs_peer *peer, const char *hostname, assert (peer); assert (peer->realm); - err = _rs_resolv (&peer->addr, peer->realm->type, hostname, service); + err = rs_resolv (&peer->addr, peer->realm->type, hostname, service); if (err) - return _rs_err_conn_push_err (peer->conn, err); + return err_conn_push_err (peer->conn, err); return RSE_OK; } -- cgit v1.1