mirror of
https://github.com/servalproject/serval-dna.git
synced 2025-01-18 02:39:44 +00:00
make rhizome http port number configurable via serval.conf
This commit is contained in:
parent
84caf21969
commit
52bd428c09
@ -155,7 +155,7 @@ int cf_opt_rhizome_peer_from_uri(struct config_rhizome_peer *rpeer, const char *
|
||||
}
|
||||
const char *host;
|
||||
size_t hostlen;
|
||||
uint16_t port = HTTPD_PORT;
|
||||
uint16_t port = HTTPD_PORT_DEFAULT;
|
||||
if (!str_uri_authority_hostname(auth, &host, &hostlen))
|
||||
return CFINVALID;
|
||||
str_uri_authority_port(auth, &port);
|
||||
|
@ -373,7 +373,7 @@ END_STRUCT
|
||||
STRUCT(rhizome_peer)
|
||||
STRING(25, protocol, "http", protocol,, "Protocol name")
|
||||
STRING(256, host, "", str_nonempty, MANDATORY, "Host name or IP address")
|
||||
ATOM(uint16_t, port, HTTPD_PORT, uint16_nonzero,, "Port number")
|
||||
ATOM(uint16_t, port, HTTPD_PORT_DEFAULT, uint16_nonzero,, "Port number")
|
||||
END_STRUCT
|
||||
|
||||
ARRAY(peerlist,)
|
||||
@ -399,6 +399,7 @@ END_STRUCT
|
||||
|
||||
STRUCT(rhizome_http)
|
||||
ATOM(bool_t, enable, 1, boolean,, "If true, Rhizome HTTP server is started")
|
||||
ATOM(uint16_t, port, HTTPD_PORT_DEFAULT, uint16_nonzero,, "Port number for Rhizome HTTP server")
|
||||
END_STRUCT
|
||||
|
||||
STRUCT(rhizome_mdp)
|
||||
|
10
httpd.c
10
httpd.c
@ -108,7 +108,7 @@ int is_httpd_server_running()
|
||||
Return 1 if the server is already started successfully.
|
||||
Return 2 if the server was not started because it is too soon since last failed attempt.
|
||||
*/
|
||||
int httpd_server_start(uint16_t port_low, uint16_t port_high)
|
||||
int httpd_server_start(const uint16_t port_low, const uint16_t port_high)
|
||||
{
|
||||
if (httpd_server_socket != -1)
|
||||
return 1;
|
||||
@ -124,9 +124,9 @@ int httpd_server_start(uint16_t port_low, uint16_t port_high)
|
||||
for (port = port_low; port <= port_high; ++port) {
|
||||
/* Create a new socket, reusable and non-blocking. */
|
||||
if (httpd_server_socket == -1) {
|
||||
httpd_server_socket = socket(AF_INET,SOCK_STREAM,0);
|
||||
httpd_server_socket = socket(AF_INET, SOCK_STREAM, 0);
|
||||
if (httpd_server_socket == -1) {
|
||||
WHY_perror("socket");
|
||||
WHY_perror("socket(AF_INET, SOCK_STREAM, 0)");
|
||||
goto error;
|
||||
}
|
||||
int on=1;
|
||||
@ -165,7 +165,7 @@ int httpd_server_start(uint16_t port_low, uint16_t port_high)
|
||||
httpd_server_socket = -1;
|
||||
}
|
||||
}
|
||||
WHYF("No ports available in range %u to %u", HTTPD_PORT, HTTPD_PORT_MAX);
|
||||
WHYF("No ports available in range %u to %u", port_low, port_high);
|
||||
error:
|
||||
if (httpd_server_socket != -1) {
|
||||
close(httpd_server_socket);
|
||||
@ -182,7 +182,7 @@ success:
|
||||
server_alarm.poll.events = POLLIN;
|
||||
watch(&server_alarm);
|
||||
|
||||
INFOF("HTTP SERVER START port=%"PRIu16" fd=%d services=RESTful%s%s",
|
||||
INFOF("HTTP SERVER START port=%u fd=%d services=RESTful%s%s",
|
||||
httpd_server_port,
|
||||
httpd_server_socket,
|
||||
config.rhizome.http.enable ? ",Rhizome" : "",
|
||||
|
10
httpd.h
10
httpd.h
@ -20,15 +20,15 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
#ifndef __SERVAL_DNA__HTTPD_H
|
||||
#define __SERVAL_DNA__HTTPD_H
|
||||
|
||||
#include "rhizome.h"
|
||||
#include "http_server.h"
|
||||
#include "keyring.h"
|
||||
#include "meshms.h"
|
||||
#include "http_server.h"
|
||||
#include "os.h"
|
||||
|
||||
int is_httpd_server_running();
|
||||
|
||||
#define HTTPD_PORT 4110
|
||||
#define HTTPD_PORT_MAX 4210
|
||||
#define HTTPD_PORT_DEFAULT 4110
|
||||
#define HTTPD_PORT_RANGE 100
|
||||
|
||||
extern uint16_t httpd_server_port;
|
||||
extern unsigned int current_httpd_request_count;
|
||||
@ -215,7 +215,7 @@ typedef struct httpd_request
|
||||
|
||||
} httpd_request;
|
||||
|
||||
int httpd_server_start(uint16_t port_low, uint16_t port_high);
|
||||
int httpd_server_start(const uint16_t port_low, const uint16_t port_high);
|
||||
|
||||
typedef int HTTP_HANDLER(httpd_request *r, const char *remainder);
|
||||
|
||||
|
@ -117,6 +117,8 @@ int keyring_dump(keyring_file *k, XPRINTF xpf, int include_secret);
|
||||
|
||||
unsigned char *keyring_get_nm_bytes(const sid_t *known_sidp, const sid_t *unknown_sidp);
|
||||
|
||||
struct internal_mdp_header;
|
||||
struct overlay_buffer;
|
||||
int keyring_mapping_request(struct internal_mdp_header *header, struct overlay_buffer *payload);
|
||||
int keyring_send_unlock(struct subscriber *subscriber);
|
||||
int keyring_release_subscriber(keyring_file *k, const sid_t *sid);
|
||||
|
@ -193,7 +193,7 @@ int overlay_rhizome_saw_advertisements(struct decode_context *context, struct ov
|
||||
httpaddr=context->addr;
|
||||
}
|
||||
if (httpaddr.addr.sa_family == AF_INET)
|
||||
httpaddr.inet.sin_port = htons(HTTPD_PORT);
|
||||
httpaddr.inet.sin_port = HTTPD_PORT_DEFAULT;
|
||||
rhizome_manifest *m=NULL;
|
||||
|
||||
int (*oldfunc)() = sqlite_set_tracefunc(is_debug_rhizome_ads);
|
||||
|
@ -1,6 +1,6 @@
|
||||
/*
|
||||
Serval Rhizome foundation types
|
||||
Copyright (C) 2012-2014 Serval Project Inc.
|
||||
Serval Rhizome foundation types and constants
|
||||
Copyright (C) 2012-2015 Serval Project Inc.
|
||||
|
||||
This program is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU General Public License
|
||||
@ -150,4 +150,8 @@ uint64_t rhizome_bar_bidprefix_ll(const rhizome_bar_t *bar);
|
||||
|
||||
#define RHIZOME_SIZE_UNSET UINT64_MAX
|
||||
|
||||
/* Rhizome constants
|
||||
*/
|
||||
|
||||
|
||||
#endif // __SERVAL_DNA__RHIZOME_TYPES_H
|
||||
|
6
server.c
6
server.c
@ -291,11 +291,11 @@ static int server_bind()
|
||||
}
|
||||
|
||||
// start the HTTP server if enabled
|
||||
if (httpd_server_start(HTTPD_PORT, HTTPD_PORT_MAX)==-1){
|
||||
if (httpd_server_start(config.rhizome.http.port, config.rhizome.http.port + HTTPD_PORT_RANGE)==-1) {
|
||||
serverMode = 0;
|
||||
return -1;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/* For testing, it can be very helpful to delay the start of the server process, for example to
|
||||
* check that the start/stop logic is robust.
|
||||
*/
|
||||
|
Loading…
Reference in New Issue
Block a user