summaryrefslogtreecommitdiff
path: root/lib/peer.c
diff options
context:
space:
mode:
authorLinus Nordberg <linus@nordu.net>2011-03-12 12:41:19 +0100
committerLinus Nordberg <linus@nordu.net>2011-03-12 12:41:19 +0100
commit2af84872cb78becf43f7bf4a654418fb7fc532d5 (patch)
tree7c3f33df5316fd67431fc4e70356d7a62da4543f /lib/peer.c
parent319c2bf1b2886b2e5cd1c5d60a8950493d2d4d75 (diff)
parentefce8db03af505f76c0c579f2439757bd6998dc9 (diff)
Merge branch 'udp' into libradsec.
Diffstat (limited to 'lib/peer.c')
-rw-r--r--lib/peer.c50
1 files changed, 44 insertions, 6 deletions
diff --git a/lib/peer.c b/lib/peer.c
index 4fbb54f..bcd5c97 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 <config.h>
#endif
@@ -6,18 +8,54 @@
#include <assert.h>
#include <radsec/radsec.h>
#include <radsec/radsec-impl.h>
+#include "err.h"
+#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;
+}
+
+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);
@@ -35,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;
}