mirror of
https://github.com/servalproject/serval-dna.git
synced 2025-01-29 15:43:56 +00:00
Further preparatory work for MDP. Next stop is actually checking
for inbound MDP connection requests on the unix domain sockets.
This commit is contained in:
parent
c59318cbab
commit
f384e6ea79
@ -133,6 +133,7 @@ int overlayServerMode()
|
||||
fdcount=1;
|
||||
rhizome_server_get_fds(fds,&fdcount,128);
|
||||
rhizome_fetching_get_fds(fds,&fdcount,128);
|
||||
overlay_mdp_get_fds(fds,&fdcount,128);
|
||||
|
||||
for(i=0;i<overlay_interface_count;i++)
|
||||
{
|
||||
@ -197,6 +198,7 @@ int overlayServerMode()
|
||||
if (rhizome_datastore_path) {
|
||||
rhizome_server_poll();
|
||||
rhizome_fetch_poll();
|
||||
overlay_mdp_poll();
|
||||
}
|
||||
} else {
|
||||
/* No data before tick occurred, so do nothing.
|
||||
|
115
overlay_mdp.c
115
overlay_mdp.c
@ -18,6 +18,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
|
||||
#include "serval.h"
|
||||
|
||||
|
||||
int mdp_abstract_socket=-1;
|
||||
int mdp_named_socket=-1;
|
||||
int overlay_mdp_setup_sockets()
|
||||
@ -27,51 +28,54 @@ int overlay_mdp_setup_sockets()
|
||||
|
||||
name.sun_family = AF_UNIX;
|
||||
|
||||
/* Abstract name space unix sockets is a special Linux thing, which is
|
||||
convenient for us because Android is Linux, but does not have a shared
|
||||
writable path that is on a UFS partition, so we cannot use traditional
|
||||
named unix domain sockets. So the abstract name space gives us a solution. */
|
||||
name.sun_path[0]=0;
|
||||
/* XXX The 100 should be replaced with the actual maximum allowed.
|
||||
Apparently POSIX requires it to be at least 100, but I would still feel
|
||||
more comfortable with using the appropriate constant. */
|
||||
snprintf(&name.sun_path[1],100,"org.servalproject.mesh.overlay.mdp");
|
||||
len = 1+strlen(&name.sun_path[1]) + sizeof(name.sun_family);
|
||||
|
||||
#ifndef HAVE_LINUX_IF_H
|
||||
/* Abstrack name space (i.e., non-file represented) unix domain sockets are a
|
||||
linux-only thing. */
|
||||
mdp_abstract_socket = -1;
|
||||
#else
|
||||
mdp_abstract_socket = socket(AF_UNIX, SOCK_STREAM, 0);
|
||||
if (mdp_abstract_socket>-1) {
|
||||
int dud=0;
|
||||
int r=bind(mdp_abstract_socket, (struct sockaddr *)&name, len);
|
||||
if (r) { dud=1; r=0; WHY("bind() of abstract name space socket failed (not an error on non-linux systems"); }
|
||||
r=listen(mdp_abstract_socket,100); // allow a lot of queued up MDP frames
|
||||
if (r) { dud++; WHY("listen() failed"); }
|
||||
if (dud) {
|
||||
close(mdp_abstract_socket);
|
||||
mdp_abstract_socket=-1;
|
||||
WHY("Could not open abstract name-space socket (only a problem on Linux).");
|
||||
if (mdp_abstract_socket==-1) {
|
||||
/* Abstract name space unix sockets is a special Linux thing, which is
|
||||
convenient for us because Android is Linux, but does not have a shared
|
||||
writable path that is on a UFS partition, so we cannot use traditional
|
||||
named unix domain sockets. So the abstract name space gives us a solution. */
|
||||
name.sun_path[0]=0;
|
||||
/* XXX The 100 should be replaced with the actual maximum allowed.
|
||||
Apparently POSIX requires it to be at least 100, but I would still feel
|
||||
more comfortable with using the appropriate constant. */
|
||||
snprintf(&name.sun_path[1],100,"org.servalproject.mesh.overlay.mdp");
|
||||
len = 1+strlen(&name.sun_path[1]) + sizeof(name.sun_family);
|
||||
|
||||
mdp_abstract_socket = socket(AF_UNIX, SOCK_STREAM, 0);
|
||||
if (mdp_abstract_socket>-1) {
|
||||
int dud=0;
|
||||
int r=bind(mdp_abstract_socket, (struct sockaddr *)&name, len);
|
||||
if (r) { dud=1; r=0; WHY("bind() of abstract name space socket failed (not an error on non-linux systems"); }
|
||||
r=listen(mdp_abstract_socket,100); // allow a lot of queued up MDP frames
|
||||
if (r) { dud++; WHY("listen() failed"); }
|
||||
if (dud) {
|
||||
close(mdp_abstract_socket);
|
||||
mdp_abstract_socket=-1;
|
||||
WHY("Could not open abstract name-space socket (only a problem on Linux).");
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
char *instancepath=serval_instancepath();
|
||||
|
||||
snprintf(&name.sun_path[0],100,"%s/mdp.socket",instancepath);
|
||||
len = 0+strlen(&name.sun_path[0]) + sizeof(name.sun_family);
|
||||
mdp_named_socket = socket(AF_UNIX, SOCK_STREAM, 0);
|
||||
if (mdp_named_socket>-1) {
|
||||
int dud=0;
|
||||
int r=bind(mdp_named_socket, (struct sockaddr *)&name, len);
|
||||
if (r) { dud=1; r=0; WHY("bind() of named unix domain socket failed"); }
|
||||
r=listen(mdp_named_socket,100); // allow a lot of queued up MDP frames
|
||||
if (r) { dud++; WHY("listen() failed"); }
|
||||
if (dud) {
|
||||
close(mdp_named_socket);
|
||||
mdp_named_socket=-1;
|
||||
WHY("Could not open named unix domain socket.");
|
||||
if (mdp_named_socket==-1) {
|
||||
char *instancepath=serval_instancepath();
|
||||
snprintf(&name.sun_path[0],100,"%s/mdp.socket",instancepath);
|
||||
len = 0+strlen(&name.sun_path[0]) + sizeof(name.sun_family);
|
||||
mdp_named_socket = socket(AF_UNIX, SOCK_STREAM, 0);
|
||||
if (mdp_named_socket>-1) {
|
||||
int dud=0;
|
||||
int r=bind(mdp_named_socket, (struct sockaddr *)&name, len);
|
||||
if (r) { dud=1; r=0; WHY("bind() of named unix domain socket failed"); }
|
||||
r=listen(mdp_named_socket,100); // allow a lot of queued up MDP frames
|
||||
if (r) { dud++; WHY("listen() failed"); }
|
||||
if (dud) {
|
||||
close(mdp_named_socket);
|
||||
mdp_named_socket=-1;
|
||||
WHY("Could not open named unix domain socket.");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -79,7 +83,44 @@ int overlay_mdp_setup_sockets()
|
||||
|
||||
}
|
||||
|
||||
int overlay_mdp_get_fds(struct pollfd *fds,int *fdcount,int fdmax)
|
||||
{
|
||||
/* Make sure sockets are open */
|
||||
overlay_mdp_setup_sockets();
|
||||
|
||||
if ((*fdcount)>=fdmax) return -1;
|
||||
if (mdp_abstract_socket>-1)
|
||||
{
|
||||
if (debug&DEBUG_IO) {
|
||||
fprintf(stderr,"MDP abstract name space socket is poll() slot #%d (fd %d)\n",
|
||||
*fdcount,mdp_abstract_socket);
|
||||
}
|
||||
fds[*fdcount].fd=mdp_abstract_socket;
|
||||
fds[*fdcount].events=POLLIN;
|
||||
(*fdcount)++;
|
||||
}
|
||||
if ((*fdcount)>=fdmax) return -1;
|
||||
if (mdp_named_socket>-1)
|
||||
{
|
||||
if (debug&DEBUG_IO) {
|
||||
fprintf(stderr,"MDP named unix domain socket is poll() slot #%d (fd %d)\n",
|
||||
*fdcount,mdp_named_socket);
|
||||
}
|
||||
fds[*fdcount].fd=mdp_named_socket;
|
||||
fds[*fdcount].events=POLLIN;
|
||||
(*fdcount)++;
|
||||
}
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int overlay_saw_mdp_frame(int interface,overlay_frame *f,long long now)
|
||||
{
|
||||
return WHY("Not implemented");
|
||||
}
|
||||
|
||||
int overlay_mdp_poll()
|
||||
{
|
||||
return WHY("Not implemented");
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user