]> rtime.felk.cvut.cz Git - frescor/forb.git/commitdiff
Automatically register FCB peer when INET is default
authorMichal Sojka <sojkam1@fel.cvut.cz>
Tue, 26 May 2009 15:03:27 +0000 (17:03 +0200)
committerMichal Sojka <sojkam1@fel.cvut.cz>
Tue, 26 May 2009 15:38:18 +0000 (17:38 +0200)
FCB is always found on a fixed port. If FCB_ADDR environment variable
it not set, it is registered on 127.0.0.1, otherwise it is registered
on address according to the FCB_ADDR.

src/proto_inet.c

index 8442dfc2d484bf4f713b20cdc8af06a3bc412610..1c356794219f2f04c5b4ac5815035731f1757cbb 100644 (file)
@@ -59,6 +59,7 @@
 #include <ul_log.h>
 #include <unistd.h>
 #include <forb/config.h>
+#include "discovery.h"
 
 /**
  * @file   proto_inet.c
@@ -417,6 +418,28 @@ size_t inet_addr2str(char *dest, size_t maxlen, const void *addr)
        return ret;
 }
 
+#if CONFIG_FCB && CONFIG_FORB_PROTO_INET_DEFAULT
+
+#include <fcb.h>
+#include <fcb_contact_info.h>
+#include <stdlib.h>
+
+static void inet_register_cb(forb_port_t *port)
+{
+       struct inet_addr *ia;
+       
+       ia = malloc(sizeof(*ia));
+       if (!ia) return;
+
+       char *fcb_addr = getenv("FCB_ADDR");
+       if (!fcb_addr) fcb_addr = "127.0.0.1";
+       ia->addr.s_addr = inet_addr(fcb_addr);
+       ia->port = htons(FCB_TCP_PORT);
+       forb_new_peer_discovered(port, NULL, FCB_SERVER_ID, ia, "");
+}
+#else
+#define inet_register_cb NULL
+#endif
 
 static const forb_proto_t proto_inet = {
        .hello_interval = 40 /* seconds */,
@@ -428,6 +451,7 @@ static const forb_proto_t proto_inet = {
        .serialize_addr = inet_serialize_addr,
        .deserialize_addr = inet_deserialize_addr,
        .addr2str = inet_addr2str,
+       .register_cb = inet_register_cb,
 };
 
 #define MAX_INTERFACES 10