Assign an ID to each backend.
This commit is contained in:
3
Makefile
3
Makefile
@@ -1,6 +1,7 @@
|
|||||||
CC ?= clang
|
CC ?= clang
|
||||||
CFLAGS ?= -Wall -Werror -O4 -g --std=gnu11 --pedantic-errors
|
CFLAGS ?= -Wall -Werror -O4 -g --std=gnu11 --pedantic-errors
|
||||||
LDFLAGS ?= -Wall -O4
|
LDFLAGS ?= -Wall -O4
|
||||||
|
LIBS ?= -luuid
|
||||||
|
|
||||||
all: adsbus
|
all: adsbus
|
||||||
|
|
||||||
@@ -11,4 +12,4 @@ clean:
|
|||||||
$(CC) -c $(CFLAGS) $< -o $@
|
$(CC) -c $(CFLAGS) $< -o $@
|
||||||
|
|
||||||
adsbus: adsbus.o backend.o airspy_adsb.o common.o
|
adsbus: adsbus.o backend.o airspy_adsb.o common.o
|
||||||
$(CC) $(LDFLAGS) -o adsbus adsbus.o backend.o airspy_adsb.o common.o
|
$(CC) $(LDFLAGS) -o adsbus adsbus.o backend.o airspy_adsb.o common.o $(LIBS)
|
||||||
|
|||||||
1
adsbus.c
1
adsbus.c
@@ -84,7 +84,6 @@ int main(int argc, char *argv[]) {
|
|||||||
for (int i = 0, j = optind; i < nbackends && j < argc; i++, j += 2) {
|
for (int i = 0, j = optind; i < nbackends && j < argc; i++, j += 2) {
|
||||||
backend_init(&backends[i]);
|
backend_init(&backends[i]);
|
||||||
if (!backend_connect(argv[j], argv[j + 1], &backends[i], epoll_fd)) {
|
if (!backend_connect(argv[j], argv[j + 1], &backends[i], epoll_fd)) {
|
||||||
fprintf(stderr, "Unable to connect to %s %s\n", argv[j], argv[j + 1]);
|
|
||||||
return EXIT_FAILURE;
|
return EXIT_FAILURE;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
17
backend.c
17
backend.c
@@ -5,6 +5,7 @@
|
|||||||
#include <netdb.h>
|
#include <netdb.h>
|
||||||
#include <sys/epoll.h>
|
#include <sys/epoll.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
#include <uuid/uuid.h>
|
||||||
|
|
||||||
#include "airspy_adsb.h"
|
#include "airspy_adsb.h"
|
||||||
#include "backend.h"
|
#include "backend.h"
|
||||||
@@ -30,6 +31,12 @@ void backend_init(struct backend *backend) {
|
|||||||
bool backend_connect(char *node, char *service, struct backend *backend, int epoll_fd) {
|
bool backend_connect(char *node, char *service, struct backend *backend, int epoll_fd) {
|
||||||
assert(backend->type == PEER_BACKEND);
|
assert(backend->type == PEER_BACKEND);
|
||||||
|
|
||||||
|
{
|
||||||
|
uuid_t uuid;
|
||||||
|
uuid_generate(uuid);
|
||||||
|
uuid_unparse(uuid, backend->id);
|
||||||
|
}
|
||||||
|
|
||||||
struct addrinfo *addrs;
|
struct addrinfo *addrs;
|
||||||
|
|
||||||
{
|
{
|
||||||
@@ -40,7 +47,7 @@ bool backend_connect(char *node, char *service, struct backend *backend, int epo
|
|||||||
|
|
||||||
int gai_err = getaddrinfo(node, service, &hints, &addrs);
|
int gai_err = getaddrinfo(node, service, &hints, &addrs);
|
||||||
if (gai_err) {
|
if (gai_err) {
|
||||||
fprintf(stderr, "getaddrinfo(%s %s): %s\n", node, service, gai_strerror(gai_err));
|
fprintf(stderr, "%s: getaddrinfo(%s %s): %s\n", backend->id, node, service, gai_strerror(gai_err));
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -63,13 +70,13 @@ bool backend_connect(char *node, char *service, struct backend *backend, int epo
|
|||||||
|
|
||||||
if (addr == NULL) {
|
if (addr == NULL) {
|
||||||
freeaddrinfo(addrs);
|
freeaddrinfo(addrs);
|
||||||
fprintf(stderr, "Can't connect to %s %s\n", node, service);
|
fprintf(stderr, "%s: Can't connect to %s %s\n", backend->id, node, service);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
char hbuf[NI_MAXHOST], sbuf[NI_MAXSERV];
|
char hbuf[NI_MAXHOST], sbuf[NI_MAXSERV];
|
||||||
if (getnameinfo(addr->ai_addr, addr->ai_addrlen, hbuf, sizeof(hbuf), sbuf, sizeof(sbuf), NI_NUMERICHOST | NI_NUMERICSERV) == 0) {
|
if (getnameinfo(addr->ai_addr, addr->ai_addrlen, hbuf, sizeof(hbuf), sbuf, sizeof(sbuf), NI_NUMERICHOST | NI_NUMERICSERV) == 0) {
|
||||||
fprintf(stderr, "Connected to %s %s\n", hbuf, sbuf);
|
fprintf(stderr, "%s: Connected to %s %s\n", backend->id, hbuf, sbuf);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -93,7 +100,7 @@ bool backend_connect(char *node, char *service, struct backend *backend, int epo
|
|||||||
|
|
||||||
bool backend_read(struct backend *backend) {
|
bool backend_read(struct backend *backend) {
|
||||||
if (buf_fill(&backend->buf, backend->fd) < 0) {
|
if (buf_fill(&backend->buf, backend->fd) < 0) {
|
||||||
fprintf(stderr, "Connection closed by backend\n");
|
fprintf(stderr, "%s: Connection closed by backend\n", backend->id);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -102,7 +109,7 @@ bool backend_read(struct backend *backend) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (backend->buf.length == BUF_LEN_MAX) {
|
if (backend->buf.length == BUF_LEN_MAX) {
|
||||||
fprintf(stderr, "Input buffer overrun. This probably means that adsbus doesn't understand the protocol that this source is speaking.\n");
|
fprintf(stderr, "%s: Input buffer overrun. This probably means that adsbus doesn't understand the protocol that this source is speaking.\n", backend->id);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ struct backend;
|
|||||||
typedef bool (*parser)(struct backend *, struct packet *);
|
typedef bool (*parser)(struct backend *, struct packet *);
|
||||||
struct backend {
|
struct backend {
|
||||||
enum peer_type type;
|
enum peer_type type;
|
||||||
|
char id[UUID_LEN];
|
||||||
int fd;
|
int fd;
|
||||||
struct buf buf;
|
struct buf buf;
|
||||||
char parser_state[PARSER_STATE_LEN];
|
char parser_state[PARSER_STATE_LEN];
|
||||||
|
|||||||
Reference in New Issue
Block a user