diff --git a/README.md b/README.md index 07aa3ea..b25efe5 100644 --- a/README.md +++ b/README.md @@ -208,27 +208,31 @@ before the first peak to provide some context. It is possible to display different categories of messages: - --debug 1 Displays all the messages correctly demoudulated. + --debug 1 Displays all the messages correctly demoudulated. A correctly demodulated message is just one that makes sense as a Mode S message, the preamble makes sense, and there are no message errors, that is, no adiacet samples describing bits are the same magnitude. - --debug 2 Only messages with demodulation errors are displayed, + --debug 2 Only messages with demodulation errors are displayed, That is, only messages where one or more adiacent samples that should describe bits are the same magnitude. - --debug 3 Correctly deooded messages with Bad CRC are displayed. + --debug 3 Correctly deooded messages with Bad CRC are displayed. - --debug 4 Correctly deooded messages with good CRC are displayed. + --debug 4 Correctly deooded messages with good CRC are displayed. - --debug 5 Preamble detection failed in some way (specified when + --debug 5 Preamble detection failed in some way (specified when dumping the samples) even if the current sample level is greater than MODES_DEBUG_NOPREAMBLE_LEVEL (set to 25 by default). +Network related debug modes: + + --debug 6 Log network events (HTTP requests & others) + How this program works? --- diff --git a/anet.h b/anet.h index 062b22c..6d74af5 100644 --- a/anet.h +++ b/anet.h @@ -54,5 +54,6 @@ int anetNonBlock(char *err, int fd); int anetTcpNoDelay(char *err, int fd); int anetTcpKeepAlive(char *err, int fd); int anetPeerToString(int fd, char *ip, int *port); +int anetSetSendBuffer(char *err, int fd, int buffsize); #endif diff --git a/dump1090.c b/dump1090.c index 0a26901..d895cb7 100644 --- a/dump1090.c +++ b/dump1090.c @@ -70,6 +70,7 @@ #define MODES_DEBUG_BADCRC 3 #define MODES_DEBUG_GOODCRC 4 #define MODES_DEBUG_NOPREAMBLE 5 +#define MODES_DEBUG_NET 6 /* When debug is set to MODES_DEBUG_NOPREAMBLE, the first sample must be * at least greater than a given level for us to dump the signal. */ @@ -84,6 +85,7 @@ #define MODES_NET_INPUT_RAW_PORT 30001 #define MODES_NET_HTTP_PORT 8080 #define MODES_CLIENT_BUF_SIZE 1024 +#define MODES_NET_SNDBUF_SIZE (1024*64) #define MODES_NOTUSED(V) ((void) V) @@ -1734,9 +1736,13 @@ void modesAcceptClients(void) { c->fd = fd; c->buflen = 0; Modes.clients[fd] = c; + anetSetSendBuffer(Modes.aneterr,fd,MODES_NET_SNDBUF_SIZE); if (Modes.maxfd < fd) Modes.maxfd = fd; j--; /* Try again with the same listening port. */ + + if (Modes.debug == MODES_DEBUG_NET) + printf("Created new client %d\n", fd); } } @@ -1746,6 +1752,9 @@ void modesFreeClient(int fd) { free(Modes.clients[fd]); Modes.clients[fd] = NULL; + if (Modes.debug == MODES_DEBUG_NET) + printf("Closing client %d\n", fd); + /* If this was our maxfd, rescan the full clients array to check what's * the new max. */ if (Modes.maxfd == fd) { @@ -1901,21 +1910,35 @@ char *aircraftsToJson(int *len) { int handleHTTPRequest(struct client *c) { char hdr[512]; int clen, hdrlen; - int keepalive; + int httpver, keepalive; char *p, *url, *content; char *ctype; - /* printf("HTTP request: %s\n", c->buf); */ + if (Modes.debug == MODES_DEBUG_NET) + printf("\nHTTP request: %s\n", c->buf); /* Minimally parse the request. */ - keepalive = strstr(c->buf, "keep-alive") != NULL; + httpver = (strstr(c->buf, "HTTP/1.1") != NULL) ? 11 : 10; + if (httpver == 10) { + /* HTTP 1.0 defaults to close, unless otherwise specified. */ + keepalive = strstr(c->buf, "Connection: keep-alive") != NULL; + } else if (httpver == 11) { + /* HTTP 1.1 defaults to keep-alive, unless close is specified. */ + keepalive = strstr(c->buf, "Connection: close") == NULL; + } + + /* Identify he URL. */ p = strchr(c->buf,' '); if (!p) return 1; /* There should be the method and a space... */ url = ++p; /* Now this should point to the requested URL. */ p = strchr(p, ' '); if (!p) return 1; /* There should be a space before HTTP/... */ *p = '\0'; - /* printf("URL: %s\n", url); */ + + if (Modes.debug == MODES_DEBUG_NET) { + printf("\nHTTP keep alive: %d\n", keepalive); + printf("HTTP requested URL: %s\n\n", url); + } /* Select the content to send, we have just two so far: * "/" -> Our google map application. @@ -1959,6 +1982,9 @@ int handleHTTPRequest(struct client *c) { keepalive ? "keep-alive" : "close", clen); + if (Modes.debug == MODES_DEBUG_NET) + printf("HTTP Reply header:\n%s", hdr); + /* Send header and content. */ if (write(c->fd, hdr, hdrlen) == -1 || write(c->fd, content, clen) == -1) @@ -1968,7 +1994,7 @@ int handleHTTPRequest(struct client *c) { } free(content); Modes.stat_http_requests++; - return 0; + return !keepalive; } /* This function polls the clients using read() in order to receive new