aboutsummaryrefslogtreecommitdiff
path: root/src/rest
diff options
context:
space:
mode:
authorSchanzenbach, Martin <mschanzenbach@posteo.de>2019-03-09 15:58:45 +0100
committerSchanzenbach, Martin <mschanzenbach@posteo.de>2019-03-09 15:58:45 +0100
commitfed55fd466b43dc0175a12a1a475e43747da137a (patch)
tree2082f86b9db158374a9f7283cd2004bbd942e090 /src/rest
parent5ffc8cb3dd59bb3f12b26413f22d00fc607d04ef (diff)
downloadgnunet-fed55fd466b43dc0175a12a1a475e43747da137a.tar.gz
gnunet-fed55fd466b43dc0175a12a1a475e43747da137a.zip
bind to config option (default localhost)
Diffstat (limited to 'src/rest')
-rw-r--r--src/rest/gnunet-rest-server.c59
-rw-r--r--src/rest/rest.conf2
2 files changed, 61 insertions, 0 deletions
diff --git a/src/rest/gnunet-rest-server.c b/src/rest/gnunet-rest-server.c
index 77f3d898d..f9e954912 100644
--- a/src/rest/gnunet-rest-server.c
+++ b/src/rest/gnunet-rest-server.c
@@ -64,6 +64,16 @@
64static struct GNUNET_SCHEDULER_Task *httpd_task; 64static struct GNUNET_SCHEDULER_Task *httpd_task;
65 65
66/** 66/**
67 * The address to bind to
68 */
69static in_addr_t address;
70
71/**
72 * The IPv6 address to bind to
73 */
74static struct in6_addr address6;
75
76/**
67 * The port the service is running on (default 7776) 77 * The port the service is running on (default 7776)
68 */ 78 */
69static unsigned long long port = GNUNET_REST_SERVICE_PORT; 79static unsigned long long port = GNUNET_REST_SERVICE_PORT;
@@ -695,6 +705,7 @@ bind_v4 ()
695 memset (&sa4, 0, sizeof (sa4)); 705 memset (&sa4, 0, sizeof (sa4));
696 sa4.sin_family = AF_INET; 706 sa4.sin_family = AF_INET;
697 sa4.sin_port = htons (port); 707 sa4.sin_port = htons (port);
708 sa4.sin_addr.s_addr = address;
698#if HAVE_SOCKADDR_IN_SIN_LEN 709#if HAVE_SOCKADDR_IN_SIN_LEN
699 sa4.sin_len = sizeof (sa4); 710 sa4.sin_len = sizeof (sa4);
700#endif 711#endif
@@ -731,6 +742,7 @@ bind_v6 ()
731 memset (&sa6, 0, sizeof (sa6)); 742 memset (&sa6, 0, sizeof (sa6));
732 sa6.sin6_family = AF_INET6; 743 sa6.sin6_family = AF_INET6;
733 sa6.sin6_port = htons (port); 744 sa6.sin6_port = htons (port);
745 sa6.sin6_addr = address6;
734#if HAVE_SOCKADDR_IN_SIN_LEN 746#if HAVE_SOCKADDR_IN_SIN_LEN
735 sa6.sin6_len = sizeof (sa6); 747 sa6.sin6_len = sizeof (sa6);
736#endif 748#endif
@@ -806,9 +818,56 @@ run (void *cls,
806 const char *cfgfile, 818 const char *cfgfile,
807 const struct GNUNET_CONFIGURATION_Handle *c) 819 const struct GNUNET_CONFIGURATION_Handle *c)
808{ 820{
821 char* addr_str;
809 cfg = c; 822 cfg = c;
810 plugin_map = GNUNET_CONTAINER_multihashmap_create (10, GNUNET_NO); 823 plugin_map = GNUNET_CONTAINER_multihashmap_create (10, GNUNET_NO);
811 824
825 /* Get address to bind to */
826 if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_string (cfg, "rest",
827 "BIND_TO",
828 &addr_str))
829 {
830 //No address specified
831 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
832 "Don't know what to bind to...\n");
833 GNUNET_free (addr_str);
834 GNUNET_SCHEDULER_shutdown ();
835 return;
836 }
837 if (1 != inet_pton (AF_INET, addr_str, &address))
838 {
839 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
840 "Unable to parse address %s\n",
841 addr_str);
842 GNUNET_free (addr_str);
843 GNUNET_SCHEDULER_shutdown ();
844 return;
845 }
846 GNUNET_free (addr_str);
847 /* Get address to bind to */
848 if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_string (cfg, "rest",
849 "BIND_TO6",
850 &addr_str))
851 {
852 //No address specified
853 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
854 "Don't know what to bind6 to...\n");
855 GNUNET_free (addr_str);
856 GNUNET_SCHEDULER_shutdown ();
857 return;
858 }
859 if (1 != inet_pton (AF_INET6, addr_str, &address6))
860 {
861 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
862 "Unable to parse IPv6 address %s\n",
863 addr_str);
864 GNUNET_free (addr_str);
865 GNUNET_SCHEDULER_shutdown ();
866 return;
867 }
868 GNUNET_free (addr_str);
869
870
812 /* Get CORS data from cfg */ 871 /* Get CORS data from cfg */
813 if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_string (cfg, "rest", 872 if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_string (cfg, "rest",
814 "REST_ALLOW_ORIGIN", 873 "REST_ALLOW_ORIGIN",
diff --git a/src/rest/rest.conf b/src/rest/rest.conf
index 138751696..bef8cf473 100644
--- a/src/rest/rest.conf
+++ b/src/rest/rest.conf
@@ -1,6 +1,8 @@
1[rest] 1[rest]
2UNIXPATH = $GNUNET_USER_RUNTIME_DIR/gnunet-service-rest.sock 2UNIXPATH = $GNUNET_USER_RUNTIME_DIR/gnunet-service-rest.sock
3BINARY=gnunet-rest-server 3BINARY=gnunet-rest-server
4BIND_TO=127.0.0.1
5BIND_TO6=::1
4REST_PORT=7776 6REST_PORT=7776
5REST_ALLOW_HEADERS=Authorization,Accept,Content-Type 7REST_ALLOW_HEADERS=Authorization,Accept,Content-Type
6REST_ALLOW_ORIGIN=* 8REST_ALLOW_ORIGIN=*