mirror of
https://github.com/servalproject/serval-dna.git
synced 2025-01-18 02:39:44 +00:00
Added Mesh Datagram Protocol (MDP) source file and initial work.
Added overlay_mdp.c to Makefile.in, and also trans_cache.c which had not yet been added.
This commit is contained in:
parent
ac072c22d0
commit
348c5ebcf3
10
Makefile.in
10
Makefile.in
@ -1,18 +1,20 @@
|
||||
SRCS= dna.c server.c client.c peers.c ciphers.c responses.c packetformats.c dataformats.c \
|
||||
hlrdata.c srandomdev.c simulate.c batman.c export.c gateway.c \
|
||||
overlay.c overlay_buffer.c overlay_interface.c overlay_payload.c overlay_route.c \
|
||||
overlay_packetformats.c overlay_abbreviations.c overlay_advertise.c \
|
||||
overlay_packetformats.c overlay_abbreviations.c overlay_advertise.c overlay_mdp.c \
|
||||
rhizome.c rhizome_http.c rhizome_bundle.c rhizome_database.c rhizome_crypto.c \
|
||||
rhizome_packetformats.c rhizome_fetch.c sqlite3.c encode.c sha2.c randombytes.c \
|
||||
overlay_broadcast.c dna_identity.c commandline.c serval_packetvisualise.c
|
||||
overlay_broadcast.c dna_identity.c commandline.c serval_packetvisualise.c \
|
||||
trans_cache.c
|
||||
|
||||
OBJS= dna.o server.o client.o peers.o ciphers.o responses.o packetformats.o dataformats.o \
|
||||
hlrdata.o srandomdev.o simulate.o batman.o export.o gateway.o \
|
||||
overlay.o overlay_buffer.o overlay_interface.o overlay_payload.o overlay_route.o \
|
||||
overlay_packetformats.o overlay_abbreviations.o overlay_advertise.o \
|
||||
overlay_packetformats.o overlay_abbreviations.o overlay_advertise.o overlay_mdp.o \
|
||||
rhizome.o rhizome_http.o rhizome_bundle.o rhizome_database.o rhizome_crypto.o \
|
||||
rhizome_packetformats.o rhizome_fetch.o sqlite3.o encode.o sha2.o randombytes.o \
|
||||
overlay_broadcast.o dna_identity.o commandline.o serval_packetvisualise.o
|
||||
overlay_broadcast.o dna_identity.o commandline.o serval_packetvisualise.o \
|
||||
trans_cache.o
|
||||
|
||||
HDRS= Makefile serval.h sqlite-amalgamation-3070900/sqlite3.h sha2.h rhizome.h
|
||||
|
||||
|
85
overlay_mdp.c
Normal file
85
overlay_mdp.c
Normal file
@ -0,0 +1,85 @@
|
||||
/*
|
||||
Copyright (C) 2010-2012 Paul Gardner-Stephen, Serval Project.
|
||||
|
||||
This program is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU General Public License
|
||||
as published by the Free Software Foundation; either version 2
|
||||
of the License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; if not, write to the Free Software
|
||||
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()
|
||||
{
|
||||
struct sockaddr_un name;
|
||||
int len;
|
||||
|
||||
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).");
|
||||
}
|
||||
}
|
||||
#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.");
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
||||
}
|
||||
|
||||
int overlay_saw_mdp_frame(int interface,overlay_frame *f,long long now)
|
||||
{
|
||||
return WHY("Not implemented");
|
||||
}
|
Loading…
Reference in New Issue
Block a user