public inbox for b.a.t.m.a.n@lists.open-mesh.org
 help / color / mirror / Atom feed
From: Hans-Werner Hilse <hwhilse@gmail.com>
To: b.a.t.m.a.n@lists.open-mesh.org
Cc: Hans-Werner Hilse <hwhilse@gmail.com>
Subject: [B.A.T.M.A.N.] [RFC] alfred: implement TCP support for server-to-server
Date: Mon, 21 Mar 2016 10:03:52 +0100	[thread overview]
Message-ID: <1458551033-8734-1-git-send-email-hwhilse@gmail.com> (raw)

As announced in A.L.F.R.E.D. issue #202 (https://www.open-mesh.org/issues/202),
I gave implementing server-to-server communication via TCP a spin.

The result is this - rather large - patch. I'd be glad for comments on the
implementation. Also, I might split this into more commits, but I think I need
ideas on how to properly separate the various parts - they mostly make sense
to me as a unit only.

A rough overview:

alfred.h:
* struct tcp_connection is new, stores socket fd, pointer to data buffer,
  a counter for data already read from socket (TCP is a stream and we can't
  rely on self-contained datagrams), and list management
* struct interface is extended by a socket fd for the TCP socket and
  a list of "tcp_connection"s
* struct globals is extended by a "requestproto" field that stores desired
  operation mode.

main.c:
* TCP operation is for now triggered by a command line flag "-t".

netsock.c:
* for each interface, a TCP socket, bound/listening, is created and teared
  down along with the UDP sockets
* a list of tcp_connection sockets is kept, managed and cleared alongside
* the sockets are incorporated into the fd_set management for select()

recv.c:
* process_alfred_request() gets another argument for a socket fd. It just
  gets handed over to push_data() for sending the reply over the same
  socket the request came from.
* recv_alfred_stream() is new and the analog function to recv_alfred_packet().
  It manages the data buffer and will act on a received packet if and when
  it is completely received.
  ALFRED_REQUEST, ALFRED_PUSH_DATA and ALFRED_STATUS_TXEND packets are
  handled for now.

send.c:
* connect_tcp() function for setting up a new connection to a (TCP) server
* push_data() gets a new argument for a socket fd (c.f.
  process_alfred_request() in recv.c). If said argument is >=0, the function
  will operate on the socket rather than recvmsg() a datagram.
* sync_data() will act on requestproto configuration in globals struct and
  opt to make the sync via TCP if configured to do so
* send_alfred_stream() will use connect_tcp() to create a new connection,
  then send a packet analog to send_alfred_packet() and will then register
  the socket to the list of "tcp_connection"s for the interface it is
  currently operating upon. This way, the socket can receive a reply and
  will be handled as long as it is not closed on the other end.

server.c:
* check_if_socket() will tear down the TCP server and client sockets
  along with the UDP sockets

unix_sock.c:
* depending on the globals' requestproto setting, a REQUEST will be send
  via TCP rather than UDP.


Testing has been only in an artificial virtual setup for now. I have some
hopes to get "mission clearance" for giving it a spin in our local
"Freifunk" setup. Even then TCP will most certainly only be used on a
handful of gateways since on the majority of nodes, reading values from
A.L.F.R.E.D. is not really needed (they are mostly push-only).

I'd be glad to hear some feedback.

-hwh


Hans-Werner Hilse (1):
  alfred: implement TCP support for server-to-server communication

 alfred.h    |  24 +++++++++-
 main.c      |   8 +++-
 netsock.c   | 148 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-
 recv.c      |  88 ++++++++++++++++++++++++++++++++++--
 send.c      | 119 +++++++++++++++++++++++++++++++++++++++++++-----
 server.c    |  11 +++++
 unix_sock.c |   8 ++++
 7 files changed, 389 insertions(+), 17 deletions(-)

-- 
2.7.3


             reply	other threads:[~2016-03-21  9:03 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-03-21  9:03 Hans-Werner Hilse [this message]
2016-03-21  9:03 ` [B.A.T.M.A.N.] [RFC] alfred: implement TCP support for server-to-server communication Hans-Werner Hilse
2016-03-21  9:13   ` Sven Eckelmann
2016-03-21  9:38     ` Hans-Werner Hilse
2016-03-21 12:29       ` Simon Wunderlich
2016-03-21 13:25         ` Andrew Lunn
2016-03-27 18:26 ` [B.A.T.M.A.N.] [RFC v2] " Hans-Werner Hilse
2016-03-27 18:37   ` Hans-Werner Hilse
2016-04-22 18:37     ` jens
2016-04-24 22:02       ` Hans-Werner Hilse

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1458551033-8734-1-git-send-email-hwhilse@gmail.com \
    --to=hwhilse@gmail.com \
    --cc=b.a.t.m.a.n@lists.open-mesh.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox