/*
This file is part of GNUnet.
(C) 2009, 2012 Christian Grothoff (and other contributing authors)
GNUnet 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, or (at your
option) any later version.
GNUnet 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 GNUnet; see the file COPYING. If not, write to the
Free Software Foundation, Inc., 59 Temple Place - Suite 330,
Boston, MA 02111-1307, USA.
*/
/**
* @file util/connection.c
* @brief TCP connection management
* @author Christian Grothoff
*
* This code is rather complex. Only modify it if you
* 1) Have a NEW testcase showing that the new code
* is needed and correct
* 2) All EXISTING testcases pass with the new code
* These rules should apply in general, but for this
* module they are VERY, VERY important.
*/
#include "platform.h"
#include "gnunet_common.h"
#include "gnunet_connection_lib.h"
#include "gnunet_container_lib.h"
#include "gnunet_resolver_service.h"
#include "gnunet_scheduler_lib.h"
#include "gnunet_server_lib.h"
#define LOG(kind,...) GNUNET_log_from (kind, "util", __VA_ARGS__)
#define LOG_STRERROR(kind,syscall) GNUNET_log_from_strerror (kind, "util", syscall)
/**
* Transmission handle. There can only be one for each connection.
*/
struct GNUNET_CONNECTION_TransmitHandle
{
/**
* Function to call if the send buffer has notify_size
* bytes available.
*/
GNUNET_CONNECTION_TransmitReadyNotify notify_ready;
/**
* Closure for notify_ready.
*/
void *notify_ready_cls;
/**
* Our connection handle.
*/
struct GNUNET_CONNECTION_Handle *connection;
/**
* Timeout for receiving (in absolute time).
*/
struct GNUNET_TIME_Absolute transmit_timeout;
/**
* Task called on timeout.
*/
GNUNET_SCHEDULER_TaskIdentifier timeout_task;
/**
* At what number of bytes available in the
* write buffer should the notify method be called?
*/
size_t notify_size;
};
/**
* During connect, we try multiple possible IP addresses
* to find out which one might work.
*/
struct AddressProbe
{
/**
* This is a linked list.
*/
struct AddressProbe *next;
/**
* This is a doubly-linked list.
*/
struct AddressProbe *prev;
/**
* The address; do not free (allocated at the end of this struct).
*/
const struct sockaddr *addr;
/**
* Underlying OS's socket.
*/
struct GNUNET_NETWORK_Handle *sock;
/**
* Connec