Implementation of the SMTP transport service. More...
#include "platform.h"
#include "gnunet_util.h"
#include "gnunet_constants.h"
#include "gnunet_protocols.h"
#include "gnunet_transport.h"
#include "gnunet_stats_service.h"
#include <libesmtp.h>
#include <signal.h>
Go to the source code of this file.
Data Structures | |
struct | EmailAddress |
Host-Address in a SMTP network. More... | |
struct | SMTPMessage |
Encapsulation of a GNUnet message in the SMTP mail body (before base64 encoding). More... | |
struct | GetMessageClosure |
Macros | |
#define | SMTP_MESSAGE_SIZE 65528 |
The default maximum size of each outbound SMTP message. More... | |
#define | DEBUG_SMTP GNUNET_EXTRA_LOGGING |
#define | FILTER_STRING_SIZE 64 |
#define | MAX_CHAR_PER_LINE 76 |
#define | EBUF_LEN 128 |
#define | strAUTOncmp(a, b) strncmp (a, b, strlen (b)) |
#define | READLINE(l, limit) |
#define | EBUF_LEN 128 |
Functions | |
static void * | listenAndDistribute (void *unused) |
Listen to the pipe, decode messages and send to core. More... | |
static int | api_verify_hello (const GNUNET_MessageHello *hello) |
Verify that a hello-Message is correct (a node is reachable at that address). More... | |
static GNUNET_MessageHello * | api_create_hello () |
Create a hello-Message for the current node. More... | |
static const char * | get_message (void **buf, int *len, void *cls) |
static int | api_send (GNUNET_TSession *tsession, const void *msg, const unsigned int size, int important) |
Send a message to the specified remote node. More... | |
static int | api_connect (const GNUNET_MessageHello *hello, GNUNET_TSession **tsessionPtr, int may_reuse) |
Establish a connection to a remote node. More... | |
static int | api_disconnect (GNUNET_TSession *tsession) |
Disconnect from a remote node. More... | |
static int | api_start_transport_server () |
Start the server process to receive inbound traffic. More... | |
static int | api_stop_transport_server () |
Shutdown the server process (stop receiving inbound traffic). More... | |
static int | api_hello_to_address (const GNUNET_MessageHello *hello, void **sa, unsigned int *sa_len) |
Convert SMTP hello to an IP address (always fails). More... | |
static int | api_associate (GNUNET_TSession *tsession) |
Always fails. More... | |
static int | api_test_would_try (GNUNET_TSession *tsession, unsigned int size, int important) |
Always succeeds (for now; we should look at adding frequency limits to SMTP in the future!). More... | |
GNUNET_TransportAPI * | inittransport_smtp (struct GNUNET_CoreAPIForTransport *core) |
The exported method. More... | |
void | donetransport_smtp () |
Variables | |
static GNUNET_NETWORK_STRUCT_END GNUNET_CoreAPIForTransport * | core_api |
apis (our advertised API and the core api ) More... | |
static struct GNUNET_GE_Context * | ectx |
static struct GNUNET_ThreadHandle * | dispatchThread |
Thread that listens for inbound messages. More... | |
static int | smtp_shutdown = GNUNET_YES |
Flag to indicate that server has been shut down. More... | |
static char * | smtp_server_name |
Set to the SMTP server hostname (and port) for outgoing messages. More... | |
static char * | pipename |
static struct GNUNET_Mutex * | lock |
Lock for uses of libesmtp (not thread-safe). More... | |
static struct sigaction | old_handler |
Old handler for SIGPIPE (kept to be able to restore). More... | |
static char * | |
static GNUNET_TransportAPI | smtpAPI |
static GNUNET_Stats_ServiceAPI * | stats |
static int | stat_bytesReceived |
static int | stat_bytesSent |
static int | stat_bytesDropped |
static unsigned long long | rate_limit |
How many e-mails are we allowed to send per hour? More... | |
static GNUNET_CronTime | last_transmission |
Implementation of the SMTP transport service.
Definition in file plugin_transport_smtp.c.
#define SMTP_MESSAGE_SIZE 65528 |
The default maximum size of each outbound SMTP message.
Definition at line 41 of file plugin_transport_smtp.c.
#define DEBUG_SMTP GNUNET_EXTRA_LOGGING |
Definition at line 43 of file plugin_transport_smtp.c.
#define FILTER_STRING_SIZE 64 |
Definition at line 45 of file plugin_transport_smtp.c.
#define MAX_CHAR_PER_LINE 76 |
Definition at line 49 of file plugin_transport_smtp.c.
#define EBUF_LEN 128 |
Definition at line 51 of file plugin_transport_smtp.c.
#define strAUTOncmp | ( | a, | |
b | |||
) | strncmp (a, b, strlen (b)) |
Definition at line 148 of file plugin_transport_smtp.c.
#define READLINE | ( | l, | |
limit | |||
) |
#define EBUF_LEN 128 |
Definition at line 51 of file plugin_transport_smtp.c.
|
static |
Listen to the pipe, decode messages and send to core.
Definition at line 154 of file plugin_transport_smtp.c.
References _, core_api, ectx, END, GNUNET_free, GNUNET_malloc, GNUNET_new, GNUNET_NO, GNUNET_STRINGS_base64_decode(), SMTPMessage::header, line, MAX_CHAR_PER_LINE, pipename, READLINE, SMTPMessage::sender, GNUNET_MessageHeader::size, size, smtp_shutdown, stat_bytesReceived, and stats.
Referenced by api_start_transport_server().
|
static |
Verify that a hello-Message is correct (a node is reachable at that address).
Since the reply will be asynchronous, a method must be called on success.
hello | the hello message to verify (the signature/crc have been verified before) |
Definition at line 273 of file plugin_transport_smtp.c.
References ectx, EmailAddress::filter, FILTER_STRING_SIZE, GNUNET_OK, GNUNET_SYSERR, and EmailAddress::senderAddress.
Referenced by api_create_hello(), and inittransport_smtp().
|
static |
Create a hello-Message for the current node.
The hello is created without signature and without a timestamp. The GNUnet core will GNUNET_RSA_sign the message and add an expiration time.
Definition at line 300 of file plugin_transport_smtp.c.
References _, api_verify_hello(), core_api, ectx, email, filter, EmailAddress::filter, FILTER_STRING_SIZE, GNUNET_free, GNUNET_malloc, GNUNET_memcpy, GNUNET_SYSERR, msg, EmailAddress::senderAddress, GNUNET_MessageHeader::size, and smtpAPI.
Referenced by inittransport_smtp().
|
static |
Definition at line 350 of file plugin_transport_smtp.c.
References buf, GetMessageClosure::ebody, GetMessageClosure::esize, len, and GetMessageClosure::pos.
Referenced by api_send().
|
static |
Send a message to the specified remote node.
tsession | the GNUNET_MessageHello identifying the remote node |
msg | what to send |
size | the size of the message |
important | is this message important enough to override typical limits? |
Definition at line 378 of file plugin_transport_smtp.c.
References _, core_api, GetMessageClosure::ebody, EBUF_LEN, ectx, email, GetMessageClosure::esize, filter, EmailAddress::filter, get_message(), GNUNET_free, GNUNET_malloc, GNUNET_memcpy, GNUNET_NO, GNUNET_OK, GNUNET_strdup, GNUNET_STRINGS_base64_encode(), GNUNET_SYSERR, GNUNET_YES, SMTPMessage::header, last_transmission, lock, m, msg, GetMessageClosure::pos, rate_limit, SMTPMessage::sender, EmailAddress::senderAddress, GNUNET_MessageHeader::size, size, smtp_server_name, smtp_shutdown, smtpAPI, stat_bytesSent, stats, and GNUNET_MessageHeader::type.
Referenced by inittransport_smtp().
|
static |
Establish a connection to a remote node.
hello | the hello-Message for the target node |
tsessionPtr | the session handle that is to be set |
may_reuse | can we re-use an existing connection? |
Definition at line 545 of file plugin_transport_smtp.c.
References GNUNET_malloc, GNUNET_memcpy, GNUNET_new, GNUNET_OK, and smtpAPI.
Referenced by inittransport_smtp().
|
static |
Disconnect from a remote node.
tsession | the session that is closed |
Definition at line 567 of file plugin_transport_smtp.c.
References GNUNET_free, and GNUNET_OK.
Referenced by inittransport_smtp().
|
static |
Start the server process to receive inbound traffic.
Definition at line 584 of file plugin_transport_smtp.c.
References dispatchThread, ectx, GNUNET_NO, GNUNET_OK, GNUNET_SYSERR, listenAndDistribute(), and smtp_shutdown.
Referenced by inittransport_smtp().
|
static |
Shutdown the server process (stop receiving inbound traffic).
Maybe restarted later!
Definition at line 605 of file plugin_transport_smtp.c.
References dispatchThread, GNUNET_OK, GNUNET_YES, and smtp_shutdown.
Referenced by inittransport_smtp().
|
static |
Convert SMTP hello to an IP address (always fails).
Definition at line 620 of file plugin_transport_smtp.c.
References GNUNET_SYSERR.
Referenced by inittransport_smtp().
|
static |
Always fails.
Definition at line 631 of file plugin_transport_smtp.c.
References GNUNET_SYSERR.
Referenced by inittransport_smtp().
|
static |
Always succeeds (for now; we should look at adding frequency limits to SMTP in the future!).
Definition at line 642 of file plugin_transport_smtp.c.
References GNUNET_OK.
Referenced by inittransport_smtp().
GNUNET_TransportAPI* inittransport_smtp | ( | struct GNUNET_CoreAPIForTransport * | core | ) |
The exported method.
Makes the core api available via a global and returns the smtp transport API.
Definition at line 654 of file plugin_transport_smtp.c.
References _, api_associate(), api_connect(), api_create_hello(), api_disconnect(), api_hello_to_address(), api_send(), api_start_transport_server(), api_stop_transport_server(), api_test_would_try(), api_verify_hello(), core, core_api, ectx, email, gettext_noop, GNUNET_free, GNUNET_NO, lock, old_handler, pipename, rate_limit, SMTP_MESSAGE_SIZE, smtp_server_name, smtpAPI, stat_bytesDropped, stat_bytesReceived, stat_bytesSent, and stats.
void donetransport_smtp | ( | ) |
Definition at line 731 of file plugin_transport_smtp.c.
References core_api, email, GNUNET_free, lock, old_handler, pipename, smtp_server_name, and stats.
|
static |
apis (our advertised API and the core api )
Definition at line 95 of file plugin_transport_smtp.c.
Referenced by api_create_hello(), api_send(), donetransport_smtp(), inittransport_smtp(), and listenAndDistribute().
|
static |
Definition at line 97 of file plugin_transport_smtp.c.
Referenced by api_create_hello(), api_send(), api_start_transport_server(), api_verify_hello(), inittransport_smtp(), and listenAndDistribute().
|
static |
Thread that listens for inbound messages.
Definition at line 102 of file plugin_transport_smtp.c.
Referenced by api_start_transport_server(), and api_stop_transport_server().
|
static |
Flag to indicate that server has been shut down.
Definition at line 107 of file plugin_transport_smtp.c.
Referenced by api_send(), api_start_transport_server(), api_stop_transport_server(), and listenAndDistribute().
|
static |
Set to the SMTP server hostname (and port) for outgoing messages.
Definition at line 112 of file plugin_transport_smtp.c.
Referenced by api_send(), donetransport_smtp(), and inittransport_smtp().
|
static |
Definition at line 114 of file plugin_transport_smtp.c.
Referenced by donetransport_smtp(), inittransport_smtp(), and listenAndDistribute().
|
static |
Lock for uses of libesmtp (not thread-safe).
Definition at line 119 of file plugin_transport_smtp.c.
Referenced by api_send(), donetransport_smtp(), and inittransport_smtp().
|
static |
Old handler for SIGPIPE (kept to be able to restore).
Definition at line 119 of file plugin_transport_smtp.c.
Referenced by donetransport_smtp(), and inittransport_smtp().
|
static |
Definition at line 126 of file plugin_transport_smtp.c.
Referenced by api_create_hello(), api_send(), donetransport_smtp(), and inittransport_smtp().
|
static |
Definition at line 128 of file plugin_transport_smtp.c.
Referenced by api_connect(), api_create_hello(), api_send(), and inittransport_smtp().
|
static |
Definition at line 130 of file plugin_transport_smtp.c.
Referenced by api_send(), donetransport_smtp(), inittransport_smtp(), and listenAndDistribute().
|
static |
Definition at line 132 of file plugin_transport_smtp.c.
Referenced by inittransport_smtp(), and listenAndDistribute().
|
static |
Definition at line 134 of file plugin_transport_smtp.c.
Referenced by api_send(), and inittransport_smtp().
|
static |
Definition at line 136 of file plugin_transport_smtp.c.
Referenced by inittransport_smtp().
|
static |
How many e-mails are we allowed to send per hour?
Definition at line 141 of file plugin_transport_smtp.c.
Referenced by api_send(), and inittransport_smtp().
|
static |
Definition at line 143 of file plugin_transport_smtp.c.
Referenced by api_send(), and client_response_handler().